From 74c399d675676938f31faf18174a98ed7a1709da Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 23 Apr 2024 17:34:42 +0200 Subject: Add conversation title change in gui Fix bug with multiple requests a .har in OpenaiChat --- g4f/Provider/Bing.py | 2 +- g4f/Provider/BingCreateImages.py | 14 ++++++++------ g4f/Provider/HuggingChat.py | 3 +++ g4f/Provider/openai/har_file.py | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) (limited to 'g4f/Provider') diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py index bfd74f8c..a9eb78e6 100644 --- a/g4f/Provider/Bing.py +++ b/g4f/Provider/Bing.py @@ -484,7 +484,7 @@ async def stream_generate( elif message.get('contentType') == "IMAGE": prompt = message.get('text') try: - image_client = BingCreateImages(cookies, proxy) + image_client = BingCreateImages(cookies, proxy, api_key) image_response = await image_client.create_async(prompt) except Exception as e: if debug.logging: diff --git a/g4f/Provider/BingCreateImages.py b/g4f/Provider/BingCreateImages.py index 69bf1e92..9e5146cc 100644 --- a/g4f/Provider/BingCreateImages.py +++ b/g4f/Provider/BingCreateImages.py @@ -19,9 +19,13 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin): needs_auth = True image_models = ["dall-e"] - def __init__(self, cookies: Cookies = None, proxy: str = None) -> None: - self.cookies: Cookies = cookies - self.proxy: str = proxy + def __init__(self, cookies: Cookies = None, proxy: str = None, api_key: str = None) -> None: + if api_key is not None: + if cookies is None: + cookies = {} + cookies["_U"] = api_key + self.cookies = cookies + self.proxy = proxy @classmethod async def create_async_generator( @@ -33,9 +37,7 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin): proxy: str = None, **kwargs ) -> AsyncResult: - if api_key is not None: - cookies = {"_U": api_key} - session = BingCreateImages(cookies, proxy) + session = BingCreateImages(cookies, proxy, api_key) yield await session.create_async(messages[-1]["content"]) def create(self, prompt: str) -> Iterator[Union[ImageResponse, str]]: diff --git a/g4f/Provider/HuggingChat.py b/g4f/Provider/HuggingChat.py index 527f0a56..65273345 100644 --- a/g4f/Provider/HuggingChat.py +++ b/g4f/Provider/HuggingChat.py @@ -24,6 +24,9 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin): 'mistralai/Mistral-7B-Instruct-v0.2', 'meta-llama/Meta-Llama-3-70B-Instruct' ] + model_aliases = { + "mistralai/Mistral-7B-Instruct-v0.1": "mistralai/Mistral-7B-Instruct-v0.2" + } @classmethod def get_models(cls): diff --git a/g4f/Provider/openai/har_file.py b/g4f/Provider/openai/har_file.py index da25b637..6a34c97a 100644 --- a/g4f/Provider/openai/har_file.py +++ b/g4f/Provider/openai/har_file.py @@ -30,6 +30,7 @@ sessionUrl = "https://chat.openai.com/api/auth/session" chatArk: arkReq = None accessToken: str = None cookies: dict = None +headers: dict = None def readHAR(): dirPath = "./" @@ -130,7 +131,7 @@ def getN() -> str: return base64.b64encode(timestamp.encode()).decode() async def getArkoseAndAccessToken(proxy: str) -> tuple[str, str, dict, dict]: - global chatArk, accessToken, cookies + global chatArk, accessToken, cookies, headers if chatArk is None or accessToken is None: chatArk, accessToken, cookies, headers = readHAR() if chatArk is None: -- cgit v1.2.3