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

XFEstudio/gpt4free

Adding a new provider with support for models

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

代码差异

3 个文件 +101 -2
Added g4f/Provider/Bixin123.py +89 -0
@@ -0,0 +1,89 @@
1 from __future__ import annotations
2
3 from aiohttp import ClientSession
4 import json
5 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
6 from ..typing import AsyncResult, Messages
7 from .helper import format_prompt
8
9 class Bixin123(AsyncGeneratorProvider, ProviderModelMixin):
10 url = "https://chat.bixin123.com"
11 api_endpoint = "https://chat.bixin123.com/api/chatgpt/chat-process"
12 working = True
13 supports_gpt_35_turbo = True
14 supports_gpt_4 = True
15
16 default_model = 'gpt-3.5-turbo-0125'
17 models = ['gpt-3.5-turbo-0125', 'gpt-3.5-turbo-16k-0613', 'gpt-4-turbo', 'qwen-turbo']
18
19 model_aliases = {
20 "gpt-3.5-turbo": "gpt-3.5-turbo-0125",
21 "gpt-3.5-turbo": "gpt-3.5-turbo-16k-0613",
22 }
23
24 @classmethod
25 def get_model(cls, model: str) -> str:
26 if model in cls.models:
27 return model
28 elif model in cls.model_aliases:
29 return cls.model_aliases[model]
30 else:
31 return cls.default_model
32
33 @classmethod
34 async def create_async_generator(
35 cls,
36 model: str,
37 messages: Messages,
38 proxy: str = None,
39 **kwargs
40 ) -> AsyncResult:
41 model = cls.get_model(model)
42
43 headers = {
44 "accept": "application/json, text/plain, */*",
45 "accept-language": "en-US,en;q=0.9",
46 "cache-control": "no-cache",
47 "content-type": "application/json",
48 "fingerprint": "988148794",
49 "origin": cls.url,
50 "pragma": "no-cache",
51 "priority": "u=1, i",
52 "referer": f"{cls.url}/chat",
53 "sec-ch-ua": '"Chromium";v="127", "Not)A;Brand";v="99"',
54 "sec-ch-ua-mobile": "?0",
55 "sec-ch-ua-platform": '"Linux"',
56 "sec-fetch-dest": "empty",
57 "sec-fetch-mode": "cors",
58 "sec-fetch-site": "same-origin",
59 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
60 "x-website-domain": "chat.bixin123.com",
61 }
62
63 async with ClientSession(headers=headers) as session:
64 prompt = format_prompt(messages)
65 data = {
66 "prompt": prompt,
67 "options": {
68 "usingNetwork": False,
69 "file": ""
70 }
71 }
72 async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
73 response.raise_for_status()
74 response_text = await response.text()
75
76 lines = response_text.strip().split("\n")
77 last_json = None
78 for line in reversed(lines):
79 try:
80 last_json = json.loads(line)
81 break
82 except json.JSONDecodeError:
83 pass
84
85 if last_json:
86 text = last_json.get("text", "")
87 yield text
88 else:
89 yield ""
Modified g4f/Provider/__init__.py +1 -0
@@ -16,6 +16,7 @@ from .AiChats import AiChats
16 16 from .Aura import Aura
17 17 from .Bing import Bing
18 18 from .BingCreateImages import BingCreateImages
19 from .Bixin123 import Bixin123
19 20 from .Blackbox import Blackbox
20 21 from .ChatGot import ChatGot
21 22 from .Chatgpt4Online import Chatgpt4Online
Modified g4f/models.py +11 -2
@@ -7,6 +7,7 @@ from .Provider import (
7 7 AiChatOnline,
8 8 Allyfy,
9 9 Bing,
10 Bixin123,
10 11 Blackbox,
11 12 ChatGot,
12 13 Chatgpt4Online,
@@ -81,6 +82,7 @@ default = Model(
81 82 ReplicateHome,
82 83 Upstage,
83 84 Blackbox,
85 Bixin123,
84 86 ])
85 87 )
86 88
@@ -103,7 +105,7 @@ gpt_35_turbo = Model(
103 105 name = 'gpt-3.5-turbo',
104 106 base_provider = 'OpenAI',
105 107 best_provider = IterListProvider([
106 Allyfy, TwitterBio, Nexra,
108 Allyfy, TwitterBio, Nexra, Bixin123,
107 109 ])
108 110 )
109 111
@@ -128,7 +130,7 @@ gpt_4_turbo = Model(
128 130 name = 'gpt-4-turbo',
129 131 base_provider = 'OpenAI',
130 132 best_provider = IterListProvider([
131 Nexra, Liaobots, Bing
133 Nexra, Bixin123, Liaobots, Bing
132 134 ])
133 135 )
134 136
@@ -332,6 +334,12 @@ qwen_1_5_14b = Model(
332 334 best_provider = IterListProvider([FreeChatgpt])
333 335 )
334 336
337 qwen_turbo = Model(
338 name = 'qwen-turbo',
339 base_provider = 'Qwen',
340 best_provider = IterListProvider([Bixin123])
341 )
342
335 343
336 344 ### Zhipu AI ###
337 345 glm4_9b = Model(
@@ -584,6 +592,7 @@ class ModelUtils:
584 592
585 593 ### Qwen ###
586 594 'qwen-1.5-14b': qwen_1_5_14b,
595 'qwen-turbo': qwen_turbo,
587 596
588 597
589 598 ### Zhipu AI ###