diff options
author | najam-tariq <103676132+najam-tariq@users.noreply.github.com> | 2023-07-19 13:44:15 +0200 |
---|---|---|
committer | najam-tariq <103676132+najam-tariq@users.noreply.github.com> | 2023-07-19 13:44:15 +0200 |
commit | b3d473c0af04f082cad90f397cb5b946fc2e8d80 (patch) | |
tree | 7d834031cfcfe7f4ca2da29977c347a4e19cbace /g4f | |
parent | Update README.md (diff) | |
download | gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.tar gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.tar.gz gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.tar.bz2 gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.tar.lz gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.tar.xz gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.tar.zst gpt4free-b3d473c0af04f082cad90f397cb5b946fc2e8d80.zip |
Diffstat (limited to 'g4f')
-rw-r--r-- | g4f/Provider/Providers/DfeHub.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/g4f/Provider/Providers/DfeHub.py b/g4f/Provider/Providers/DfeHub.py index a1488bc5..afc9861a 100644 --- a/g4f/Provider/Providers/DfeHub.py +++ b/g4f/Provider/Providers/DfeHub.py @@ -1,6 +1,8 @@ import os, requests from ...typing import sha256, Dict, get_type_hints import json +import re +import time url = "https://chat.dfehub.com/api/chat" model = ['gpt-3.5-turbo'] @@ -34,12 +36,18 @@ def _create_completion(model: str, messages: list, stream: bool, **kwargs): 'presence_penalty': 0, 'frequency_penalty': 0, 'top_p': 1, + "stream": True, } - response = requests.post('https://chat.dfehub.com/api/openai/v1/chat/completions', headers=headers, json=json_data) for chunk in response.iter_lines(): + if b'detail' in chunk: + delay = re.findall(r"\d+\.\d+", chunk.decode()) + delay = float(delay[-1]) + print(f"Provider.DfeHub::Rate Limit Reached::Waiting {delay} seconds") + time.sleep(delay) + yield from _create_completion(model, messages, stream, **kwargs) if b'content' in chunk: data = json.loads(chunk.decode().split('data: ')[1]) yield (data['choices'][0]['delta']['content']) |