diff options
author | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-02 02:04:22 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-02 02:04:22 +0200 |
commit | eb0e2c6a93c3f21937457d13220ce2b7fca1f04a (patch) | |
tree | e0139cd399052db29326d502f9d738d1943c7bce /g4f/Provider/Ylokh.py | |
parent | Change event loop policy on windows (diff) | |
download | gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.tar gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.tar.gz gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.tar.bz2 gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.tar.lz gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.tar.xz gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.tar.zst gpt4free-eb0e2c6a93c3f21937457d13220ce2b7fca1f04a.zip |
Diffstat (limited to 'g4f/Provider/Ylokh.py')
-rw-r--r-- | g4f/Provider/Ylokh.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/g4f/Provider/Ylokh.py b/g4f/Provider/Ylokh.py index 2187eb78..3c8b32dd 100644 --- a/g4f/Provider/Ylokh.py +++ b/g4f/Provider/Ylokh.py @@ -2,7 +2,7 @@ from __future__ import annotations import json -from ..requests import AsyncSession +from ..requests import StreamSession from .base_provider import AsyncGeneratorProvider from ..typing import AsyncGenerator @@ -37,18 +37,19 @@ class Ylokh(AsyncGeneratorProvider): "stream": stream, **kwargs } - async with AsyncSession( - 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 |