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

XFEstudio/gpt4free

Adding a new provider Binjie

dc8562f6
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

3 个文件 +70 -2
Added g4f/Provider/Binjie.py +65 -0
@@ -0,0 +1,65 @@
1 from __future__ import annotations
2
3 import random
4 from ..requests import StreamSession
5
6 from ..typing import AsyncResult, Messages
7 from .base_provider import AsyncGeneratorProvider, format_prompt
8
9
10 class Binjie(AsyncGeneratorProvider):
11 url = "https://chat18.aichatos8.com"
12 working = True
13 supports_gpt_4 = True
14 supports_stream = True
15 supports_system_message = True
16 supports_message_history = True
17
18 @staticmethod
19 async def create_async_generator(
20 model: str,
21 messages: Messages,
22 proxy: str = None,
23 timeout: int = 120,
24 **kwargs,
25 ) -> AsyncResult:
26 async with StreamSession(
27 headers=_create_header(), proxies={"https": proxy}, timeout=timeout
28 ) as session:
29 payload = _create_payload(messages, **kwargs)
30 async with session.post("https://api.binjie.fun/api/generateStream", json=payload) as response:
31 response.raise_for_status()
32 async for chunk in response.iter_content():
33 if chunk:
34 chunk = chunk.decode()
35 if "sorry, 您的ip已由于触发防滥用检测而被封禁" in chunk:
36 raise RuntimeError("IP address is blocked by abuse detection.")
37 yield chunk
38
39
40 def _create_header():
41 return {
42 "accept" : "application/json, text/plain, */*",
43 "content-type" : "application/json",
44 "origin" : "https://chat18.aichatos8.com",
45 "referer" : "https://chat18.aichatos8.com/"
46 }
47
48
49 def _create_payload(
50 messages: Messages,
51 system_message: str = "",
52 user_id: int = None,
53 **kwargs
54 ):
55 if not user_id:
56 user_id = random.randint(1690000544336, 2093025544336)
57 return {
58 "prompt": format_prompt(messages),
59 "network": True,
60 "system": system_message,
61 "withoutContext": False,
62 "stream": True,
63 "userId": f"#/chat/{user_id}"
64 }
65
Modified g4f/Provider/__init__.py +2 -1
@@ -16,13 +16,14 @@ from .AiChats import AiChats
16 16 from .Aura import Aura
17 17 from .Bing import Bing
18 18 from .BingCreateImages import BingCreateImages
19 from .Binjie import Binjie
19 20 from .Bixin123 import Bixin123
20 21 from .Blackbox import Blackbox
21 22 from .ChatGot import ChatGot
22 23 from .Chatgpt4Online import Chatgpt4Online
23 24 from .Chatgpt4o import Chatgpt4o
24 25 from .ChatgptFree import ChatgptFree
25 from .CodeNews import CodeNews
26 from .CodeNews import CodeNews
26 27 from .DDG import DDG
27 28 from .DeepInfra import DeepInfra
28 29 from .DeepInfraImage import DeepInfraImage
Modified g4f/models.py +3 -1
@@ -7,6 +7,7 @@ from .Provider import (
7 7 AiChatOnline,
8 8 Allyfy,
9 9 Bing,
10 Binjie,
10 11 Bixin123,
11 12 Blackbox,
12 13 ChatGot,
@@ -84,6 +85,7 @@ default = Model(
84 85 Upstage,
85 86 Blackbox,
86 87 Bixin123,
88 Binjie,
87 89 ])
88 90 )
89 91
@@ -139,7 +141,7 @@ gpt_4 = Model(
139 141 name = 'gpt-4',
140 142 base_provider = 'OpenAI',
141 143 best_provider = IterListProvider([
142 Chatgpt4Online, Nexra, Bing,
144 Chatgpt4Online, Nexra, Binjie, Bing,
143 145 gpt_4_turbo.best_provider, gpt_4o.best_provider, gpt_4o_mini.best_provider
144 146 ])
145 147 )