Module genai_apis.openai_api
Classes
class OpenAIAPI (client)
-
Abstract base class for text generation APIs.
Expand source code
class OpenAIAPI(TextGenerationAPI): def __init__(self, client): self.client = client async def generate_text(self, model, prompt, system_instruction="", **kwargs): messages = [ {"role": "system", "content": system_instruction}, {"role": "user", "content": prompt}, ] response = await self.client.chat.completions.create( model=model, messages=messages, **kwargs ) if "stream" in kwargs and kwargs["stream"] is True: return _get_stream_outputs(response) else: return response.choices[0].message.content
Ancestors
Inherited members