summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Ylokh.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-02 12:20:18 +0200
committerGitHub <noreply@github.com>2023-10-02 12:20:18 +0200
commitc0632c27411b5cc8a643e0bffd71537f4224473c (patch)
treed8a07c23a8172e26004560e4d6b08982f637e71c /g4f/Provider/Ylokh.py
parent~ | v-0.1.4.2 `pip install -U g4f` (diff)
parentFix: There is no current event loop in thread (diff)
downloadgpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.tar
gpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.tar.gz
gpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.tar.bz2
gpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.tar.lz
gpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.tar.xz
gpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.tar.zst
gpt4free-c0632c27411b5cc8a643e0bffd71537f4224473c.zip
Diffstat (limited to 'g4f/Provider/Ylokh.py')
-rw-r--r--g4f/Provider/Ylokh.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/g4f/Provider/Ylokh.py b/g4f/Provider/Ylokh.py
index c7b92089..3c8b32dd 100644
--- a/g4f/Provider/Ylokh.py
+++ b/g4f/Provider/Ylokh.py
@@ -1,8 +1,8 @@
from __future__ import annotations
import json
-from aiohttp import ClientSession
+from ..requests import StreamSession
from .base_provider import AsyncGeneratorProvider
from ..typing import AsyncGenerator
@@ -23,14 +23,8 @@ class Ylokh(AsyncGeneratorProvider):
) -> AsyncGenerator:
model = model if model else "gpt-3.5-turbo"
headers = {
- "User-Agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
- "Accept" : "*/*",
- "Accept-language" : "de,en-US;q=0.7,en;q=0.3",
"Origin" : cls.url,
"Referer" : cls.url + "/",
- "Sec-Fetch-Dest" : "empty",
- "Sec-Fetch-Mode" : "cors",
- "Sec-Fetch-Site" : "same-origin",
}
data = {
"messages": messages,
@@ -43,18 +37,19 @@ class Ylokh(AsyncGeneratorProvider):
"stream": stream,
**kwargs
}
- async with ClientSession(
- headers=headers
+ async with StreamSession(
+ headers=headers,
+ proxies={"https": proxy}
) as session:
- async with session.post("https://chatapi.ylokh.xyz/v1/chat/completions", json=data, proxy=proxy) as response:
+ async with session.post("https://chatapi.ylokh.xyz/v1/chat/completions", json=data) as response:
response.raise_for_status()
if stream:
- async for line in response.content:
+ async for line in response.iter_lines():
line = line.decode()
if line.startswith("data: "):
if line.startswith("data: [DONE]"):
break
- line = json.loads(line[6:-1])
+ line = json.loads(line[6:])
content = line["choices"][0]["delta"].get("content")
if content:
yield content