summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-06 18:21:56 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-06 18:21:56 +0200
commitaf9ed889c11f2ca5f1df96c40f072012a68b5713 (patch)
tree23259ad64f84a3397f197549fcdd12b7c2563707
parent~ | g4f v-0.1.5.0 (diff)
downloadgpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.tar
gpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.tar.gz
gpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.tar.bz2
gpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.tar.lz
gpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.tar.xz
gpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.tar.zst
gpt4free-af9ed889c11f2ca5f1df96c40f072012a68b5713.zip
-rw-r--r--g4f/Provider/AiAsk.py6
-rw-r--r--g4f/Provider/Aichat.py4
-rw-r--r--g4f/Provider/Bing.py2
-rw-r--r--g4f/Provider/ChatForAi.py14
-rw-r--r--g4f/Provider/ChatgptAi.py4
-rw-r--r--g4f/Provider/ChatgptDemo.py4
-rw-r--r--g4f/Provider/GptGo.py4
-rw-r--r--g4f/Provider/Liaobots.py5
-rw-r--r--g4f/Provider/Vitalentum.py4
9 files changed, 17 insertions, 30 deletions
diff --git a/g4f/Provider/AiAsk.py b/g4f/Provider/AiAsk.py
index 0a44af3e..870dd1ab 100644
--- a/g4f/Provider/AiAsk.py
+++ b/g4f/Provider/AiAsk.py
@@ -1,11 +1,9 @@
from __future__ import annotations
-from aiohttp import ClientSession
-
+from aiohttp import ClientSession, ClientTimeout
from ..typing import AsyncGenerator
from .base_provider import AsyncGeneratorProvider
-
class AiAsk(AsyncGeneratorProvider):
url = "https://e.aiask.me"
supports_gpt_35_turbo = True
@@ -24,7 +22,7 @@ class AiAsk(AsyncGeneratorProvider):
"origin": cls.url,
"referer": f"{cls.url}/chat",
}
- async with ClientSession(headers=headers, timeout=timeout) as session:
+ async with ClientSession(headers=headers, timeout=ClientTimeout(timeout)) as session:
data = {
"continuous": True,
"id": "fRMSQtuHl91A4De9cCvKD",
diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py
index 41496765..2e141b53 100644
--- a/g4f/Provider/Aichat.py
+++ b/g4f/Provider/Aichat.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from aiohttp import ClientSession
+from aiohttp import ClientSession, ClientTimeout
from .base_provider import AsyncProvider, format_prompt
@@ -34,7 +34,7 @@ class Aichat(AsyncProvider):
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
}
async with ClientSession(
- headers=headers, timeout=timeout
+ headers=headers, timeout=ClientTimeout(timeout)
) as session:
json_data = {
"message": format_prompt(messages),
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index aa2db990..f4275a5f 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -250,7 +250,7 @@ async def stream_generate(
conversation = await create_conversation(session)
try:
async with session.ws_connect(
- f'wss://sydney.bing.com/sydney/ChatHub?sec_access_token={urllib.parse.quote_plus(conversation.conversationSignature)}',
+ f'wss://sydney.bing.com/sydney/ChatHub',
autoping=False,
params={'sec_access_token': conversation.conversationSignature}
) as wss:
diff --git a/g4f/Provider/ChatForAi.py b/g4f/Provider/ChatForAi.py
index 47ac46f0..86b29639 100644
--- a/g4f/Provider/ChatForAi.py
+++ b/g4f/Provider/ChatForAi.py
@@ -1,7 +1,5 @@
from __future__ import annotations
-import time, hashlib
-
from ..typing import AsyncGenerator
from ..requests import StreamSession
from .base_provider import AsyncGeneratorProvider
@@ -21,11 +19,9 @@ class ChatForAi(AsyncGeneratorProvider):
**kwargs
) -> AsyncGenerator:
async with StreamSession(impersonate="chrome107", timeout=timeout) as session:
- conversation_id = f"id_{int(time.time())}"
prompt = messages[-1]["content"]
- timestamp = int(time.time())
data = {
- "conversationId": conversation_id,
+ "conversationId": "temp",
"conversationType": "chat_continuous",
"botId": "chat_continuous",
"globalSettings":{
@@ -39,8 +35,6 @@ class ChatForAi(AsyncGeneratorProvider):
"botSettings": {},
"prompt": prompt,
"messages": messages,
- "sign": generate_signature(timestamp, conversation_id, prompt),
- "timestamp": timestamp
}
async with session.post(f"{cls.url}/api/handle/provider-openai", json=data) as response:
response.raise_for_status()
@@ -56,8 +50,4 @@ class ChatForAi(AsyncGeneratorProvider):
("stream", "bool"),
]
param = ", ".join([": ".join(p) for p in params])
- return f"g4f.provider.{cls.__name__} supports: ({param})"
-
-def generate_signature(timestamp, id, prompt):
- data = f"{timestamp}:{id}:{prompt}:6B46K4pt"
- return hashlib.sha256(data.encode()).hexdigest()
+ return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file
diff --git a/g4f/Provider/ChatgptAi.py b/g4f/Provider/ChatgptAi.py
index 0ae0fa38..553a9860 100644
--- a/g4f/Provider/ChatgptAi.py
+++ b/g4f/Provider/ChatgptAi.py
@@ -1,7 +1,7 @@
from __future__ import annotations
import re
-from aiohttp import ClientSession
+from aiohttp import ClientSession, ClientTimeout
from .base_provider import AsyncProvider, format_prompt
@@ -40,7 +40,7 @@ class ChatgptAi(AsyncProvider):
"user-agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
}
async with ClientSession(
- headers=headers, timeout=timeout
+ headers=headers, timeout=ClientTimeout(timeout)
) as session:
if not cls._nonce:
async with session.get(cls.url, proxy=proxy) as response:
diff --git a/g4f/Provider/ChatgptDemo.py b/g4f/Provider/ChatgptDemo.py
index fdd7730b..c9d2894a 100644
--- a/g4f/Provider/ChatgptDemo.py
+++ b/g4f/Provider/ChatgptDemo.py
@@ -1,7 +1,7 @@
from __future__ import annotations
import time, json, re
-from aiohttp import ClientSession
+from aiohttp import ClientSession, ClientTimeout
from typing import AsyncGenerator
from .base_provider import AsyncGeneratorProvider
@@ -34,7 +34,7 @@ class ChatgptDemo(AsyncGeneratorProvider):
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
}
- async with ClientSession(headers=headers, timeout=timeout) as session:
+ async with ClientSession(headers=headers, timeout=ClientTimeout(timeout)) as session:
async with session.get(f"{cls.url}/", proxy=proxy) as response:
response.raise_for_status()
response = await response.text()
diff --git a/g4f/Provider/GptGo.py b/g4f/Provider/GptGo.py
index 19484291..be62250c 100644
--- a/g4f/Provider/GptGo.py
+++ b/g4f/Provider/GptGo.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from aiohttp import ClientSession
+from aiohttp import ClientSession, ClientTimeout
import json
from ..typing import AsyncGenerator
@@ -32,7 +32,7 @@ class GptGo(AsyncGeneratorProvider):
"Sec-Fetch-Site" : "same-origin",
}
async with ClientSession(
- headers=headers, timeout=timeout
+ headers=headers, timeout=ClientTimeout(timeout)
) as session:
async with session.get(
"https://gptgo.ai/action_get_token.php",
diff --git a/g4f/Provider/Liaobots.py b/g4f/Provider/Liaobots.py
index e65c3a0d..2e0154d5 100644
--- a/g4f/Provider/Liaobots.py
+++ b/g4f/Provider/Liaobots.py
@@ -1,9 +1,8 @@
from __future__ import annotations
-import json
import uuid
-from aiohttp import ClientSession
+from aiohttp import ClientSession, ClientTimeout
from ..typing import AsyncGenerator
from .base_provider import AsyncGeneratorProvider
@@ -55,7 +54,7 @@ class Liaobots(AsyncGeneratorProvider):
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
}
async with ClientSession(
- headers=headers, timeout=timeout
+ headers=headers, timeout=ClientTimeout(timeout)
) as session:
cls._auth_code = auth if isinstance(auth, str) else cls._auth_code
if not cls._auth_code:
diff --git a/g4f/Provider/Vitalentum.py b/g4f/Provider/Vitalentum.py
index 9125c285..ccaaeb00 100644
--- a/g4f/Provider/Vitalentum.py
+++ b/g4f/Provider/Vitalentum.py
@@ -1,7 +1,7 @@
from __future__ import annotations
import json
-from aiohttp import ClientSession
+from aiohttp import ClientSession, ClientTimeout
from .base_provider import AsyncGeneratorProvider
from ..typing import AsyncGenerator
@@ -41,7 +41,7 @@ class Vitalentum(AsyncGeneratorProvider):
**kwargs
}
async with ClientSession(
- headers=headers, timeout=timeout
+ headers=headers, timeout=ClientTimeout(timeout)
) as session:
async with session.post(cls.url + "/api/converse-edge", json=data, proxy=proxy) as response:
response.raise_for_status()