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

XFEstudio/gpt4free

Added Marsyoo provider with support for the gpt-4o model. Updating models.py

15fdd2cb
kqlio67 <166700875+kqlio67@users.noreply.github.com>
提交于

代码差异

3 个文件 +67 -1
Added g4f/Provider/Marsyoo.py +64 -0
@@ -0,0 +1,64 @@
1 from __future__ import annotations
2
3 import json
4 from aiohttp import ClientSession, ClientResponseError
5
6 from ..typing import AsyncResult, Messages
7 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
8 from .helper import format_prompt
9
10
11 class Marsyoo(AsyncGeneratorProvider, ProviderModelMixin):
12 url = "https://aiagent.marsyoo.com"
13 api_endpoint = "/api/chat-messages"
14 working = True
15 supports_gpt_4 = True
16 default_model = 'gpt-4o'
17
18 @classmethod
19 async def create_async_generator(
20 cls,
21 model: str,
22 messages: Messages,
23 proxy: str = None,
24 **kwargs
25 ) -> AsyncResult:
26 headers = {
27 "Accept": "*/*",
28 "Accept-Language": "en-US,en;q=0.9",
29 "Connection": "keep-alive",
30 "DNT": "1",
31 "Origin": cls.url,
32 "Referer": f"{cls.url}/chat",
33 "Sec-Fetch-Dest": "empty",
34 "Sec-Fetch-Mode": "cors",
35 "Sec-Fetch-Site": "same-origin",
36 "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
37 "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0MWNkOTE3MS1mNTg1LTRjMTktOTY0Ni01NzgxMTBjYWViNTciLCJzdWIiOiJXZWIgQVBJIFBhc3Nwb3J0IiwiYXBwX2lkIjoiNDFjZDkxNzEtZjU4NS00YzE5LTk2NDYtNTc4MTEwY2FlYjU3IiwiYXBwX2NvZGUiOiJMakhzdWJqNjhMTXZCT0JyIiwiZW5kX3VzZXJfaWQiOiI4YjE5YjY2Mi05M2E1LTRhYTktOGNjNS03MDhmNWE0YmQxNjEifQ.pOzdQ4wTrQjjRlEv1XY9TZitkW5KW1K-wbcUJAoBJ5I",
38 "content-type": "application/json",
39 "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
40 "sec-ch-ua-mobile": "?0",
41 "sec-ch-ua-platform": "Linux",
42 }
43 async with ClientSession(headers=headers) as session:
44 prompt = format_prompt(messages)
45 data = {
46 "response_mode": "streaming",
47 "query": prompt,
48 "inputs": {},
49 }
50 try:
51 async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response:
52 response.raise_for_status()
53 async for line in response.content:
54 if line:
55 try:
56 json_data = json.loads(line.decode('utf-8').strip().lstrip('data: '))
57 if json_data['event'] == 'message':
58 yield json_data['answer']
59 elif json_data['event'] == 'message_end':
60 return
61 except json.JSONDecodeError:
62 continue
63 except ClientResponseError as e:
64 yield f"Error: HTTP {e.status}: {e.message}"
Modified g4f/Provider/__init__.py +1 -0
@@ -37,6 +37,7 @@ from .Koala import Koala
37 37 from .Liaobots import Liaobots
38 38 from .Llama import Llama
39 39 from .Local import Local
40 from .Marsyoo import Marsyoo
40 41 from .MetaAI import MetaAI
41 42 from .MetaAIAccount import MetaAIAccount
42 43 from .Ollama import Ollama
Modified g4f/models.py +2 -1
@@ -25,6 +25,7 @@ from .Provider import (
25 25 HuggingFace,
26 26 Koala,
27 27 Liaobots,
28 Marsyoo,
28 29 MetaAI,
29 30 OpenaiChat,
30 31 PerplexityLabs,
@@ -169,7 +170,7 @@ gpt_4o = Model(
169 170 name = 'gpt-4o',
170 171 base_provider = 'openai',
171 172 best_provider = IterListProvider([
172 You, Liaobots, Chatgpt4o, AI365VIP, OpenaiChat
173 You, Liaobots, Chatgpt4o, AI365VIP, OpenaiChat, Marsyoo
173 174 ])
174 175 )
175 176