gpt4free/g4f/Provider/Acytoo.py

51 lines
1.3 KiB
Python
Raw Normal View History

from __future__ import annotations
from aiohttp import ClientSession
2023-07-28 06:07:17 -04:00
from ..typing import AsyncGenerator
from .base_provider import AsyncGeneratorProvider
2023-07-28 06:07:17 -04:00
class Acytoo(AsyncGeneratorProvider):
url = 'https://chat.acytoo.com'
2023-08-27 11:37:44 -04:00
working = True
2023-07-28 06:07:17 -04:00
supports_gpt_35_turbo = True
2023-08-24 15:32:22 -04:00
@classmethod
async def create_async_generator(
2023-08-24 15:32:22 -04:00
cls,
2023-07-28 06:07:17 -04:00
model: str,
messages: list[dict[str, str]],
proxy: str = None,
**kwargs
) -> AsyncGenerator:
async with ClientSession(
headers=_create_header()
) as session:
async with session.post(
cls.url + '/api/completions',
proxy=proxy,
json=_create_payload(messages, **kwargs)
) as response:
response.raise_for_status()
async for stream in response.content.iter_any():
if stream:
yield stream.decode()
2023-07-28 06:07:17 -04:00
def _create_header():
return {
2023-08-27 11:37:44 -04:00
'accept': '*/*',
'content-type': 'application/json',
2023-07-28 06:07:17 -04:00
}
def _create_payload(messages: list[dict[str, str]], temperature: float = 0.5, **kwargs):
2023-07-28 06:07:17 -04:00
return {
2023-08-27 11:37:44 -04:00
'key' : '',
'model' : 'gpt-3.5-turbo',
'messages' : messages,
2023-08-27 11:37:44 -04:00
'temperature' : temperature,
'password' : ''
}