XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix timeout in create_async

af9ed889
Heiner Lohaus <heiner@lohaus.eu>
提交于

代码差异

9 个文件 +17 -30
Modified g4f/Provider/AiAsk.py +2 -4
@@ -1,11 +1,9 @@
1 1 from __future__ import annotations
2 2
3 from aiohttp import ClientSession
4
3 from aiohttp import ClientSession, ClientTimeout
5 4 from ..typing import AsyncGenerator
6 5 from .base_provider import AsyncGeneratorProvider
7 6
8
9 7 class AiAsk(AsyncGeneratorProvider):
10 8 url = "https://e.aiask.me"
11 9 supports_gpt_35_turbo = True
@@ -24,7 +22,7 @@ class AiAsk(AsyncGeneratorProvider):
24 22 "origin": cls.url,
25 23 "referer": f"{cls.url}/chat",
26 24 }
27 async with ClientSession(headers=headers, timeout=timeout) as session:
25 async with ClientSession(headers=headers, timeout=ClientTimeout(timeout)) as session:
28 26 data = {
29 27 "continuous": True,
30 28 "id": "fRMSQtuHl91A4De9cCvKD",
Modified g4f/Provider/Aichat.py +2 -2
@@ -1,6 +1,6 @@
1 1 from __future__ import annotations
2 2
3 from aiohttp import ClientSession
3 from aiohttp import ClientSession, ClientTimeout
4 4
5 5 from .base_provider import AsyncProvider, format_prompt
6 6
@@ -34,7 +34,7 @@ class Aichat(AsyncProvider):
34 34 "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",
35 35 }
36 36 async with ClientSession(
37 headers=headers, timeout=timeout
37 headers=headers, timeout=ClientTimeout(timeout)
38 38 ) as session:
39 39 json_data = {
40 40 "message": format_prompt(messages),
Modified g4f/Provider/Bing.py +1 -1
@@ -250,7 +250,7 @@ async def stream_generate(
250 250 conversation = await create_conversation(session)
251 251 try:
252 252 async with session.ws_connect(
253 f'wss://sydney.bing.com/sydney/ChatHub?sec_access_token={urllib.parse.quote_plus(conversation.conversationSignature)}',
253 f'wss://sydney.bing.com/sydney/ChatHub',
254 254 autoping=False,
255 255 params={'sec_access_token': conversation.conversationSignature}
256 256 ) as wss:
Modified g4f/Provider/ChatForAi.py +2 -12
@@ -1,7 +1,5 @@
1 1 from __future__ import annotations
2 2
3 import time, hashlib
4
5 3 from ..typing import AsyncGenerator
6 4 from ..requests import StreamSession
7 5 from .base_provider import AsyncGeneratorProvider
@@ -21,11 +19,9 @@ class ChatForAi(AsyncGeneratorProvider):
21 19 **kwargs
22 20 ) -> AsyncGenerator:
23 21 async with StreamSession(impersonate="chrome107", timeout=timeout) as session:
24 conversation_id = f"id_{int(time.time())}"
25 22 prompt = messages[-1]["content"]
26 timestamp = int(time.time())
27 23 data = {
28 "conversationId": conversation_id,
24 "conversationId": "temp",
29 25 "conversationType": "chat_continuous",
30 26 "botId": "chat_continuous",
31 27 "globalSettings":{
@@ -39,8 +35,6 @@ class ChatForAi(AsyncGeneratorProvider):
39 35 "botSettings": {},
40 36 "prompt": prompt,
41 37 "messages": messages,
42 "sign": generate_signature(timestamp, conversation_id, prompt),
43 "timestamp": timestamp
44 38 }
45 39 async with session.post(f"{cls.url}/api/handle/provider-openai", json=data) as response:
46 40 response.raise_for_status()
@@ -56,8 +50,4 @@ class ChatForAi(AsyncGeneratorProvider):
56 50 ("stream", "bool"),
57 51 ]
58 52 param = ", ".join([": ".join(p) for p in params])
59 return f"g4f.provider.{cls.__name__} supports: ({param})"
60
61 def generate_signature(timestamp, id, prompt):
62 data = f"{timestamp}:{id}:{prompt}:6B46K4pt"
63 return hashlib.sha256(data.encode()).hexdigest()
53 return f"g4f.provider.{cls.__name__} supports: ({param})"
Modified g4f/Provider/ChatgptAi.py +2 -2
@@ -1,7 +1,7 @@
1 1 from __future__ import annotations
2 2
3 3 import re
4 from aiohttp import ClientSession
4 from aiohttp import ClientSession, ClientTimeout
5 5
6 6 from .base_provider import AsyncProvider, format_prompt
7 7
@@ -40,7 +40,7 @@ class ChatgptAi(AsyncProvider):
40 40 "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",
41 41 }
42 42 async with ClientSession(
43 headers=headers, timeout=timeout
43 headers=headers, timeout=ClientTimeout(timeout)
44 44 ) as session:
45 45 if not cls._nonce:
46 46 async with session.get(cls.url, proxy=proxy) as response:
Modified g4f/Provider/ChatgptDemo.py +2 -2
@@ -1,7 +1,7 @@
1 1 from __future__ import annotations
2 2
3 3 import time, json, re
4 from aiohttp import ClientSession
4 from aiohttp import ClientSession, ClientTimeout
5 5 from typing import AsyncGenerator
6 6
7 7 from .base_provider import AsyncGeneratorProvider
@@ -34,7 +34,7 @@ class ChatgptDemo(AsyncGeneratorProvider):
34 34 "sec-fetch-site": "same-origin",
35 35 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
36 36 }
37 async with ClientSession(headers=headers, timeout=timeout) as session:
37 async with ClientSession(headers=headers, timeout=ClientTimeout(timeout)) as session:
38 38 async with session.get(f"{cls.url}/", proxy=proxy) as response:
39 39 response.raise_for_status()
40 40 response = await response.text()
Modified g4f/Provider/GptGo.py +2 -2
@@ -1,6 +1,6 @@
1 1 from __future__ import annotations
2 2
3 from aiohttp import ClientSession
3 from aiohttp import ClientSession, ClientTimeout
4 4 import json
5 5
6 6 from ..typing import AsyncGenerator
@@ -32,7 +32,7 @@ class GptGo(AsyncGeneratorProvider):
32 32 "Sec-Fetch-Site" : "same-origin",
33 33 }
34 34 async with ClientSession(
35 headers=headers, timeout=timeout
35 headers=headers, timeout=ClientTimeout(timeout)
36 36 ) as session:
37 37 async with session.get(
38 38 "https://gptgo.ai/action_get_token.php",
Modified g4f/Provider/Liaobots.py +2 -3
@@ -1,9 +1,8 @@
1 1 from __future__ import annotations
2 2
3 import json
4 3 import uuid
5 4
6 from aiohttp import ClientSession
5 from aiohttp import ClientSession, ClientTimeout
7 6
8 7 from ..typing import AsyncGenerator
9 8 from .base_provider import AsyncGeneratorProvider
@@ -55,7 +54,7 @@ class Liaobots(AsyncGeneratorProvider):
55 54 "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",
56 55 }
57 56 async with ClientSession(
58 headers=headers, timeout=timeout
57 headers=headers, timeout=ClientTimeout(timeout)
59 58 ) as session:
60 59 cls._auth_code = auth if isinstance(auth, str) else cls._auth_code
61 60 if not cls._auth_code:
Modified g4f/Provider/Vitalentum.py +2 -2
@@ -1,7 +1,7 @@
1 1 from __future__ import annotations
2 2
3 3 import json
4 from aiohttp import ClientSession
4 from aiohttp import ClientSession, ClientTimeout
5 5
6 6 from .base_provider import AsyncGeneratorProvider
7 7 from ..typing import AsyncGenerator
@@ -41,7 +41,7 @@ class Vitalentum(AsyncGeneratorProvider):
41 41 **kwargs
42 42 }
43 43 async with ClientSession(
44 headers=headers, timeout=timeout
44 headers=headers, timeout=ClientTimeout(timeout)
45 45 ) as session:
46 46 async with session.post(cls.url + "/api/converse-edge", json=data, proxy=proxy) as response:
47 47 response.raise_for_status()