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

XFEstudio/gpt4free

Add Cromicle to provider list

4a9d7714
Heiner Lohaus <heiner@lohaus.eu>
提交于

代码差异

6 个文件 +66 -28
Modified g4f/Provider/ChatgptX.py +38 -11
@@ -1,25 +1,26 @@
1 1 from __future__ import annotations
2 2
3 3 import re
4 import json
4 5
5 6 from aiohttp import ClientSession
6
7 from .base_provider import AsyncProvider
7 from typing import AsyncGenerator, Dict, List
8 from .base_provider import AsyncGeneratorProvider
8 9 from .helper import format_prompt
9 10
10 11
11 class ChatgptX(AsyncProvider):
12 class ChatgptX(AsyncGeneratorProvider):
12 13 url = "https://chatgptx.de"
13 14 supports_gpt_35_turbo = True
14 15 working = True
15 16
16 17 @classmethod
17 async def create_async(
18 async def create_async_generator(
18 19 cls,
19 20 model: str,
20 messages: list[dict[str, str]],
21 messages: List[Dict[str, str]],
21 22 **kwargs
22 ) -> str:
23 ) -> AsyncGenerator[str, None]:
23 24 headers = {
24 25 'accept-language': 'de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US',
25 26 'sec-ch-ua': '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
@@ -63,8 +64,34 @@ class ChatgptX(AsyncProvider):
63 64 }
64 65 async with session.post(cls.url + '/sendchat', data=data, headers=headers) as response:
65 66 response.raise_for_status()
66 data = await response.json()
67 if "message" in data:
68 return data["message"]
69 elif "messages" in data:
70 raise RuntimeError(f'Response: {data["messages"]}')
67 chat = await response.json()
68 if "response" not in chat or not chat["response"]:
69 raise RuntimeError(f'Response: {data}')
70 headers = {
71 'authority': 'chatgptx.de',
72 'accept': 'text/event-stream',
73 'referer': f'{cls.url}/',
74 'x-csrf-token': csrf_token,
75 'x-requested-with': 'XMLHttpRequest'
76 }
77 data = {
78 "user_id": user_id,
79 "chats_id": chat_id,
80 "prompt": format_prompt(messages),
81 "current_model": "gpt3",
82 "conversions_id": chat["conversions_id"],
83 "ass_conversions_id": chat["ass_conversions_id"],
84 }
85 async with session.get(f'{cls.url}/chats_stream', params=data, headers=headers) as response:
86 response.raise_for_status()
87 async for line in response.content:
88 if line.startswith(b"data: "):
89 row = line[6:-1]
90 if row == b"[DONE]":
91 break
92 try:
93 content = json.loads(row)["choices"][0]["delta"].get("content")
94 except:
95 raise RuntimeError(f"Broken line: {line.decode()}")
96 if content:
97 yield content
Modified g4f/Provider/Cromicle.py +15 -15
@@ -2,32 +2,32 @@ from __future__ import annotations
2 2
3 3 from aiohttp import ClientSession
4 4 from hashlib import sha256
5 from typing import AsyncGenerator, Dict, List
5 6
6 from ..typing import AsyncGenerator
7 7 from .base_provider import AsyncGeneratorProvider
8 from .helper import format_prompt
8 9
9 10
10 11 class Cromicle(AsyncGeneratorProvider):
11 url = 'https://cromicle.top'
12 working = True
13 supports_gpt_35_turbo = True
12 url: str = 'https://cromicle.top'
13 working: bool = True
14 supports_gpt_35_turbo: bool = True
14 15
15 16 @classmethod
16 17 async def create_async_generator(
17 18 cls,
18 19 model: str,
19 messages: list[dict[str, str]],
20 messages: List[Dict[str, str]],
20 21 proxy: str = None,
21 22 **kwargs
22 ) -> AsyncGenerator:
23 message = messages[-1]["content"]
23 ) -> AsyncGenerator[str, None]:
24 24 async with ClientSession(
25 25 headers=_create_header()
26 26 ) as session:
27 27 async with session.post(
28 cls.url + '/chat',
28 f'{cls.url}/chat',
29 29 proxy=proxy,
30 json=_create_payload(message, **kwargs)
30 json=_create_payload(format_prompt(messages))
31 31 ) as response:
32 32 response.raise_for_status()
33 33 async for stream in response.content.iter_any():
@@ -35,16 +35,16 @@ class Cromicle(AsyncGeneratorProvider):
35 35 yield stream.decode()
36 36
37 37
38 def _create_header():
38 def _create_header() -> Dict[str, str]:
39 39 return {
40 40 'accept': '*/*',
41 41 'content-type': 'application/json',
42 42 }
43 43
44 44
45 def _create_payload(message: str):
45 def _create_payload(message: str) -> Dict[str, str]:
46 46 return {
47 'message' : message,
48 'token' : 'abc',
49 'hash' : sha256('abc'.encode() + message.encode()).hexdigest()
50 }
47 'message': message,
48 'token': 'abc',
49 'hash': sha256('abc'.encode() + message.encode()).hexdigest()
50 }
Modified g4f/Provider/GptForLove.py +4 -1
@@ -50,7 +50,10 @@ class GptForLove(AsyncGeneratorProvider):
50 50 async with session.post("https://api.gptplus.one/chat-process", json=data) as response:
51 51 response.raise_for_status()
52 52 async for line in response.content:
53 line = json.loads(line)
53 try:
54 line = json.loads(line)
55 except:
56 raise RuntimeError(f"Broken line: {line}")
54 57 if "detail" in line:
55 58 content = line["detail"]["choices"][0]["delta"].get("content")
56 59 if content:
Modified g4f/Provider/Yqcloud.py +3 -0
@@ -26,6 +26,9 @@ class Yqcloud(AsyncGeneratorProvider):
26 26 response.raise_for_status()
27 27 async for stream in response.content.iter_any():
28 28 if stream:
29 stream = stream.decode()
30 if "sorry, 您的ip已由于触发防滥用检测而被封禁" in stream:
31 raise RuntimeError("IP address is blocked by abuse detection.")
29 32 yield stream.decode()
30 33
31 34
Modified g4f/Provider/__init__.py +2 -0
@@ -15,6 +15,7 @@ from .ChatgptAi import ChatgptAi
15 15 from .ChatgptDemo import ChatgptDemo
16 16 from .ChatgptDuo import ChatgptDuo
17 17 from .ChatgptX import ChatgptX
18 from .Cromicle import Cromicle
18 19 from .DeepAi import DeepAi
19 20 from .FreeGpt import FreeGpt
20 21 from .GPTalk import GPTalk
@@ -62,6 +63,7 @@ __all__ = [
62 63 'ChatgptDuo',
63 64 'ChatgptLogin',
64 65 'ChatgptX',
66 'Cromicle',
65 67 'CodeLinkAva',
66 68 'DeepAi',
67 69 'DfeHub',
Modified g4f/models.py +4 -1
@@ -19,6 +19,8 @@ from .Provider import (
19 19 Vercel,
20 20 DeepAi,
21 21 Aichat,
22 GPTalk,
23 GptGod,
22 24 AiAsk,
23 25 GptGo,
24 26 Ylokh,
@@ -53,7 +55,8 @@ gpt_35_long = Model(
53 55 base_provider = 'openai',
54 56 best_provider = RetryProvider([
55 57 AiAsk, Aibn, Aichat, ChatForAi, ChatgptAi, ChatgptDemo, ChatgptDuo,
56 FreeGpt, GptGo, Liaobots, Myshell, Vitalentum, Ylokh, You, Yqcloud
58 FreeGpt, GptGo, Liaobots, Myshell, Vitalentum, Ylokh, You, Yqcloud,
59 GPTalk, GptGod
57 60 ])
58 61 )
59 62