xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
59.79k stars 13.19k forks source link

Support and compatibility with SillyTavern #767

Closed MemeticGitHubUser closed 1 year ago

MemeticGitHubUser commented 1 year ago

Sillytavern is a UI frontend I enjoy using a lot. would it be possible to make it so GPT4FREE can be used with it?

bagusindrayana commented 1 year ago

maybe bit late, SillyTavern actualy support proxy or custom url, so basically you can use local server from gpt4free to SillyTavern, BUT SillyTavern need check connection to the server with request to route /models and gpt4free doesnt have it so to able to make work with sillytavern you need add some code in interference/app.py and run (follow readme to run local server)

# add this code
@app.route("/models", methods=['get'])
def models():
    return {
        "object": "list",
        "data": [
            {
                "id": "gpt-3.5-turbo",
            }
        ]
    }

and maybe you want change provider to another providers that are still working

@app.route("/chat/completions", methods=['POST'])
def chat_completions():
    streaming = request.json.get('stream', False)
    model = request.json.get('model', 'gpt-3.5-turbo')
    messages = request.json.get('messages')

    response = ChatCompletion.create(model=model, 
                                     stream=streaming,
                                     messages=messages,
                                     # change to provider that work
                                     provider=Provider.AItianhu)

and now you can adjust sillytavern config, chang to your local gpt4free server, default is http://127.0.0.1:1337 or http://localhost:1337 image

disable streaming if provider doesnt support stream image

setting open ai key with random string or int image

and click connect and test message

also always check your local gpt4free server if have some error try change current provider to another provider that work image

result : image

nacho00112 commented 1 year ago

Thanks for the tutorial, maybe we need the "/models" in the repo and a command line option to change provider

github-actions[bot] commented 1 year ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

MemeticGitHubUser commented 1 year ago

I keep getting this error:

Traceback (most recent call last): File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask\app.py", line 2213, in __call__ return self.wsgi_app(environ, start_response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask\app.py", line 2193, in wsgi_app response = self.handle_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask_cors\extension.py", line 176, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask\app.py", line 2190, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask\app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask_cors\extension.py", line 176, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask\app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\venv\Lib\site-packages\flask\app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\interference\app.py", line 32, in chat_completions response = ChatCompletion.create(model=model, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\g4f\__init__.py", line 36, in create if stream else ''.join(engine._create_completion(model.name, messages, stream, **kwargs))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Kyle\PycharmProjects\gpt4free\g4f\Provider\Providers\ChatgptAi.py", line 49, in _create_completion yield (response.json()['data']) ^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: 'data'

nacho00112 commented 1 year ago

Try another provider, ones work others not

nacho00112 commented 1 year ago

But there should be some working ones

MemeticGitHubUser commented 1 year ago

Besides Bing, that is the only active provider listed using gpt4 lol. And I've had no luck with bing because of a Captcha.

nacho00112 commented 1 year ago

Bing was working for me, but now i'm getting requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

github-actions[bot] commented 1 year ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] commented 1 year ago

Closing due to inactivity.