summaryrefslogtreecommitdiffstats
path: root/gpt4free/theb/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'gpt4free/theb/__init__.py')
-rw-r--r--gpt4free/theb/__init__.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/gpt4free/theb/__init__.py b/gpt4free/theb/__init__.py
index 96053877..75a15068 100644
--- a/gpt4free/theb/__init__.py
+++ b/gpt4free/theb/__init__.py
@@ -2,7 +2,7 @@ from json import loads
from queue import Queue, Empty
from re import findall
from threading import Thread
-from typing import Generator
+from typing import Generator, Optional
from curl_cffi import requests
from fake_useragent import UserAgent
@@ -19,7 +19,7 @@ class Completion:
stream_completed = False
@staticmethod
- def request(prompt: str):
+ def request(prompt: str, proxy: Optional[str]=None):
headers = {
'authority': 'chatbot.theb.ai',
'content-type': 'application/json',
@@ -27,9 +27,12 @@ class Completion:
'user-agent': UserAgent().random,
}
+ proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None
+
requests.post(
'https://chatbot.theb.ai/api/chat-process',
headers=headers,
+ proxies=proxies,
content_callback=Completion.handle_stream_response,
json={'prompt': prompt, 'options': {}},
)
@@ -37,8 +40,8 @@ class Completion:
Completion.stream_completed = True
@staticmethod
- def create(prompt: str) -> Generator[str, None, None]:
- Thread(target=Completion.request, args=[prompt]).start()
+ def create(prompt: str, proxy: Optional[str]=None) -> Generator[str, None, None]:
+ Thread(target=Completion.request, args=[prompt, proxy]).start()
while not Completion.stream_completed or not Completion.message_queue.empty():
try: