gabm.io.llm.openai module

For sending prompts to OpenAI, receiving responses, and managing model lists and cache.

Features: - Send prompts to OpenAI and cache responses for reproducibility. - List available models from the OpenAI API and save as both JSON and TXT for validation and reference. - Validate selected model names against the cached JSON model list. - Unified workflow for model management, matching other LLM modules in the project.

class gabm.io.llm.openai.OpenAIService(logger=None)

Bases: LLMService

Service class for OpenAI LLM integration. Handles prompt sending, response caching, logging, and model listing.

SERVICE_NAME = 'openai'
list_available_models(api_key)

List available OpenAI models and write them to JSON and TXT files. Returns the list.

Args:

api_key (str): OpenAI API key.

Returns:

list: List of model objects.

send(api_key, message, model='gpt-3.5-turbo')

Send a prompt to OpenAI and return the response object. Caches and logs the response for reproducibility.

Args:

api_key (str): OpenAI API key. message (str): Prompt to send. model (str): Model name (default: “gpt-3.5-turbo”).

Returns:

Response object or None on error.

static simple_extract_text(response)