返回提交历史
Modified
g4f/Provider/Providers/DfeHub.py
+9
-1
XFEstudio/gpt4free
Update Provider.DfeHub to consider rate-limit
b3d473c0
代码差异
1 个文件
+9
-1
@@ -1,6 +1,8 @@
1
1
import os, requests
2
2
from ...typing import sha256, Dict, get_type_hints
3
3
import json
4
import re
5
import time
4
6
5
7
url = "https://chat.dfehub.com/api/chat"
6
8
model = ['gpt-3.5-turbo']
@@ -34,12 +36,18 @@ def _create_completion(model: str, messages: list, stream: bool, **kwargs):
34
36
'presence_penalty': 0,
35
37
'frequency_penalty': 0,
36
38
'top_p': 1,
39
"stream": True,
37
40
}
38
39
41
response = requests.post('https://chat.dfehub.com/api/openai/v1/chat/completions',
40
42
headers=headers, json=json_data)
41
43
42
44
for chunk in response.iter_lines():
45
if b'detail' in chunk:
46
delay = re.findall(r"\d+\.\d+", chunk.decode())
47
delay = float(delay[-1])
48
print(f"Provider.DfeHub::Rate Limit Reached::Waiting {delay} seconds")
49
time.sleep(delay)
50
yield from _create_completion(model, messages, stream, **kwargs)
43
51
if b'content' in chunk:
44
52
data = json.loads(chunk.decode().split('data: ')[1])
45
53
yield (data['choices'][0]['delta']['content'])