summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/DeepAi.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner.lohaus@netformic.com>2023-09-05 17:27:24 +0200
committerHeiner Lohaus <heiner.lohaus@netformic.com>2023-09-05 17:27:24 +0200
commit5ca47b44b2b42abb4f48163c17500b5ee67ab28f (patch)
treeb8fba4bde73d59c05857459eac41b25347d65c8e /g4f/Provider/DeepAi.py
parent~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff)
downloadgpt4free-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/DeepAi.py31
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