~ | improve compatibility

pull/1281/head
abc 7 months ago
parent e8d88c955f
commit 9140541179

@ -24,7 +24,9 @@ def get_model_info() -> dict[str, Any]:
models_regex = r'let .="\\n\\nHuman:\",r=(.+?),.='
for script in scripts:
if matches := re.findall(models_regex, script):
matches = re.findall(models_regex, script)
if matches:
models_str = matches[0]
stop_sequences_regex = r"(?<=stopSequences:{value:\[)\D(?<!\])"
models_str = re.sub(

@ -27,7 +27,9 @@ class Chatgpt4Online(AsyncProvider):
async with session.get(f"{cls.url}/", proxy=proxy) as response:
response.raise_for_status()
response = await response.text()
if result := re.search(r'data-nonce="(.*?)"', response):
result = re.search(r'data-nonce="(.*?)"', response)
if result:
cls._wpnonce = result.group(1)
else:
raise RuntimeError("No nonce found")

@ -45,7 +45,9 @@ class ChatgptAi(AsyncGeneratorProvider):
async with session.get(cls.url, proxy=proxy) as response:
response.raise_for_status()
text = await response.text()
if result := re.search(r"data-system='(.*?)'", text):
result = re.search(r"data-system='(.*?)'", text)
if result :
cls._system = json.loads(html.unescape(result.group(1)))
if not cls._system:
raise RuntimeError("System args not found")

@ -37,10 +37,13 @@ class ChatgptDemo(AsyncGeneratorProvider):
async with session.get(f"{cls.url}/", proxy=proxy) as response:
response.raise_for_status()
response = await response.text()
if result := re.search(
result = re.search(
r'<div id="USERID" style="display: none">(.*?)<\/div>',
response,
):
)
if result:
user_id = result.group(1)
else:
raise RuntimeError("No user id found")
@ -59,5 +62,7 @@ class ChatgptDemo(AsyncGeneratorProvider):
async for line in response.content:
if line.startswith(b"data: "):
line = json.loads(line[6:-1])
if chunk := line["choices"][0]["delta"].get("content"):
chunk = line["choices"][0]["delta"].get("content")
if chunk:
yield chunk

@ -65,7 +65,8 @@ class ChatgptFree(AsyncProvider):
raise RuntimeError("No post id found")
cls._post_id = result.group(1)
if result := re.search(r'data-nonce="(.*?)"', response):
result = re.search(r'data-nonce="(.*?)"', response)
if result:
cls._nonce = result.group(1)
else:

@ -45,10 +45,12 @@ class ChatgptLogin(AsyncGeneratorProvider):
async with session.get(f"{cls.url}/chat/", proxy=proxy) as response:
response.raise_for_status()
response = await response.text()
if result := re.search(
result = re.search(
r'<div id="USERID" style="display: none">(.*?)<\/div>',
response,
):
)
if result:
cls._user_id = result.group(1)
else:
raise RuntimeError("No user id found")
@ -67,9 +69,10 @@ class ChatgptLogin(AsyncGeneratorProvider):
response.raise_for_status()
async for line in response.content:
if line.startswith(b"data: "):
if content := json.loads(line[6:])["choices"][0][
"delta"
].get("content"):
content = json.loads(line[6:])["choices"][0]["delta"].get("content")
if content:
yield content
async with session.post(f"{cls.url}/chat/delete_chat", json={"chat_id": chat_id}, proxy=proxy) as response:
response.raise_for_status()

@ -35,15 +35,21 @@ class ChatgptX(AsyncGeneratorProvider):
async with ClientSession(headers=headers) as session:
async with session.get(f"{cls.url}/", proxy=proxy) as response:
response = await response.text()
if result := re.search(
result = re.search(
r'<meta name="csrf-token" content="(.*?)"', response
):
)
if result:
csrf_token = result.group(1)
if result := re.search(r"openconversions\('(.*?)'\)", response):
result = re.search(r"openconversions\('(.*?)'\)", response)
if result:
chat_id = result.group(1)
if result := re.search(
result = re.search(
r'<input type="hidden" id="user_id" value="(.*?)"', response
):
)
if result:
user_id = result.group(1)
if not csrf_token or not chat_id or not user_id:

@ -47,12 +47,15 @@ class GptGod(AsyncGeneratorProvider):
response.raise_for_status()
event = None
async for line in response.content:
print(line)
# print(line)
if line.startswith(b'event: '):
event = line[7:-1]
elif event == b"data" and line.startswith(b"data: "):
if data := json.loads(line[6:-1]):
data = json.loads(line[6:-1])
if data:
yield data
elif event == b"done":
break

@ -6,10 +6,9 @@ from ..typing import Messages, TypedDict, CreateResult, Any
from .base_provider import BaseProvider
from ..debug import logging
class Vercel(BaseProvider):
url = 'https://sdk.vercel.ai'
working = True
working = False
supports_message_history = True
supports_gpt_35_turbo = True
supports_stream = True

@ -46,5 +46,7 @@ class CodeLinkAva(AsyncGeneratorProvider):
if line.startswith("data: [DONE]"):
break
line = json.loads(line[6:-1])
if content := line["choices"][0]["delta"].get("content"):
content = line["choices"][0]["delta"].get("content")
if content:
yield content

@ -65,5 +65,7 @@ class Equing(BaseProvider):
if line:
if b'content' in line:
line_json = json.loads(line.decode('utf-8').split('data: ')[1])
if token := line_json['choices'][0]['delta'].get('content'):
token = line_json['choices'][0]['delta'].get('content')
if token:
yield token

@ -69,9 +69,11 @@ class FastGpt(BaseProvider):
try:
if b'content' in line:
line_json = json.loads(line.decode('utf-8').split('data: ')[1])
if token := line_json['choices'][0]['delta'].get(
token = line_json['choices'][0]['delta'].get(
'content'
):
)
if token:
yield token
except:
continue

@ -38,6 +38,7 @@ class Lockchat(BaseProvider):
for token in response.iter_lines():
if b"The model: `gpt-4` does not exist" in token:
print("error, retrying...")
Lockchat.create_completion(
model = model,
messages = messages,
@ -47,5 +48,7 @@ class Lockchat(BaseProvider):
if b"content" in token:
token = json.loads(token.decode("utf-8").split("data: ")[1])
if token := token["choices"][0]["delta"].get("content"):
token = token["choices"][0]["delta"].get("content")
if token:
yield (token)

@ -49,5 +49,7 @@ class Vitalentum(AsyncGeneratorProvider):
if line.startswith("data: [DONE]"):
break
line = json.loads(line[6:-1])
if content := line["choices"][0]["delta"].get("content"):
content = line["choices"][0]["delta"].get("content")
if content:
yield content

@ -43,9 +43,12 @@ class ChatAiGpt(AsyncGeneratorProvider):
async with session.get(f"{cls.url}/", proxy=proxy) as response:
response.raise_for_status()
response = await response.text()
if result := re.search(
result = re.search(
r'data-nonce=(.*?) data-post-id=([0-9]+)', response
):
)
if result:
cls._nonce, cls._post_id = result.group(1), result.group(2)
else:
raise RuntimeError("No nonce found")

@ -48,7 +48,8 @@ class MikuChat(AsyncGeneratorProvider):
async for line in response.iter_lines():
if line.startswith(b"data: "):
line = json.loads(line[6:])
if chunk := line["choices"][0]["delta"].get("content"):
chunk = line["choices"][0]["delta"].get("content")
if chunk:
yield chunk
def k(e: str, t: int):

@ -11,7 +11,7 @@ with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as fh:
with open('requirements.txt') as f:
required = f.read().splitlines()
VERSION = '0.1.8.7'
VERSION = '0.1.8.8'
DESCRIPTION = (
'The official gpt4free repository | various collection of powerful language models'
)

Loading…
Cancel
Save