summaryrefslogtreecommitdiffstats
path: root/gpt4free
diff options
context:
space:
mode:
authorCivitasv <hscivitasv@gmail.com>2023-04-30 07:19:46 +0200
committerCivitasv <hscivitasv@gmail.com>2023-04-30 07:19:46 +0200
commit70acea30a58c55288c1d31c630801e9498b24114 (patch)
treedeeff36849acce2ea0bffba5c1d319adc396ce3a /gpt4free
parentMerge branch 'main' of https://github.com/xtekky/gpt4free (diff)
downloadgpt4free-70acea30a58c55288c1d31c630801e9498b24114.tar
gpt4free-70acea30a58c55288c1d31c630801e9498b24114.tar.gz
gpt4free-70acea30a58c55288c1d31c630801e9498b24114.tar.bz2
gpt4free-70acea30a58c55288c1d31c630801e9498b24114.tar.lz
gpt4free-70acea30a58c55288c1d31c630801e9498b24114.tar.xz
gpt4free-70acea30a58c55288c1d31c630801e9498b24114.tar.zst
gpt4free-70acea30a58c55288c1d31c630801e9498b24114.zip
Diffstat (limited to 'gpt4free')
-rw-r--r--gpt4free/forefront/__init__.py6
-rw-r--r--gpt4free/quora/__init__.py8
-rw-r--r--gpt4free/theb/__init__.py11
-rw-r--r--gpt4free/you/__init__.py4
4 files changed, 24 insertions, 5 deletions
diff --git a/gpt4free/forefront/__init__.py b/gpt4free/forefront/__init__.py
index f0ca1a15..aa78cfa7 100644
--- a/gpt4free/forefront/__init__.py
+++ b/gpt4free/forefront/__init__.py
@@ -98,12 +98,15 @@ class StreamingCompletion:
action_type='new',
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
model='gpt-4',
+ proxy=None
) -> Generator[ForeFrontResponse, None, None]:
if not token:
raise Exception('Token is required!')
if not chat_id:
chat_id = str(uuid4())
+ proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else None
+
headers = {
'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
'accept': '*/*',
@@ -135,6 +138,7 @@ class StreamingCompletion:
for chunk in post(
'https://chat-server.tenant-forefront-default.knative.chi.coreweave.com/chat',
headers=headers,
+ proxies=proxies,
json=json_data,
stream=True,
).iter_lines():
@@ -169,6 +173,7 @@ class Completion:
action_type='new',
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
model='gpt-4',
+ proxy=None
) -> ForeFrontResponse:
text = ''
final_response = None
@@ -179,6 +184,7 @@ class Completion:
action_type=action_type,
default_persona=default_persona,
model=model,
+ proxy=proxy
):
if response:
final_response = response
diff --git a/gpt4free/quora/__init__.py b/gpt4free/quora/__init__.py
index f548ff41..afbfb68d 100644
--- a/gpt4free/quora/__init__.py
+++ b/gpt4free/quora/__init__.py
@@ -187,7 +187,7 @@ class Account:
enable_bot_creation: bool = False,
):
client = TLS(client_identifier='chrome110')
- client.proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else None
+ client.proxies = {'http': f'http://{proxy}', 'https': f'http://{proxy}'} if proxy else {}
mail_client = Emailnator()
mail_address = mail_client.get_mail()
@@ -293,10 +293,13 @@ class StreamingCompletion:
custom_model: bool = None,
prompt: str = 'hello world',
token: str = '',
+ proxy: Optional[str] = None
) -> Generator[PoeResponse, None, None]:
_model = MODELS[model] if not custom_model else custom_model
+ proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else False
client = PoeClient(token)
+ client.proxy = proxies
for chunk in client.send_message(_model, prompt):
yield PoeResponse(
@@ -330,10 +333,13 @@ class Completion:
custom_model: str = None,
prompt: str = 'hello world',
token: str = '',
+ proxy: Optional[str] = None
) -> PoeResponse:
_model = MODELS[model] if not custom_model else custom_model
+ proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False
client = PoeClient(token)
+ client.proxy = proxies
chunk = None
for response in client.send_message(_model, prompt):
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:
diff --git a/gpt4free/you/__init__.py b/gpt4free/you/__init__.py
index 97b48464..d084a842 100644
--- a/gpt4free/you/__init__.py
+++ b/gpt4free/you/__init__.py
@@ -30,12 +30,16 @@ class Completion:
include_links: bool = False,
detailed: bool = False,
debug: bool = False,
+ proxy: Optional[str] = None
) -> PoeResponse:
if chat is None:
chat = []
+ proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else {}
+
client = Session(client_identifier='chrome_108')
client.headers = Completion.__get_headers()
+ client.proxies = proxies
response = client.get(
f'https://you.com/api/streamingSearch',