XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
UTF-8
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
from ..typing import AsyncResult, Messages
from ..requests import DEFAULT_HEADERS
from aiohttp import ClientSession

class ItalyGPT(AsyncGeneratorProvider, ProviderModelMixin):
    label = "ItalyGPT"
    url = "https://italygpt.it"
    working = True
    supports_system_message = True
    supports_message_history = True

    default_model = "gpt-4o"
    models = [default_model]

    @classmethod
    async def create_async_generator(
        cls,
        model: str,
        messages: Messages,
        stream: bool = True,
        proxy: str = None,
        **kwargs
    ) -> AsyncResult:
        model = cls.get_model(model)
        headers = {
            **DEFAULT_HEADERS,
            "content-type": "application/json",
            "origin": "https://italygpt.it",
            "referer": "https://italygpt.it/",
        }
        payload = {
            "messages": messages,
            "stream": stream,
        }
        async with ClientSession() as session:
            async with session.post(
                f"{cls.url}/api/chat",
                json=payload,
                headers=headers,
                proxy=proxy,
            ) as resp:
                resp.raise_for_status()
                async for chunk in resp.content.iter_any():
                    if chunk:
                        yield chunk.decode()