From eb0e2c6a93c3f21937457d13220ce2b7fca1f04a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 2 Oct 2023 02:04:22 +0200 Subject: +Curl +Async +Stream Requests Update Model List --- g4f/Provider/Ylokh.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'g4f/Provider/Ylokh.py') 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 -- cgit v1.2.3