diff --git a/chatmastermind/ais/openai.py b/chatmastermind/ais/openai.py new file mode 100644 index 0000000..67c520e --- /dev/null +++ b/chatmastermind/ais/openai.py @@ -0,0 +1,43 @@ +""" +Implements the OpenAI client classes and functions. +""" +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))