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

XFEstudio/gpt4free

Fix Opchatgpts and ChatForAi Provider Deprecate Vitalentum and Aivvm Provider

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

代码差异

11 个文件 +121 -106
Renamed g4f/Provider/ChatForAi.py +25 -8
@@ -1,12 +1,16 @@
1 1 from __future__ import annotations
2 2
3 from ...typing import AsyncResult, Messages
4 from ...requests import StreamSession
5 from ..base_provider import AsyncGeneratorProvider
3 import time
4 import hashlib
5
6 from ..typing import AsyncResult, Messages
7 from ..requests import StreamSession
8 from .base_provider import AsyncGeneratorProvider
6 9
7 10
8 11 class ChatForAi(AsyncGeneratorProvider):
9 url = "https://chatforai.com"
12 url = "https://chatforai.store"
13 working = True
10 14 supports_gpt_35_turbo = True
11 15
12 16 @classmethod
@@ -18,10 +22,17 @@ class ChatForAi(AsyncGeneratorProvider):
18 22 timeout: int = 120,
19 23 **kwargs
20 24 ) -> AsyncResult:
21 async with StreamSession(impersonate="chrome107", proxies={"https": proxy}, timeout=timeout) as session:
25 headers = {
26 "Content-Type": "text/plain;charset=UTF-8",
27 "Origin": cls.url,
28 "Referer": f"{cls.url}/?r=b",
29 }
30 async with StreamSession(impersonate="chrome107", headers=headers, proxies={"https": proxy}, timeout=timeout) as session:
22 31 prompt = messages[-1]["content"]
32 timestamp = int(time.time() * 1e3)
33 conversation_id = f"id_{timestamp-123}"
23 34 data = {
24 "conversationId": "temp",
35 "conversationId": conversation_id,
25 36 "conversationType": "chat_continuous",
26 37 "botId": "chat_continuous",
27 38 "globalSettings":{
@@ -33,8 +44,10 @@ class ChatForAi(AsyncGeneratorProvider):
33 44 **kwargs
34 45 },
35 46 "botSettings": {},
36 "prompt": prompt,
47 "prompt": prompt,
37 48 "messages": messages,
49 "timestamp": timestamp,
50 "sign": generate_signature(timestamp, prompt, conversation_id)
38 51 }
39 52 async with session.post(f"{cls.url}/api/handle/provider-openai", json=data) as response:
40 53 response.raise_for_status()
@@ -52,4 +65,8 @@ class ChatForAi(AsyncGeneratorProvider):
52 65 ("stream", "bool"),
53 66 ]
54 67 param = ", ".join([": ".join(p) for p in params])
55 return f"g4f.provider.{cls.__name__} supports: ({param})"
68 return f"g4f.provider.{cls.__name__} supports: ({param})"
69
70 def generate_signature(timestamp: int, message: str, id: str):
71 buffer = f"{timestamp}:{id}:{message}:7YN8z6d6"
72 return hashlib.sha256(buffer.encode()).hexdigest()
Modified g4f/Provider/GptForLove.py +6 -7
@@ -42,11 +42,10 @@ class GptForLove(AsyncGeneratorProvider):
42 42 data = {
43 43 "prompt": prompt,
44 44 "options": {},
45 "systemMessage": "You are ChatGPT, the version is GPT3.5, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.",
46 "temperature": 0.8,
47 "top_p": 1,
45 "systemMessage": kwargs.get("system_message", "You are ChatGPT, the version is GPT3.5, a large language model trained by OpenAI. Follow the user's instructions carefully."),
46 "temperature": kwargs.get("temperature", 0.8),
47 "top_p": kwargs.get("top_p", 1),
48 48 "secret": get_secret(),
49 **kwargs
50 49 }
51 50 async with session.post("https://api.gptplus.one/chat-process", json=data, proxy=proxy) as response:
52 51 response.raise_for_status()
@@ -67,9 +66,9 @@ class GptForLove(AsyncGeneratorProvider):
67 66
68 67 def get_secret() -> str:
69 68 dir = os.path.dirname(__file__)
70 dir += '/npm/node_modules/crypto-js'
69 include = dir + '/npm/node_modules/crypto-js/crypto-js'
71 70 source = """
72 CryptoJS = require('{dir}/crypto-js')
71 CryptoJS = require({include})
73 72 var k = '14487141bvirvvG'
74 73 , e = Math.floor(new Date().getTime() / 1e3);
75 74 var t = CryptoJS.enc.Utf8.parse(e)
@@ -79,5 +78,5 @@ var t = CryptoJS.enc.Utf8.parse(e)
79 78 });
80 79 return o.toString()
81 80 """
82 source = source.replace('{dir}', dir)
81 source = source.replace('{include}', json.dumps(include))
83 82 return execjs.compile(source).call('')
Added g4f/Provider/Opchatgpts.py +76 -0
@@ -0,0 +1,76 @@
1 from __future__ import annotations
2
3 import random, string, json
4 from aiohttp import ClientSession
5
6 from ..typing import Messages, AsyncResult
7 from .base_provider import AsyncGeneratorProvider
8
9
10 class Opchatgpts(AsyncGeneratorProvider):
11 url = "https://opchatgpts.net"
12 supports_gpt_35_turbo = True
13 working = True
14
15 @classmethod
16 async def create_async_generator(
17 cls,
18 model: str,
19 messages: Messages,
20 proxy: str = None,
21 **kwargs
22 ) -> AsyncResult:
23 headers = {
24 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
25 "Accept" : "*/*",
26 "Accept-Language" : "de,en-US;q=0.7,en;q=0.3",
27 "Origin" : cls.url,
28 "Alt-Used" : "opchatgpts.net",
29 "Referer" : f"{cls.url}/chatgpt-free-use/",
30 "Sec-Fetch-Dest" : "empty",
31 "Sec-Fetch-Mode" : "cors",
32 "Sec-Fetch-Site" : "same-origin",
33 }
34 async with ClientSession(
35 headers=headers
36 ) as session:
37 data = {
38 "botId": "default",
39 "chatId": random_string(),
40 "contextId": 28,
41 "customId": None,
42 "messages": messages,
43 "newMessage": messages[-1]["content"],
44 "session": "N/A",
45 "stream": True
46 }
47 async with session.post(f"{cls.url}/wp-json/mwai-ui/v1/chats/submit", json=data, proxy=proxy) as response:
48 response.raise_for_status()
49 async for line in response.content:
50 if line.startswith(b"data: "):
51 try:
52 line = json.loads(line[6:])
53 assert "type" in line
54 except:
55 raise RuntimeError(f"Broken line: {line.decode()}")
56 if line["type"] == "live":
57 yield line["data"]
58 elif line["type"] == "end":
59 break
60
61
62 @classmethod
63 @property
64 def params(cls):
65 params = [
66 ("model", "str"),
67 ("messages", "list[dict[str, str]]"),
68 ("stream", "bool"),
69 ("proxy", "str"),
70 ]
71 param = ", ".join([": ".join(p) for p in params])
72 return f"g4f.provider.{cls.__name__} supports: ({param})"
73
74
75 def random_string(length: int = 10):
76 return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(length))
Modified g4f/Provider/__init__.py +2 -2
@@ -4,11 +4,11 @@ from .AiAsk import AiAsk
4 4 from .Aibn import Aibn
5 5 from .Aichat import Aichat
6 6 from .Ails import Ails
7 from .Aivvm import Aivvm
8 7 from .AItianhu import AItianhu
9 8 from .AItianhuSpace import AItianhuSpace
10 9 from .Bing import Bing
11 10 from .ChatBase import ChatBase
11 from .ChatForAi import ChatForAi
12 12 from .Chatgpt4Online import Chatgpt4Online
13 13 from .ChatgptAi import ChatgptAi
14 14 from .ChatgptDemo import ChatgptDemo
@@ -26,9 +26,9 @@ from .GptGod import GptGod
26 26 from .H2o import H2o
27 27 from .Liaobots import Liaobots
28 28 from .Myshell import Myshell
29 from .Opchatgpts import Opchatgpts
29 30 from .Phind import Phind
30 31 from .Vercel import Vercel
31 from .Vitalentum import Vitalentum
32 32 from .Ylokh import Ylokh
33 33 from .You import You
34 34 from .Yqcloud import Yqcloud
Renamed g4f/Provider/deprecated/Aivvm.py +3 -3
@@ -1,8 +1,8 @@
1 1 from __future__ import annotations
2 2 import requests
3 3
4 from .base_provider import BaseProvider
5 from ..typing import CreateResult
4 from ..base_provider import BaseProvider
5 from ...typing import CreateResult, Messages
6 6 from json import dumps
7 7
8 8 # to recreate this easily, send a post request to https://chat.aivvm.com/api/models
@@ -27,7 +27,7 @@ class Aivvm(BaseProvider):
27 27 @classmethod
28 28 def create_completion(cls,
29 29 model: str,
30 messages: list[dict[str, str]],
30 messages: Messages,
31 31 stream: bool,
32 32 **kwargs
33 33 ) -> CreateResult:
Deleted g4f/Provider/deprecated/Opchatgpts.py +0 -74
@@ -1,74 +0,0 @@
1 from __future__ import annotations
2
3 import os, re
4 from aiohttp import ClientSession
5
6 from ..base_provider import AsyncProvider, format_prompt
7
8
9 class Opchatgpts(AsyncProvider):
10 url = "https://opchatgpts.net"
11 supports_gpt_35_turbo = True
12 working = True
13 _nonce = None
14
15 @classmethod
16 async def create_async(
17 cls,
18 model: str,
19 messages: list[dict[str, str]],
20 **kwargs
21 ) -> str:
22 headers = {
23 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
24 "Accept" : "*/*",
25 "Accept-language" : "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3",
26 "Origin" : "https://opchatgpts.net",
27 "Alt-Used" : "opchatgpts.net",
28 "Referer" : "https://opchatgpts.net/chatgpt-free-use/",
29 "Sec-Fetch-Dest" : "empty",
30 "Sec-Fetch-Mode" : "cors",
31 "Sec-Fetch-Site" : "same-origin",
32 }
33 async with ClientSession(
34 headers=headers
35 ) as session:
36 if not cls._nonce:
37 async with session.get(
38 "https://opchatgpts.net/chatgpt-free-use/",
39 params={"id": os.urandom(6).hex()},
40 ) as response:
41 result = re.search(r'data-nonce="(.*?)"', await response.text())
42 if not result:
43 raise RuntimeError("No nonce value")
44 cls._nonce = result.group(1)
45 data = {
46 "_wpnonce": cls._nonce,
47 "post_id": 28,
48 "url": "https://opchatgpts.net/chatgpt-free-use",
49 "action": "wpaicg_chat_shortcode_message",
50 "message": format_prompt(messages),
51 "bot_id": 0
52 }
53 async with session.post("https://opchatgpts.net/wp-admin/admin-ajax.php", data=data) as response:
54 response.raise_for_status()
55 data = await response.json()
56 if "data" in data:
57 return data["data"]
58 elif "msg" in data:
59 raise RuntimeError(data["msg"])
60 else:
61 raise RuntimeError(f"Response: {data}")
62
63
64 @classmethod
65 @property
66 def params(cls):
67 params = [
68 ("model", "str"),
69 ("messages", "list[dict[str, str]]"),
70 ("stream", "bool"),
71 ("temperature", "float"),
72 ]
73 param = ", ".join([": ".join(p) for p in params])
74 return f"g4f.provider.{cls.__name__} supports: ({param})"
Renamed g4f/Provider/deprecated/Vitalentum.py +2 -3
@@ -3,12 +3,11 @@ from __future__ import annotations
3 3 import json
4 4 from aiohttp import ClientSession
5 5
6 from .base_provider import AsyncGeneratorProvider
7 from ..typing import AsyncResult, Messages
6 from ..base_provider import AsyncGeneratorProvider
7 from ...typing import AsyncResult, Messages
8 8
9 9 class Vitalentum(AsyncGeneratorProvider):
10 10 url = "https://app.vitalentum.io"
11 working = True
12 11 supports_gpt_35_turbo = True
13 12
14 13
Modified g4f/Provider/deprecated/__init__.py +2 -2
@@ -4,11 +4,11 @@ from .DfeHub import DfeHub
4 4 from .EasyChat import EasyChat
5 5 from .Forefront import Forefront
6 6 from .GetGpt import GetGpt
7 from .Opchatgpts import Opchatgpts
8 7 from .Lockchat import Lockchat
9 8 from .Wewordle import Wewordle
10 9 from .Equing import Equing
11 10 from .Wuguokai import Wuguokai
12 11 from .V50 import V50
13 12 from .FastGpt import FastGpt
14 from .ChatForAi import ChatForAi
13 from .Aivvm import Aivvm
14 from .Vitalentum import Vitalentum
Modified g4f/Provider/unfinished/ChatAiGpt.py +0 -1
@@ -11,7 +11,6 @@ from ..helper import format_prompt
11 11 class ChatAiGpt(AsyncGeneratorProvider):
12 12 url = "https://chataigpt.org"
13 13 supports_gpt_35_turbo = True
14 working = True
15 14 _nonce = None
16 15 _post_id = None
17 16
Modified g4f/Provider/unfinished/TalkAi.py +0 -1
@@ -9,7 +9,6 @@ from ..base_provider import AsyncGeneratorProvider
9 9 class TalkAi(AsyncGeneratorProvider):
10 10 url = "https://talkai.info"
11 11 supports_gpt_35_turbo = True
12 working = True
13 12
14 13 @classmethod
15 14 async def create_async_generator(
Modified g4f/models.py +5 -5
@@ -7,8 +7,10 @@ from .Provider import (
7 7 ChatgptLogin,
8 8 ChatgptDemo,
9 9 ChatgptDuo,
10 Vitalentum,
10 GptForLove,
11 Opchatgpts,
11 12 ChatgptAi,
13 GptChatly,
12 14 AItianhu,
13 15 ChatBase,
14 16 Liaobots,
@@ -18,7 +20,6 @@ from .Provider import (
18 20 Vercel,
19 21 Aichat,
20 22 GPTalk,
21 GptGod,
22 23 AiAsk,
23 24 GptGo,
24 25 Ylokh,
@@ -52,9 +53,8 @@ gpt_35_long = Model(
52 53 name = 'gpt-3.5-turbo',
53 54 base_provider = 'openai',
54 55 best_provider = RetryProvider([
55 AiAsk, Aibn, Aichat, ChatgptAi, ChatgptDemo, ChatgptDuo,
56 FreeGpt, GptGo, Liaobots, Myshell, Vitalentum, Ylokh, You, Yqcloud,
57 GPTalk, GptGod
56 AiAsk, Aichat, ChatgptDemo, FreeGpt, GptGo, Liaobots, You,
57 GPTalk, ChatgptLogin, GptChatly, GptForLove, Opchatgpts,
58 58 ])
59 59 )
60 60