diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-07 19:45:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-07 19:45:04 +0200 |
commit | 7ca1a59d95b52f94f674e8f981eab910b2f03518 (patch) | |
tree | ca506c3c152f3906a5b727a4cc6ebba1fd59d335 /g4f/Provider/DeepAi.py | |
parent | ~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff) | |
parent | Fix imports in Bing (diff) | |
download | gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.gz gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.bz2 gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.lz gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.xz gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.zst gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.zip |
Diffstat (limited to 'g4f/Provider/DeepAi.py')
-rw-r--r-- | g4f/Provider/DeepAi.py | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/g4f/Provider/DeepAi.py b/g4f/Provider/DeepAi.py index feba6b41..88225f1f 100644 --- a/g4f/Provider/DeepAi.py +++ b/g4f/Provider/DeepAi.py @@ -1,25 +1,25 @@ from __future__ import annotations import json - import js2py -import requests +from aiohttp import ClientSession -from ..typing import Any, CreateResult -from .base_provider import BaseProvider +from ..typing import AsyncGenerator +from .base_provider import AsyncGeneratorProvider -class DeepAi(BaseProvider): +class DeepAi(AsyncGeneratorProvider): url: str = "https://deepai.org" working = True - supports_stream = True supports_gpt_35_turbo = True @staticmethod - def create_completion( + async def create_async_generator( model: str, messages: list[dict[str, str]], - stream: bool, **kwargs: Any) -> CreateResult: + proxy: str = None, + **kwargs + ) -> AsyncGenerator: token_js = """ var agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36' @@ -53,10 +53,11 @@ f = function () { "api-key": api_key, "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36", } - - response = requests.post("https://api.deepai.org/make_me_a_pizza", - headers=headers, data=payload, stream=True) - - for chunk in response.iter_content(chunk_size=None): - response.raise_for_status() - yield chunk.decode() + async with ClientSession( + headers=headers + ) as session: + async with session.post("https://api.deepai.org/make_me_a_pizza", proxy=proxy, data=payload) as response: + response.raise_for_status() + async for stream in response.content.iter_any(): + if stream: + yield stream.decode()
\ No newline at end of file |