From 7294abc890c377d75c6c8c932620c2e2c8b3f0f9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 28 Aug 2023 01:43:45 +0200 Subject: Add async support for H2o Add format_prompt helper Fix create_completion in AsyncGeneratorProvider Move get_cookies from constructor to function Add ow HuggingChat implement Remove need auth form Liabots Add staic cache for access_token in OpenaiChat Add OpenAssistant provider Support stream and async in You Support async and add userId in Yqcloud Add log_time module --- g4f/Provider/Yqcloud.py | 52 ++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'g4f/Provider/Yqcloud.py') diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py index 44173525..7c1d06ba 100644 --- a/g4f/Provider/Yqcloud.py +++ b/g4f/Provider/Yqcloud.py @@ -1,29 +1,27 @@ -import requests +from aiohttp import ClientSession -from ..typing import Any, CreateResult -from .base_provider import BaseProvider +from .base_provider import AsyncProvider, format_prompt -class Yqcloud(BaseProvider): - url = "https://chat9.yqcloud.top/" - working = True - supports_gpt_35_turbo = True +class Yqcloud(AsyncProvider): + url = "https://chat9.yqcloud.top/" + working = True + supports_gpt_35_turbo = True @staticmethod - def create_completion( + async def create_async( model: str, messages: list[dict[str, str]], - stream: bool, **kwargs: Any) -> CreateResult: - - headers = _create_header() - payload = _create_payload(messages) - - response = requests.post("https://api.aichatos.cloud/api/generateStream", - headers=headers, json=payload) - - response.raise_for_status() - response.encoding = 'utf-8' - yield response.text + proxy: str = None, + **kwargs, + ) -> str: + async with ClientSession( + headers=_create_header() + ) as session: + payload = _create_payload(messages) + async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response: + response.raise_for_status() + return await response.text() def _create_header(): @@ -35,15 +33,11 @@ def _create_header(): def _create_payload(messages: list[dict[str, str]]): - prompt = "" - for message in messages: - prompt += "%s: %s\n" % (message["role"], message["content"]) - prompt += "assistant:" - return { - "prompt" : prompt, - "network" : True, - "system" : "", + "prompt": format_prompt(messages), + "network": True, + "system": "", "withoutContext": False, - "stream" : False, - } \ No newline at end of file + "stream": False, + "userId": "#/chat/1693025544336" + } -- cgit v1.2.3