Git Product home page Git Product logo

aledipa / free-gpt4-web-api Goto Github PK

View Code? Open in Web Editor NEW
375.0 5.0 79.0 3.2 MB

FreeGPT4-WEB-API is a python server that allows you to have a self-hosted GPT-4 Unlimited and Free WEB API, via the latest Bing's AI (and much more).

Home Page: https://api.freegpt4.ddns.net/?text=Your Request Here

License: GNU General Public License v3.0

Python 39.70% Dockerfile 1.12% CSS 2.50% JavaScript 10.74% HTML 45.94%
artificial-intelligence bing-api chatgpt gpt-4 gpt-alternative sirigpt free-gpt gpt-4-api api api-server

free-gpt4-web-api's Introduction

Docker Image CI GPT4-API-PyApp

Free-GPT4-WEB-API

FreeGPT4-WEB-API is a python server that allows you to have a self-hosted GPT-4 Unlimited and Free WEB API, via the latest Bing's AI.

GUI Preview:

Requirements

  • Python 3
  • Flask[async]
  • g4f (from here).
  • aiohttp
  • auth
  • Werkzeug

Manual Installation

To install the required libraries, you can use the following command:

pip3 install -r requirements.txt

Usage

To run the server, use the following command:

python3 FreeGPT4_Server.py [-h] [--remove-sources] [--enable-gui] 
                           [--private-mode] [--enable-history] [--password PASSWORD] 
                           [--cookie-file COOKIE_FILE] [--file-input] [--port PORT] 
                           [--model MODEL] [--provider PROVIDER] [--keyword KEYWORD] 
                           [--system-prompt SYSTEM_PROMPT]

Options:

-h, --help show this help message and exit

--remove-sources Remove the sources from the response

--enable-gui Use a graphical interface for settings

--private-mode Use a private token to access the API

--enable-history Enable the history of the messages

--password PASSWORD Optional, set a password for the settings page [mandatory in docker envirtonment]

--cookie-file COOKIE_FILE Use a cookie file

--file-input Add the file as input support

--port PORT Change the port (default: 5500)

--model MODEL Change the model (default: gpt-4)

--provider PROVIDER Change the provider (default: Bing)

--keyword KEYWORD Add the keyword support

--system-prompt SYSTEM_PROMPT Use a system prompt to 'customize' the answers

If you want to use it with curl (credits to @ayoubelmhamdi):

fileTMP="$1"
curl -s -F file=@"${fileTMP}" http://127.0.0.1:5500/

Docker Installation

It's possible to install the docker image of this API by running this command:

docker container run -v /path/to/your/cookies.json:/cookies.json:ro -p YOUR_PORT:5500 d0ckmg/free-gpt4-web-api

just omit -v /path/to/your/cookies.json:/cookies.json:ro for using it without cookies

or alternatively, you can use a docker-compose file:

docker-compose.yml

version: "3.9"
services:
  api:
    image: "d0ckmg/free-gpt4-web-api:latest"
    ports:
      - "YOUR_PORT:5500"
    #volumes:
    #  - /path/to/your/cookies.json:/cookies.json:ro

This will start the server and allow you to access the GPT-4 WEB API.

Once the server is running, you can access the API by sending HTTP requests to the server's address. The data for the requests should be sent via hotlinking and the response will be returned as plain text.

For example, to generate text using the API, you can send a GET request with the text parameter set to the text you want to use as a prompt and the (optional) style parameter set to the style you want to use. The default style is "balanced" and is recommended since it is faster. The generated text will be returned in the response as plain text.

To stop the server, you can press CTRL+C in the terminal where the server is running. (credits to @git-malik)

Siri Integration

You can implement the power of GPT4 in Siri by using the GPTMode Apple Shortcut. Then you can use it just by saying "GPT Mode" to Siri and then ask your question when prompted to do so.

Configuration

The server can be configured by editing the FreeGPT4_Server.py file. You can change the server's port, host, and other settings. Please do not edit the settings.json file manually, use the GUI or the corresponding parameters. The only cookie needed for the Bing model is _"U".

Main Libraries

FreeGPT4-WEB-API uses the Flask and GPT4Free libraries. Flask is a micro web framework for Python that allows you to easily create web applications. GPT4Free is a library that provides an interface to the Bing's GPT-4, credits to @xtekky's GPT4Free.

Star History

Star History Chart

Notes

  • The demo server may be overloaded and not always work as expected. (Check the "Demo Server Status" above)
  • Any kind of contribution to the repository is welcome.

Todo ✔️

  • Fix Demo Server
  • Update README

free-gpt4-web-api's People

Contributors

aledipa avatar dependabot[bot] avatar git-malik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

free-gpt4-web-api's Issues

Duplicate responses.

Most answers when using a language other than English, double answers appear.

>Hola.
Hola, este es Bing. ¿Qué quieres saber hoy? 😊 Hello, this is Bing. What do you want to know today? 😊
>Hola buenos días.
Hola, este es Bing. ¿En qué puedo ayudarte? 😊 Hello, this is Bing. How can I help you? 😊

instructions to enable webgui in docker

It seems difficult to enable webgui in docker container. please update the instructions. I tired following

  1. mapped /app/src/data to one of my host folders which has settings.json and a password set
  2. changed docker compose to have
    command: 
      - "--remove-sources"
      - "--enable-gui"

I can get the docker server started. However, when I go to host:port/settings, it shows a login page, but entering the password just refreshed the login page. it doesn't take to settings page.

internal error

image
getting this error.

running the server on http://localhost:8081/ and i can see the ''Please enter a question'' msg.

How do you send a request and receive responses?

error

Hello,

I can log to the page setting but i can't actually use the chat, i have an error when putting the url http://127.0.0.1:5005/?text=your%20query
I've tried to use my own bing cookie file aswell but still have an error.

error

Internal server error

I'm using docker,and when I send GET request with text params, it shows

<!doctype html>
<html lang=en>
  <title>500 Internal Server Error</title>
  <h1>Internal Server Error</h1>
  <p>The server encountered an internal error and was unable to complete your
    request. Either the server is overloaded or there is an error in the
    application.</p>

TypeError when running FreeGPT4_Server.py

While attempting to use FreeGPT4_Server.py, I encountered a TypeError. The error occurs when the server attempts to process a GET request.

The error message indicates that an issue arises in the create_message function of the Bing.py file, specifically when trying to use the "|" operator with two dictionaries. Here's the traceback for the error:

Traceback (most recent call last):
  File "/home/chris/.local/lib/python3.8/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/chris/.local/lib/python3.8/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/chris/.local/lib/python3.8/site-packages/flask/app.py", line 867, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/chris/.local/lib/python3.8/site-packages/flask/app.py", line 852, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/home/chris/.local/lib/python3.8/site-packages/asgiref/sync.py", line 277, in __call__
    return call_result.result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/home/chris/.local/lib/python3.8/site-packages/asgiref/sync.py", line 353, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "FreeGPT4_Server.py", line 133, in index
    await PROVIDERS[args.provider].create_async(
  File "/home/chris/.local/lib/python3.8/site-packages/g4f/Provider/base_provider.py", line 122, in create_async
    return "".join([
  File "/home/chris/.local/lib/python3.8/site-packages/g4f/Provider/base_provider.py", line 122, in <listcomp>
    return "".join([
  File "/home/chris/.local/lib/python3.8/site-packages/g4f/Provider/Bing.py", line 447, in stream_generate
    await wss.send_str(create_message(conversation, prompt, tone, context))
  File "/home/chris/.local/lib/python3.8/site-packages/g4f/Provider/Bing.py", line 392, in create_message
    'message': Defaults.location | {
TypeError: unsupported operand type(s) for |: 'dict' and 'dict'

This error prevents the server from functioning as expected. Could you please provide guidance on how to resolve this issue?

get_parameters() missing 1 required positional argument: 'cls'

Getting the following error after sending request with default settings on bing:
[2024-03-24 22:16:54,169] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.10/dist-packages/asgiref/sync.py", line 254, in call
return call_result.result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
return self.__get_result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/usr/local/lib/python3.10/dist-packages/asgiref/sync.py", line 331, in main_wrap
result = await self.awaitable(*args, **kwargs)
File "/Free-GPT4-WEB-API-main/src/FreeGPT4_Server.py", line 146, in index
print(PROVIDERS[args.provider].params) # supported args
File "/usr/local/lib/python3.10/dist-packages/g4f/providers/base_provider.py", line 98, in params
for name, param in cls.get_parameters().items():
TypeError: AbstractProvider.get_parameters() missing 1 required positional argument: 'cls'

Blank response

So, if you ask a medium-long question, it just responds blank—nothing. Is it because of the tokens or the length of the message? (I'm not using any cookies, btw) or sum else? I really need an answer, please.

Free hosting

How do i host this for free? Can i host in github?

Demo API is not working.

Always respond

Internal Server Error
The server encountered an internal error and was unable to complete your request. 
Either the server is overloaded or there is an error in the application.

Using bing as provider not giving any output

  • Serving Flask app 'FreeGPT4_Server'
  • Debug mode: off
    WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on all addresses (0.0.0.0)
  • Running on http://127.0.0.1:3000
  • Running on http://192.168.0.14:3000
    Press CTRL+C to quit
    Initializing...
    start
    get
    ici

Input: 你看得见我吗?
g4f.provider.Bing supports: (model: str, messages: list[dict[str, str]], stream: bool)
Result Str:

127.0.0.1 - - [06/Oct/2023 22:52:15] "GET /?text=你看得见我吗? HTTP/1.1" 200 -

There is no results from Bing gpt4.

unavailable

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
image
image

[BUG discussion] escape sequence in string

# Cleans the response from the resources links
    # INFO: Unsupported escape sequence in string literal
    if (args.remove_sources):
        if re.search("\[\^[0-9]+\^\]\[[0-9]+\]", resp_str):
            resp_str = resp_str.split("\n\n")
            if len(resp_str) > 1:
                resp_str.pop(0)
            resp_str = re.sub("\[\^[0-9]+\^\]\[[0-9]+\]", "", str(resp_str[0]))

Because of that bug, on average 40% of the request response is useless, due to Bing mostly answering in this manner :

🤖 Hello, I'm Bing ! Here is your reply : 

- ....

Does this still need cookies.json ?

Hello there

Given bing is now open to public, without any login needs, can this be used without cookies.json now ?
I am using the docker compose version.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.