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

XFEstudio/gpt4free

dmca

45ef06d5
Tekky <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

2 个文件 +0 -79
Deleted g4f/Provider/not_working/Chatgpt4Online.py +0 -78
@@ -1,78 +0,0 @@
1 from __future__ import annotations
2
3 import json
4 from aiohttp import ClientSession
5
6 from ...typing import AsyncResult, Messages
7 from ..base_provider import AsyncGeneratorProvider
8 from ..helper import format_prompt
9
10
11 class Chatgpt4Online(AsyncGeneratorProvider):
12 url = "https://chatgpt4online.org"
13 api_endpoint = "/wp-json/mwai-ui/v1/chats/submit"
14 working = False
15
16 default_model = 'gpt-4'
17 models = [default_model]
18
19 async def get_nonce(headers: dict) -> str:
20 async with ClientSession(headers=headers) as session:
21 async with session.post(f"https://chatgpt4online.org/wp-json/mwai/v1/start_session") as response:
22 return (await response.json())["restNonce"]
23
24 @classmethod
25 async def create_async_generator(
26 cls,
27 model: str,
28 messages: Messages,
29 proxy: str = None,
30 **kwargs
31 ) -> AsyncResult:
32 headers = {
33 "accept": "text/event-stream",
34 "accept-language": "en-US,en;q=0.9",
35 "content-type": "application/json",
36 "dnt": "1",
37 "origin": cls.url,
38 "priority": "u=1, i",
39 "referer": f"{cls.url}/",
40 "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
41 "sec-ch-ua-mobile": "?0",
42 "sec-ch-ua-platform": '"Linux"',
43 "sec-fetch-dest": "empty",
44 "sec-fetch-mode": "cors",
45 "sec-fetch-site": "same-origin",
46 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
47 }
48 headers['x-wp-nonce'] = await cls.get_nonce(headers)
49 async with ClientSession(headers=headers) as session:
50 prompt = format_prompt(messages)
51 data = {
52 "botId": "default",
53 "newMessage": prompt,
54 "stream": True,
55 }
56
57 async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response:
58 response.raise_for_status()
59 full_response = ""
60
61 async for chunk in response.content.iter_any():
62 if chunk:
63 try:
64 # Extract the JSON object from the chunk
65 for line in chunk.decode().splitlines():
66 if line.startswith("data: "):
67 json_data = json.loads(line[6:])
68 if json_data["type"] == "live":
69 full_response += json_data["data"]
70 elif json_data["type"] == "end":
71 final_data = json.loads(json_data["data"])
72 full_response = final_data["reply"]
73 break
74 except json.JSONDecodeError:
75 continue
76
77 yield full_response
78
Modified g4f/Provider/not_working/__init__.py +0 -1
@@ -9,7 +9,6 @@ from .AmigoChat import AmigoChat
9 9 from .Aura import Aura
10 10 from .ChatGpt import ChatGpt
11 11 from .Chatgpt4o import Chatgpt4o
12 from .Chatgpt4Online import Chatgpt4Online
13 12 from .ChatGptEs import ChatGptEs
14 13 from .ChatgptFree import ChatgptFree
15 14 from .ChatGptt import ChatGptt