Large Language Models

class oscopilot.utils.llms.OpenAI[source]

Bases: object

A class for interacting with the OpenAI API, allowing for chat completion requests.

This class simplifies the process of sending requests to OpenAI’s chat model by providing a convenient interface for the chat completion API. It handles setting up the API key and organization for the session and provides a method to send chat messages.

model_name

The name of the model to use for chat completions. Default is set by the global MODEL_NAME.

Type:

str

api_key

The API key used for authentication with the OpenAI API. This should be set through the OPENAI_API_KEY global variable.

Type:

str

organization

The organization ID for OpenAI. Set this through the OPENAI_ORGANIZATION global variable.

Type:

str

chat(messages, temperature=0)[source]

Sends a chat completion request to the OpenAI API using the specified messages and parameters.

Parameters:
  • messages (list of dict) – A list of message dictionaries, where each dictionary should contain keys like ‘role’ and ‘content’ to specify the role (e.g., ‘system’, ‘user’) and content of each message.

  • temperature (float, optional) – Controls randomness in the generation. Lower values make the model more deterministic. Defaults to 0.

Returns:

The content of the first message in the response from the OpenAI API.

Return type:

str