""" 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'. """ # TODO: # * transform given message and chat context into OpenAI format # * make request # * create a new Message for each answer and return them # (writing Messages is done by the calles) 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))