From 3b50288c937262d9a9c20e37a5fd01a3b2025ec3 Mon Sep 17 00:00:00 2001 From: juk0de Date: Fri, 1 Sep 2023 10:18:09 +0200 Subject: [PATCH] added new module 'openai.py' --- chatmastermind/ais/openai.py | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 chatmastermind/ais/openai.py diff --git a/chatmastermind/ais/openai.py b/chatmastermind/ais/openai.py new file mode 100644 index 0000000..9681761 --- /dev/null +++ b/chatmastermind/ais/openai.py @@ -0,0 +1,43 @@ +""" +Implements the OpenAI client. +""" +import openai +from ..message import Message +from ..chat import Chat +from ..ai import AI, AIResponse + + +class OpenAI(AI): + """ + The OpenAI AI client. + """ + + def request(self, + question: Message, + context: Chat, + num_answers: int = 1) -> AIResponse: + """ + Make an AI request, asking the given question with the given + context (i. e. chat history). The nr. of requested answers + corresponds to the nr. of messages in the 'AIResponse'. + """ + raise NotImplementedError + + def models(self) -> list[str]: + """ + Return all models supported by this AI. + """ + raise NotImplementedError + + def print_models(self) -> None: + """ + Print all models supported by the current AI. + """ + not_ready = [] + for engine in sorted(openai.Engine.list()['data'], key=lambda x: x['id']): + if engine['ready']: + print(engine['id']) + else: + not_ready.append(engine['id']) + if len(not_ready) > 0: + print('\nNot ready: ' + ', '.join(not_ready))