summaryrefslogtreecommitdiffstats
path: root/g4f/gui/server/backend.py
diff options
context:
space:
mode:
authorcatmeowjiao <meowjiao321@163.com>2023-10-26 16:18:38 +0200
committercatmeowjiao <meowjiao321@163.com>2023-10-26 16:18:38 +0200
commit6fd2fa971fccc51acf4f312482e32c3b164809bd (patch)
tree70058535a4856e97a3a342e1eed5afbfe384e205 /g4f/gui/server/backend.py
parentMerge pull request #1153 from AndPim4912/ChatBase-incorrect-responses (diff)
downloadgpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.tar
gpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.tar.gz
gpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.tar.bz2
gpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.tar.lz
gpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.tar.xz
gpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.tar.zst
gpt4free-6fd2fa971fccc51acf4f312482e32c3b164809bd.zip
Diffstat (limited to '')
-rw-r--r--g4f/gui/server/backend.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py
index 2ba0ca8e..cf6d6358 100644
--- a/g4f/gui/server/backend.py
+++ b/g4f/gui/server/backend.py
@@ -1,4 +1,5 @@
import g4f
+import json
from flask import request
from .internet import search
@@ -43,6 +44,15 @@ class Backend_Api:
}
def _conversation(self):
+ config = None
+ proxy = None
+ try:
+ config = json.load(open("config.json","r",encoding="utf-8"))
+ proxy = config["proxy"]
+
+ except Exception:
+ pass
+
try:
jailbreak = request.json['jailbreak']
internet_access = request.json['meta']['content']['internet_access']
@@ -54,14 +64,25 @@ class Backend_Api:
messages = special_instructions[jailbreak] + conversation + search(internet_access, prompt) + [prompt]
def stream():
- yield from g4f.ChatCompletion.create(
- model=model,
- provider=get_provider(provider),
- messages=messages,
- stream=True,
- ) if provider else g4f.ChatCompletion.create(
- model=model, messages=messages, stream=True
- )
+ if proxy != None:
+ yield from g4f.ChatCompletion.create(
+ model=model,
+ provider=get_provider(provider),
+ messages=messages,
+ stream=True,
+ proxy=proxy
+ ) if provider else g4f.ChatCompletion.create(
+ model=model, messages=messages, stream=True, proxy=proxy
+ )
+ else:
+ yield from g4f.ChatCompletion.create(
+ model=model,
+ provider=get_provider(provider),
+ messages=messages,
+ stream=True,
+ ) if provider else g4f.ChatCompletion.create(
+ model=model, messages=messages, stream=True
+ )
return self.app.response_class(stream(), mimetype='text/event-stream')