From 831c722a9fd9907bd9066c1f3c3feb7704f93b09 Mon Sep 17 00:00:00 2001 From: kqlio67 <> Date: Sun, 12 Jan 2025 13:25:41 +0200 Subject: Update providers, documentation improvements and bug fixes --- g4f/Provider/ChatGptEs.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'g4f/Provider/ChatGptEs.py') diff --git a/g4f/Provider/ChatGptEs.py b/g4f/Provider/ChatGptEs.py index d42baffd..9222131e 100644 --- a/g4f/Provider/ChatGptEs.py +++ b/g4f/Provider/ChatGptEs.py @@ -1,11 +1,13 @@ from __future__ import annotations -from aiohttp import ClientSession import os -import json import re +import json + +from aiohttp import ClientSession from ..typing import AsyncResult, Messages +from ..requests.raise_for_status import raise_for_status from .base_provider import AsyncGeneratorProvider, ProviderModelMixin from .helper import format_prompt @@ -19,16 +21,15 @@ class ChatGptEs(AsyncGeneratorProvider, ProviderModelMixin): supports_message_history = True default_model = 'gpt-4o' - models = ['gpt-4', 'gpt-4o', 'gpt-4o-mini'] + models = ['gpt-4', default_model, 'gpt-4o-mini'] + + SYSTEM_PROMPT = "Your default language is English. Always respond in English unless the user's message is in a different language. If the user's message is not in English, respond in the language of the user's message. Maintain this language behavior throughout the conversation unless explicitly instructed otherwise. User input:" @classmethod def get_model(cls, model: str) -> str: if model in cls.models: return model - elif model in cls.model_aliases: - return cls.model_aliases[model] - else: - return cls.default_model + return cls.model_aliases[model] @classmethod async def create_async_generator( @@ -52,29 +53,22 @@ class ChatGptEs(AsyncGeneratorProvider, ProviderModelMixin): initial_response = await session.get(cls.url) nonce_ = re.findall(r'data-nonce="(.+?)"', await initial_response.text())[0] post_id = re.findall(r'data-post-id="(.+?)"', await initial_response.text())[0] - - formatted_prompt = format_prompt(messages) - - conversation_history = [] - - for message in messages[:-1]: - if message['role'] == "user": - conversation_history.append(f"Human: {message['content']}") - else: - conversation_history.append(f"AI: {message['content']}") + + prompt = f"{cls.SYSTEM_PROMPT} {format_prompt(messages)}" payload = { - 'wpaicg_user_agree': '1', + 'check_51710191': '1', '_wpnonce': nonce_, 'post_id': post_id, 'url': cls.url, 'action': 'wpaicg_chat_shortcode_message', - 'message': formatted_prompt, + 'message': prompt, 'bot_id': '0', 'chatbot_identity': 'shortcode', 'wpaicg_chat_client_id': os.urandom(5).hex(), - 'wpaicg_chat_history': json.dumps(conversation_history) + 'wpaicg_chat_history': None } + print(payload['message']) async with session.post(cls.api_endpoint, headers=headers, data=payload) as response: response.raise_for_status() -- cgit v1.2.3