From 82a3a039290cded2cc1282647f78ebd91d475b46 Mon Sep 17 00:00:00 2001 From: Rory Durrant Date: Thu, 4 May 2023 17:14:18 +0100 Subject: =?UTF-8?q?=F0=9F=94=A8=20update(theb/=5F=5Finit=5F=5F.py):=20add?= =?UTF-8?q?=20get=5Fresponse=20method=20to=20Completion=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The get_response method was added to the Completion class to allow for easier retrieval of the response from the GPT-3 API. This method takes in a prompt and an optional proxy and returns the response as a string. The method uses the create method to generate a generator object and then iterates over it to append each message to a list. Finally, the list is joined into a single string and returned. This allows for non stream usage of theb. --- gpt4free/theb/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gpt4free/theb/__init__.py b/gpt4free/theb/__init__.py index b162811e..4513ea6e 100644 --- a/gpt4free/theb/__init__.py +++ b/gpt4free/theb/__init__.py @@ -46,7 +46,6 @@ class Completion: Completion.stream_completed = True @staticmethod - def create(prompt: str, proxy: Optional[str] = None) -> Generator[str, None, None]: Completion.stream_completed = False @@ -66,3 +65,10 @@ class Completion: @staticmethod def handle_stream_response(response): Completion.message_queue.put(response.decode()) + + @staticmethod + def get_response(prompt: str, proxy: Optional[str] = None) -> str: + response_list = [] + for message in Completion.create(prompt, proxy): + response_list.append(message) + return ''.join(response_list) -- cgit v1.2.3