返回提交历史
Added
g4f/Provider/ItalyGPT.py
+45
-0
XFEstudio/gpt4free
Add ItalyGPT provider
688640b7
代码差异
1 个文件
+45
-0
@@ -0,0 +1,45 @@
1
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
2
from ..typing import AsyncResult, Messages
3
from aiohttp import ClientSession
4
5
class ItalyGPT(AsyncGeneratorProvider, ProviderModelMixin):
6
label = "ItalyGPT"
7
url = "https://italygpt.it"
8
working = True
9
supports_system_message = True
10
supports_message_history = True
11
12
default_model = "gpt-4o"
13
models = [default_model]
14
15
@classmethod
16
async def create_async_generator(
17
cls,
18
model: str,
19
messages: Messages,
20
stream: bool = True,
21
proxy: str = None,
22
**kwargs
23
) -> AsyncResult:
24
model = cls.get_model(model)
25
headers = {
26
"content-type": "application/json",
27
"origin": "https://italygpt.it",
28
"referer": "https://italygpt.it/",
29
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
30
}
31
payload = {
32
"messages": messages,
33
"stream": stream,
34
}
35
async with ClientSession() as session:
36
async with session.post(
37
f"{cls.url}/api/chat/",
38
json=payload,
39
headers=headers,
40
proxy=proxy,
41
) as resp:
42
resp.raise_for_status()
43
async for chunk in resp.content:
44
if chunk:
45
yield chunk.decode()