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

XFEstudio/gpt4free

~ | improve compatibility

91405411
abc <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

17 个文件 +69 -31
Modified etc/tool/vercel.py +3 -1
@@ -24,7 +24,9 @@ def get_model_info() -> dict[str, Any]:
24 24
25 25 models_regex = r'let .="\\n\\nHuman:\",r=(.+?),.='
26 26 for script in scripts:
27 if matches := re.findall(models_regex, script):
27
28 matches = re.findall(models_regex, script)
29 if matches:
28 30 models_str = matches[0]
29 31 stop_sequences_regex = r"(?<=stopSequences:{value:\[)\D(?<!\])"
30 32 models_str = re.sub(
Modified g4f/Provider/Chatgpt4Online.py +3 -1
@@ -27,7 +27,9 @@ class Chatgpt4Online(AsyncProvider):
27 27 async with session.get(f"{cls.url}/", proxy=proxy) as response:
28 28 response.raise_for_status()
29 29 response = await response.text()
30 if result := re.search(r'data-nonce="(.*?)"', response):
30 result = re.search(r'data-nonce="(.*?)"', response)
31
32 if result:
31 33 cls._wpnonce = result.group(1)
32 34 else:
33 35 raise RuntimeError("No nonce found")
Modified g4f/Provider/ChatgptAi.py +3 -1
@@ -45,7 +45,9 @@ class ChatgptAi(AsyncGeneratorProvider):
45 45 async with session.get(cls.url, proxy=proxy) as response:
46 46 response.raise_for_status()
47 47 text = await response.text()
48 if result := re.search(r"data-system='(.*?)'", text):
48
49 result = re.search(r"data-system='(.*?)'", text)
50 if result :
49 51 cls._system = json.loads(html.unescape(result.group(1)))
50 52 if not cls._system:
51 53 raise RuntimeError("System args not found")
Modified g4f/Provider/ChatgptDemo.py +8 -3
@@ -37,10 +37,13 @@ class ChatgptDemo(AsyncGeneratorProvider):
37 37 async with session.get(f"{cls.url}/", proxy=proxy) as response:
38 38 response.raise_for_status()
39 39 response = await response.text()
40 if result := re.search(
40
41 result = re.search(
41 42 r'<div id="USERID" style="display: none">(.*?)<\/div>',
42 43 response,
43 ):
44 )
45
46 if result:
44 47 user_id = result.group(1)
45 48 else:
46 49 raise RuntimeError("No user id found")
@@ -59,5 +62,7 @@ class ChatgptDemo(AsyncGeneratorProvider):
59 62 async for line in response.content:
60 63 if line.startswith(b"data: "):
61 64 line = json.loads(line[6:-1])
62 if chunk := line["choices"][0]["delta"].get("content"):
65
66 chunk = line["choices"][0]["delta"].get("content")
67 if chunk:
63 68 yield chunk
Modified g4f/Provider/ChatgptFree.py +2 -1
@@ -65,7 +65,8 @@ class ChatgptFree(AsyncProvider):
65 65 raise RuntimeError("No post id found")
66 66 cls._post_id = result.group(1)
67 67
68 if result := re.search(r'data-nonce="(.*?)"', response):
68 result = re.search(r'data-nonce="(.*?)"', response)
69 if result:
69 70 cls._nonce = result.group(1)
70 71
71 72 else:
Modified g4f/Provider/ChatgptLogin.py +8 -5
@@ -45,10 +45,12 @@ class ChatgptLogin(AsyncGeneratorProvider):
45 45 async with session.get(f"{cls.url}/chat/", proxy=proxy) as response:
46 46 response.raise_for_status()
47 47 response = await response.text()
48 if result := re.search(
48 result = re.search(
49 49 r'<div id="USERID" style="display: none">(.*?)<\/div>',
50 50 response,
51 ):
51 )
52
53 if result:
52 54 cls._user_id = result.group(1)
53 55 else:
54 56 raise RuntimeError("No user id found")
@@ -67,9 +69,10 @@ class ChatgptLogin(AsyncGeneratorProvider):
67 69 response.raise_for_status()
68 70 async for line in response.content:
69 71 if line.startswith(b"data: "):
70 if content := json.loads(line[6:])["choices"][0][
71 "delta"
72 ].get("content"):
72
73 content = json.loads(line[6:])["choices"][0]["delta"].get("content")
74 if content:
73 75 yield content
76
74 77 async with session.post(f"{cls.url}/chat/delete_chat", json={"chat_id": chat_id}, proxy=proxy) as response:
75 78 response.raise_for_status()
Modified g4f/Provider/ChatgptX.py +11 -5
@@ -35,15 +35,21 @@ class ChatgptX(AsyncGeneratorProvider):
35 35 async with ClientSession(headers=headers) as session:
36 36 async with session.get(f"{cls.url}/", proxy=proxy) as response:
37 37 response = await response.text()
38 if result := re.search(
38
39 result = re.search(
39 40 r'<meta name="csrf-token" content="(.*?)"', response
40 ):
41 )
42 if result:
41 43 csrf_token = result.group(1)
42 if result := re.search(r"openconversions\('(.*?)'\)", response):
44
45 result = re.search(r"openconversions\('(.*?)'\)", response)
46 if result:
43 47 chat_id = result.group(1)
44 if result := re.search(
48
49 result = re.search(
45 50 r'<input type="hidden" id="user_id" value="(.*?)"', response
46 ):
51 )
52 if result:
47 53 user_id = result.group(1)
48 54
49 55 if not csrf_token or not chat_id or not user_id:
Modified g4f/Provider/GptGod.py +5 -2
@@ -47,12 +47,15 @@ class GptGod(AsyncGeneratorProvider):
47 47 response.raise_for_status()
48 48 event = None
49 49 async for line in response.content:
50 print(line)
50 # print(line)
51 51
52 52 if line.startswith(b'event: '):
53 53 event = line[7:-1]
54
54 55 elif event == b"data" and line.startswith(b"data: "):
55 if data := json.loads(line[6:-1]):
56 data = json.loads(line[6:-1])
57 if data:
56 58 yield data
59
57 60 elif event == b"done":
58 61 break
Modified g4f/Provider/Vercel.py +1 -2
@@ -6,10 +6,9 @@ from ..typing import Messages, TypedDict, CreateResult, Any
6 6 from .base_provider import BaseProvider
7 7 from ..debug import logging
8 8
9
10 9 class Vercel(BaseProvider):
11 10 url = 'https://sdk.vercel.ai'
12 working = True
11 working = False
13 12 supports_message_history = True
14 13 supports_gpt_35_turbo = True
15 14 supports_stream = True
Modified g4f/Provider/deprecated/CodeLinkAva.py +3 -1
@@ -46,5 +46,7 @@ class CodeLinkAva(AsyncGeneratorProvider):
46 46 if line.startswith("data: [DONE]"):
47 47 break
48 48 line = json.loads(line[6:-1])
49 if content := line["choices"][0]["delta"].get("content"):
49
50 content = line["choices"][0]["delta"].get("content")
51 if content:
50 52 yield content
Modified g4f/Provider/deprecated/Equing.py +3 -1
@@ -65,5 +65,7 @@ class Equing(BaseProvider):
65 65 if line:
66 66 if b'content' in line:
67 67 line_json = json.loads(line.decode('utf-8').split('data: ')[1])
68 if token := line_json['choices'][0]['delta'].get('content'):
68
69 token = line_json['choices'][0]['delta'].get('content')
70 if token:
69 71 yield token
Modified g4f/Provider/deprecated/FastGpt.py +4 -2
@@ -69,9 +69,11 @@ class FastGpt(BaseProvider):
69 69 try:
70 70 if b'content' in line:
71 71 line_json = json.loads(line.decode('utf-8').split('data: ')[1])
72 if token := line_json['choices'][0]['delta'].get(
72 token = line_json['choices'][0]['delta'].get(
73 73 'content'
74 ):
74 )
75
76 if token:
75 77 yield token
76 78 except:
77 79 continue
Modified g4f/Provider/deprecated/Lockchat.py +4 -1
Modified g4f/Provider/deprecated/Vitalentum.py +3 -1
Modified g4f/Provider/unfinished/ChatAiGpt.py +5 -2
Modified g4f/Provider/unfinished/MikuChat.py +2 -1
Modified setup.py +1 -1