From fd2b52823b45d201c8b38183b71ee90a194e61fd Mon Sep 17 00:00:00 2001 From: razrab Date: Tue, 24 Oct 2023 18:30:24 +0300 Subject: Add support for detecting incorrect responses in ChatBase API requests. --- g4f/Provider/ChatBase.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'g4f/Provider') diff --git a/g4f/Provider/ChatBase.py b/g4f/Provider/ChatBase.py index 8f9e2aad..7190e617 100644 --- a/g4f/Provider/ChatBase.py +++ b/g4f/Provider/ChatBase.py @@ -10,6 +10,8 @@ class ChatBase(AsyncGeneratorProvider): url = "https://www.chatbase.co" supports_gpt_35_turbo = True working = True + list_incorrect_responses = ["Hmm, I am not sure. Email support@chatbase.co for more info.", + "I can only provide support and information about Chatbase"] @classmethod async def create_async_generator( @@ -41,7 +43,12 @@ class ChatBase(AsyncGeneratorProvider): async with session.post("https://www.chatbase.co/api/fe/chat", json=data, proxy=proxy) as response: response.raise_for_status() + response_data = "" async for stream in response.content.iter_any(): + response_data += stream.decode() + for incorrect_response in cls.list_incorrect_responses: + if incorrect_response in response_data: + raise RuntimeError("Incorrect response") yield stream.decode() @classmethod -- cgit v1.2.3