diff options
author | Heiner Lohaus <heiner.lohaus@netformic.com> | 2023-09-05 17:27:24 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner.lohaus@netformic.com> | 2023-09-05 17:27:24 +0200 |
commit | 5ca47b44b2b42abb4f48163c17500b5ee67ab28f (patch) | |
tree | b8fba4bde73d59c05857459eac41b25347d65c8e /g4f/Provider/Acytoo.py | |
parent | ~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff) | |
download | gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.gz gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.bz2 gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.lz gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.xz gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.zst gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/Acytoo.py | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/g4f/Provider/Acytoo.py b/g4f/Provider/Acytoo.py index 48a3a344..d36ca6da 100644 --- a/g4f/Provider/Acytoo.py +++ b/g4f/Provider/Acytoo.py @@ -1,32 +1,37 @@ from __future__ import annotations -import time +from aiohttp import ClientSession -import requests +from ..typing import AsyncGenerator +from .base_provider import AsyncGeneratorProvider -from ..typing import Any, CreateResult -from .base_provider import BaseProvider - -class Acytoo(BaseProvider): - url = 'https://chat.acytoo.com/' +class Acytoo(AsyncGeneratorProvider): + url = 'https://chat.acytoo.com' working = True supports_gpt_35_turbo = True @classmethod - def create_completion( + async def create_async_generator( cls, model: str, messages: list[dict[str, str]], - stream: bool, **kwargs: Any) -> CreateResult: - - response = requests.post(f'{cls.url}api/completions', - headers=_create_header(), json=_create_payload(messages, kwargs.get('temperature', 0.5))) - - response.raise_for_status() - response.encoding = 'utf-8' - - yield response.text + 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() def _create_header(): @@ -36,15 +41,11 @@ def _create_header(): } -def _create_payload(messages: list[dict[str, str]], temperature): - payload_messages = [ - message | {'createdAt': int(time.time()) * 1000} for message in messages - ] - +def _create_payload(messages: list[dict[str, str]], temperature: float = 0.5, **kwargs): return { 'key' : '', 'model' : 'gpt-3.5-turbo', - 'messages' : payload_messages, + 'messages' : messages, 'temperature' : temperature, 'password' : '' }
\ No newline at end of file |