mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-15 06:13:01 +00:00
~ | Merge pull request #997 from hlohaus/all
Fix timeout in create_async
This commit is contained in:
commit
796e4d7b55
@ -1,11 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
|
||||||
from ..typing import AsyncGenerator
|
from ..typing import AsyncGenerator
|
||||||
from .base_provider import AsyncGeneratorProvider
|
from .base_provider import AsyncGeneratorProvider
|
||||||
|
|
||||||
|
|
||||||
class AiAsk(AsyncGeneratorProvider):
|
class AiAsk(AsyncGeneratorProvider):
|
||||||
url = "https://e.aiask.me"
|
url = "https://e.aiask.me"
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
@ -24,7 +22,7 @@ class AiAsk(AsyncGeneratorProvider):
|
|||||||
"origin": cls.url,
|
"origin": cls.url,
|
||||||
"referer": f"{cls.url}/chat",
|
"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 = {
|
data = {
|
||||||
"continuous": True,
|
"continuous": True,
|
||||||
"id": "fRMSQtuHl91A4De9cCvKD",
|
"id": "fRMSQtuHl91A4De9cCvKD",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
|
||||||
from .base_provider import AsyncProvider, format_prompt
|
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",
|
"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(
|
async with ClientSession(
|
||||||
headers=headers, timeout=timeout
|
headers=headers, timeout=ClientTimeout(timeout)
|
||||||
) as session:
|
) as session:
|
||||||
json_data = {
|
json_data = {
|
||||||
"message": format_prompt(messages),
|
"message": format_prompt(messages),
|
||||||
|
@ -250,7 +250,7 @@ async def stream_generate(
|
|||||||
conversation = await create_conversation(session)
|
conversation = await create_conversation(session)
|
||||||
try:
|
try:
|
||||||
async with session.ws_connect(
|
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,
|
autoping=False,
|
||||||
params={'sec_access_token': conversation.conversationSignature}
|
params={'sec_access_token': conversation.conversationSignature}
|
||||||
) as wss:
|
) as wss:
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import time, hashlib
|
|
||||||
|
|
||||||
from ..typing import AsyncGenerator
|
from ..typing import AsyncGenerator
|
||||||
from ..requests import StreamSession
|
from ..requests import StreamSession
|
||||||
from .base_provider import AsyncGeneratorProvider
|
from .base_provider import AsyncGeneratorProvider
|
||||||
@ -21,11 +19,9 @@ class ChatForAi(AsyncGeneratorProvider):
|
|||||||
**kwargs
|
**kwargs
|
||||||
) -> AsyncGenerator:
|
) -> AsyncGenerator:
|
||||||
async with StreamSession(impersonate="chrome107", timeout=timeout) as session:
|
async with StreamSession(impersonate="chrome107", timeout=timeout) as session:
|
||||||
conversation_id = f"id_{int(time.time())}"
|
|
||||||
prompt = messages[-1]["content"]
|
prompt = messages[-1]["content"]
|
||||||
timestamp = int(time.time())
|
|
||||||
data = {
|
data = {
|
||||||
"conversationId": conversation_id,
|
"conversationId": "temp",
|
||||||
"conversationType": "chat_continuous",
|
"conversationType": "chat_continuous",
|
||||||
"botId": "chat_continuous",
|
"botId": "chat_continuous",
|
||||||
"globalSettings":{
|
"globalSettings":{
|
||||||
@ -39,8 +35,6 @@ class ChatForAi(AsyncGeneratorProvider):
|
|||||||
"botSettings": {},
|
"botSettings": {},
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"messages": messages,
|
"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:
|
async with session.post(f"{cls.url}/api/handle/provider-openai", json=data) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@ -56,8 +50,4 @@ class ChatForAi(AsyncGeneratorProvider):
|
|||||||
("stream", "bool"),
|
("stream", "bool"),
|
||||||
]
|
]
|
||||||
param = ", ".join([": ".join(p) for p in params])
|
param = ", ".join([": ".join(p) for p in params])
|
||||||
return f"g4f.provider.{cls.__name__} supports: ({param})"
|
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()
|
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
|
||||||
from .base_provider import AsyncProvider, format_prompt
|
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",
|
"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(
|
async with ClientSession(
|
||||||
headers=headers, timeout=timeout
|
headers=headers, timeout=ClientTimeout(timeout)
|
||||||
) as session:
|
) as session:
|
||||||
if not cls._nonce:
|
if not cls._nonce:
|
||||||
async with session.get(cls.url, proxy=proxy) as response:
|
async with session.get(cls.url, proxy=proxy) as response:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import time, json, re
|
import time, json, re
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
|
|
||||||
from .base_provider import AsyncGeneratorProvider
|
from .base_provider import AsyncGeneratorProvider
|
||||||
@ -34,7 +34,7 @@ class ChatgptDemo(AsyncGeneratorProvider):
|
|||||||
"sec-fetch-site": "same-origin",
|
"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"
|
"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:
|
async with session.get(f"{cls.url}/", proxy=proxy) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
response = await response.text()
|
response = await response.text()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ..typing import AsyncGenerator
|
from ..typing import AsyncGenerator
|
||||||
@ -32,7 +32,7 @@ class GptGo(AsyncGeneratorProvider):
|
|||||||
"Sec-Fetch-Site" : "same-origin",
|
"Sec-Fetch-Site" : "same-origin",
|
||||||
}
|
}
|
||||||
async with ClientSession(
|
async with ClientSession(
|
||||||
headers=headers, timeout=timeout
|
headers=headers, timeout=ClientTimeout(timeout)
|
||||||
) as session:
|
) as session:
|
||||||
async with session.get(
|
async with session.get(
|
||||||
"https://gptgo.ai/action_get_token.php",
|
"https://gptgo.ai/action_get_token.php",
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
|
||||||
from ..typing import AsyncGenerator
|
from ..typing import AsyncGenerator
|
||||||
from .base_provider import AsyncGeneratorProvider
|
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",
|
"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(
|
async with ClientSession(
|
||||||
headers=headers, timeout=timeout
|
headers=headers, timeout=ClientTimeout(timeout)
|
||||||
) as session:
|
) as session:
|
||||||
cls._auth_code = auth if isinstance(auth, str) else cls._auth_code
|
cls._auth_code = auth if isinstance(auth, str) else cls._auth_code
|
||||||
if not cls._auth_code:
|
if not cls._auth_code:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
|
||||||
from .base_provider import AsyncGeneratorProvider
|
from .base_provider import AsyncGeneratorProvider
|
||||||
from ..typing import AsyncGenerator
|
from ..typing import AsyncGenerator
|
||||||
@ -41,7 +41,7 @@ class Vitalentum(AsyncGeneratorProvider):
|
|||||||
**kwargs
|
**kwargs
|
||||||
}
|
}
|
||||||
async with ClientSession(
|
async with ClientSession(
|
||||||
headers=headers, timeout=timeout
|
headers=headers, timeout=ClientTimeout(timeout)
|
||||||
) as session:
|
) as session:
|
||||||
async with session.post(cls.url + "/api/converse-edge", json=data, proxy=proxy) as response:
|
async with session.post(cls.url + "/api/converse-edge", json=data, proxy=proxy) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
Loading…
Reference in New Issue
Block a user