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

XFEstudio/gpt4free

feat(g4f/Provider/ChatifyAI.py): add new AmigoChat text and image models

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

代码差异

1 个文件 +75 -0
Added g4f/Provider/ChatifyAI.py +75 -0
@@ -0,0 +1,75 @@
1 from __future__ import annotations
2
3 from aiohttp import ClientSession
4
5 from ..typing import AsyncResult, Messages
6 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
7 from .helper import format_prompt
8
9
10 class ChatifyAI(AsyncGeneratorProvider, ProviderModelMixin):
11 url = "https://chatify-ai.vercel.app"
12 api_endpoint = "https://chatify-ai.vercel.app/api/chat"
13 working = True
14 supports_stream = False
15 supports_system_message = True
16 supports_message_history = True
17
18 default_model = 'llama-3.1'
19 models = [default_model]
20
21 @classmethod
22 def get_model(cls, model: str) -> str:
23 return cls.default_model
24
25 @classmethod
26 async def create_async_generator(
27 cls,
28 model: str,
29 messages: Messages,
30 proxy: str = None,
31 **kwargs
32 ) -> AsyncResult:
33 model = cls.get_model(model)
34
35 headers = {
36 "accept": "*/*",
37 "accept-language": "en-US,en;q=0.9",
38 "cache-control": "no-cache",
39 "content-type": "application/json",
40 "origin": cls.url,
41 "pragma": "no-cache",
42 "priority": "u=1, i",
43 "referer": f"{cls.url}/",
44 "sec-ch-ua": '"Chromium";v="129", "Not=A?Brand";v="8"',
45 "sec-ch-ua-mobile": "?0",
46 "sec-ch-ua-platform": '"Linux"',
47 "sec-fetch-dest": "empty",
48 "sec-fetch-mode": "cors",
49 "sec-fetch-site": "same-origin",
50 "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
51 }
52 async with ClientSession(headers=headers) as session:
53 data = {
54 "messages": [{"role": "user", "content": format_prompt(messages)}]
55 }
56 async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
57 response.raise_for_status()
58 response_text = await response.text()
59
60 # Фільтруємо та форматуємо відповідь
61 filtered_response = cls.filter_response(response_text)
62 yield filtered_response
63
64 @staticmethod
65 def filter_response(response_text: str) -> str:
66 # Розділяємо рядок на частини
67 parts = response_text.split('"')
68
69 # Вибираємо лише текстові частини (кожна друга частина)
70 text_parts = parts[1::2]
71
72 # Об'єднуємо текстові частини
73 clean_text = ''.join(text_parts)
74
75 return clean_text