🔨 update(theb/__init__.py): add get_response method to Completion class
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.
このコミットが含まれているのは:
コミット
82a3a03929
|
@ -46,7 +46,6 @@ class Completion:
|
||||||
Completion.stream_completed = True
|
Completion.stream_completed = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
||||||
def create(prompt: str, proxy: Optional[str] = None) -> Generator[str, None, None]:
|
def create(prompt: str, proxy: Optional[str] = None) -> Generator[str, None, None]:
|
||||||
Completion.stream_completed = False
|
Completion.stream_completed = False
|
||||||
|
|
||||||
|
@ -66,3 +65,10 @@ class Completion:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def handle_stream_response(response):
|
def handle_stream_response(response):
|
||||||
Completion.message_queue.put(response.decode())
|
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)
|
||||||
|
|
読み込み中…
新しいイシューから参照