-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccessgpt.py
More file actions
28 lines (21 loc) · 773 Bytes
/
Copy pathaccessgpt.py
File metadata and controls
28 lines (21 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from g4f.client import Client
import time
def run_prompt(prompt,GPT):
client = Client()
max_retries = 5
backoff_factor = 1.5
retry_delay = 5
for i in range(max_retries):
try:
response = client.chat.completions.create(
model=GPT,
messages=[{"role": "user", "content": prompt }],
)
result = (response.choices[0].message.content)
return result
except:
print(f"Request failed, retrying in {retry_delay} seconds...")
time.sleep(retry_delay)
retry_delay *= backoff_factor
result = "Can't find the solution to this question as too many users are using the site right now"
return result