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

XFEstudio/gpt4free

New provider added (g4f/Provider/GizAI.py)

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

代码差异

1 个文件 +151 -0
Added g4f/Provider/GizAI.py +151 -0
@@ -0,0 +1,151 @@
1 from __future__ import annotations
2
3 import json
4 from aiohttp import ClientSession
5
6 from ..typing import AsyncResult, Messages
7 from ..image import ImageResponse
8 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
9 from .helper import format_prompt
10
11 class GizAI(AsyncGeneratorProvider, ProviderModelMixin):
12 url = "https://app.giz.ai/assistant/"
13 api_endpoint = "https://app.giz.ai/api/data/users/inferenceServer.infer"
14 working = True
15
16 supports_system_message = True
17 supports_message_history = True
18
19 # Chat models
20 default_model = 'chat-gemini-flash'
21 chat_models = [
22 default_model,
23 'chat-gemini-pro',
24 'chat-gpt4m',
25 'chat-gpt4',
26 'claude-sonnet',
27 'claude-haiku',
28 'llama-3-70b',
29 'llama-3-8b',
30 'mistral-large',
31 'chat-o1-mini'
32 ]
33
34 # Image models
35 image_models = [
36 'flux1',
37 'sdxl',
38 'sd',
39 'sd35',
40 ]
41
42 models = [*chat_models, *image_models]
43
44 model_aliases = {
45 # Chat model aliases
46 "gemini-flash": "chat-gemini-flash",
47 "gemini-pro": "chat-gemini-pro",
48 "gpt-4o-mini": "chat-gpt4m",
49 "gpt-4o": "chat-gpt4",
50 "claude-3.5-sonnet": "claude-sonnet",
51 "claude-3-haiku": "claude-haiku",
52 "llama-3.1-70b": "llama-3-70b",
53 "llama-3.1-8b": "llama-3-8b",
54 "o1-mini": "chat-o1-mini",
55 # Image model aliases
56 "sd-1.5": "sd",
57 "sd-3.5": "sd35",
58 "flux-schnell": "flux1",
59 }
60
61 @classmethod
62 def get_model(cls, model: str) -> str:
63 if model in cls.models:
64 return model
65 elif model in cls.model_aliases:
66 return cls.model_aliases[model]
67 else:
68 return cls.default_model
69
70 @classmethod
71 def is_image_model(cls, model: str) -> bool:
72 return model in cls.image_models
73
74 @classmethod
75 async def create_async_generator(
76 cls,
77 model: str,
78 messages: Messages,
79 proxy: str = None,
80 **kwargs
81 ) -> AsyncResult:
82 model = cls.get_model(model)
83
84 headers = {
85 'Accept': 'application/json, text/plain, */*',
86 'Accept-Language': 'en-US,en;q=0.9',
87 'Cache-Control': 'no-cache',
88 'Connection': 'keep-alive',
89 'Content-Type': 'application/json',
90 'Origin': 'https://app.giz.ai',
91 'Pragma': 'no-cache',
92 'Sec-Fetch-Dest': 'empty',
93 'Sec-Fetch-Mode': 'cors',
94 'Sec-Fetch-Site': 'same-origin',
95 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
96 'sec-ch-ua': '"Not?A_Brand";v="99", "Chromium";v="130"',
97 'sec-ch-ua-mobile': '?0',
98 'sec-ch-ua-platform': '"Linux"'
99 }
100
101 async with ClientSession() as session:
102 if cls.is_image_model(model):
103 # Image generation
104 prompt = messages[-1]["content"]
105 data = {
106 "model": model,
107 "input": {
108 "width": "1024",
109 "height": "1024",
110 "steps": 4,
111 "output_format": "webp",
112 "batch_size": 1,
113 "mode": "plan",
114 "prompt": prompt
115 }
116 }
117 async with session.post(
118 cls.api_endpoint,
119 headers=headers,
120 data=json.dumps(data),
121 proxy=proxy
122 ) as response:
123 response.raise_for_status()
124 response_data = await response.json()
125 if response_data.get('status') == 'completed' and response_data.get('output'):
126 for url in response_data['output']:
127 yield ImageResponse(images=url, alt="Generated Image")
128 else:
129 # Chat completion
130 data = {
131 "model": model,
132 "input": {
133 "messages": [
134 {
135 "type": "human",
136 "content": format_prompt(messages)
137 }
138 ],
139 "mode": "plan"
140 },
141 "noStream": True
142 }
143 async with session.post(
144 cls.api_endpoint,
145 headers=headers,
146 data=json.dumps(data),
147 proxy=proxy
148 ) as response:
149 response.raise_for_status()
150 result = await response.json()
151 yield result.get('output', '')