GPT API Module

This module provides functionality for interacting with the GPT API.

It includes functions for loading configurations, constructing prompts, sending requests to the GPT API, and managing message history.

twitch_claude_bot.gpt_api.clear_message_history() None[source]

Clear the message history.

twitch_claude_bot.gpt_api.construct_conversation(full_prompt: str) List[Dict][source]

Construct a conversation history including the new prompt.

Parameters:

full_prompt (str) – The full constructed prompt.

Returns:

A list of conversation messages in the format required by the API.

Return type:

List[Dict]

twitch_claude_bot.gpt_api.construct_full_prompt(prompt: str, persona_config: Dict) str[source]

Construct a full prompt by combining the user’s input with persona configuration.

Parameters:
  • prompt (str) – The user’s input prompt.

  • persona_config (Dict) – The configuration for the selected persona.

Returns:

The full constructed prompt.

Return type:

str

async twitch_claude_bot.gpt_api.get_gpt_response(prompt: str, persona: str = 'gpt_wizard') str[source]

Get a response from the GPT API based on the given prompt and persona.

Parameters:
  • prompt (str) – The user’s input prompt.

  • persona (str, optional) – The persona to use for the response. Defaults to ‘gpt_wizard’.

Returns:

The AI-generated response.

Return type:

str

Raises:

Exception – If the API request fails.

twitch_claude_bot.gpt_api.load_config(file_name: str) Dict[source]

Load configuration from a YAML file.

Parameters:

file_name (str) – The name of the configuration file.

Returns:

A dictionary containing the configuration data.

Return type:

Dict

twitch_claude_bot.gpt_api.log_interaction(prompt: str, response: str) None[source]

Log the interaction between the user and the AI.

Parameters:
  • prompt (str) – The user’s input prompt.

  • response (str) – The AI-generated response.

twitch_claude_bot.gpt_api.update_message_history(prompt: str, response: str) None[source]

Update the message history with the new prompt and response.

Parameters:
  • prompt (str) – The user’s input prompt.

  • response (str) – The AI-generated response.