summaryrefslogtreecommitdiffstats
path: root/g4f/gui/server
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2023-12-11 00:56:06 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2023-12-11 00:56:06 +0100
commitd743ee0c26f00916233d751f2f375be414487d49 (patch)
tree4377351363d186fefdf7d1eed27a4fde39f173a3 /g4f/gui/server
parentImprove error handling in gui (diff)
downloadgpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.gz
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.bz2
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.lz
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.xz
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.zst
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.zip
Diffstat (limited to '')
-rw-r--r--g4f/gui/server/backend.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py
index 9dc5dbb4..e4669699 100644
--- a/g4f/gui/server/backend.py
+++ b/g4f/gui/server/backend.py
@@ -4,8 +4,9 @@ from g4f.Provider import __providers__
import json
from flask import request, Flask
from .internet import get_search_message
+from g4f import debug
-g4f.debug.logging = True
+debug.logging = True
class Backend_Api:
def __init__(self, app: Flask) -> None:
@@ -52,8 +53,8 @@ class Backend_Api:
def version(self):
return {
- "version": g4f.get_version(),
- "lastet_version": g4f.get_lastet_version(),
+ "version": debug.get_version(),
+ "lastet_version": debug.get_lastet_version(),
}
def _gen_title(self):
@@ -68,28 +69,25 @@ class Backend_Api:
messages[-1]["content"] = get_search_message(messages[-1]["content"])
model = request.json.get('model')
model = model if model else g4f.models.default
- provider = request.json.get('provider').replace('g4f.Provider.', '')
+ provider = request.json.get('provider', '').replace('g4f.Provider.', '')
provider = provider if provider and provider != "Auto" else None
- if provider != None:
- provider = g4f.Provider.ProviderUtils.convert.get(provider)
def try_response():
try:
- response = g4f.ChatCompletion.create(
+ yield from g4f.ChatCompletion.create(
model=model,
provider=provider,
messages=messages,
stream=True,
ignore_stream_and_auth=True
)
- yield from response
except Exception as e:
print(e)
yield json.dumps({
'code' : 'G4F_ERROR',
'_action': '_ask',
'success': False,
- 'error' : f'an error occurred {str(e)}'
- })
+ 'error' : f'{e.__class__.__name__}: {e}'
+ })
return self.app.response_class(try_response(), mimetype='text/event-stream') \ No newline at end of file