summaryrefslogtreecommitdiffstats
path: root/g4f/api/__init__.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-27 18:36:46 +0200
committerGitHub <noreply@github.com>2023-10-27 18:36:46 +0200
commit0e700a5a951a0d9d705fb9f6c7253f8222062f09 (patch)
tree349c6c6c7c92b6c2a58db90643788ff7d64b1329 /g4f/api/__init__.py
parentUpdate README.md (diff)
parentadd api proxy (diff)
downloadgpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.tar
gpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.tar.gz
gpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.tar.bz2
gpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.tar.lz
gpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.tar.xz
gpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.tar.zst
gpt4free-0e700a5a951a0d9d705fb9f6c7253f8222062f09.zip
Diffstat (limited to 'g4f/api/__init__.py')
-rw-r--r--g4f/api/__init__.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py
index b78768bd..fec5606f 100644
--- a/g4f/api/__init__.py
+++ b/g4f/api/__init__.py
@@ -105,9 +105,25 @@ class Api:
logger.info(f'model: {model}, stream: {stream}, request: {messages[-1]["content"]}')
- response = self.engine.ChatCompletion.create(model=model,
- stream=stream, messages=messages,
- ignored=self.list_ignored_providers)
+ config = None
+ proxy = None
+
+ try:
+ config = json.load(open("config.json","r",encoding="utf-8"))
+ proxy = config["proxy"]
+
+ except Exception:
+ pass
+
+ if proxy != None:
+ response = self.engine.ChatCompletion.create(model=model,
+ stream=stream, messages=messages,
+ ignored=self.list_ignored_providers,
+ proxy=proxy)
+ else:
+ response = self.engine.ChatCompletion.create(model=model,
+ stream=stream, messages=messages,
+ ignored=self.list_ignored_providers)
completion_id = ''.join(random.choices(string.ascii_letters + string.digits, k=28))
completion_timestamp = int(time.time())