> For the complete documentation index, see [llms.txt](https://underdogcowboy.gitbook.io/underdogcowboy-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://underdogcowboy.gitbook.io/underdogcowboy-docs/tools/llmconfigmanager.md).

# LLMConfigManager

The `LLMConfigManager` is a utility component within the `underdogcowboy` library that simplifies the management of credentials and configuration settings for various Large Language Models (LLMs).

### Key Features

1. **Credential Management**:
   * The `LLMConfigManager` allows you to securely store and retrieve credentials, such as API keys, for different LLM providers (e.g., Anthropic, OpenAI).
   * This enables seamless integration of LLMs that require authentication into your dialog-based applications.
2. **Configuration Updates**:
   * The `LLMConfigManager` provides a convenient interface to update specific properties of the LLM configurations, such as the model ID or other model-specific parameters.
   * This allows you to easily switch between different model versions or configurations within your scripts, without the need to manually update the credentials.
3. **Integration with DialogManager**:
   * The `LLMConfigManager` is integrated with the `DialogManager` component, ensuring that the appropriate credentials are used when interacting with LLMs through the dialog-based scripts.
   * This integration simplifies the development process and ensures consistency across your applications.

### Usage

Here's an example of how to use the `LLMConfigManager`:

```python
from underdogcowboy import LLMConfigManager

# Create an instance of the LLMConfigManager
config_manager = LLMConfigManager()

# Get the initial credentials for the 'anthropic' provider
creds = config_manager.get_credentials('anthropic')
print(f"Initial credentials: {creds['model_id']}")

# Update the model property for the 'anthropic' provider
config_manager.update_model_property('anthropic', 'model_id', 'claude-3-5-sonnet-20240620')

# Get the updated credentials
creds = config_manager.get_credentials('anthropic')
print(f"Final credentials: {creds['model_id']}")
```

In this example, the `LLMConfigManager` is used to:

1. Retrieve the initial credentials for the 'anthropic' provider.
2. Update the `model_id` property for the 'anthropic' provider.
3. Retrieve the updated credentials, which now reflect the changed `model_id`.

The `LLMConfigManager` is designed to work seamlessly with the `DialogManager` component, ensuring that the appropriate credentials are used when interacting with LLMs through your dialog-based scripts.

The LLMConfigManager is deeply integrated with the Timeline Editor and the DialogManager components in the underdogcowboy library. Let's highlight this integration:

## Integration with Timeline Editor and DialogManager

The `LLMConfigManager` is designed to work seamlessly with the other core components of the underdogcowboy library, specifically the [**Timeline Editor**](/underdogcowboy-docs/basics/timeline-editor.md) and the [**DialogManager**](/underdogcowboy-docs/basics/dialog-manager-in-underdog-cowboy.md).

### Timeline Editor Integration

The Timeline Editor, a powerful tool for managing conversational histories and processing user commands, utilizes the `LLMConfigManager` to ensure the appropriate credentials are used when interacting with language models.

When you're working within the Timeline Editor, you can switch between different LLM configurations, such as model versions or providers, by using the `switch-model` command. The `LLMConfigManager` handles the retrieval and application of the correct credentials for the selected model, simplifying the process of managing these settings.

### DialogManager Integration

The [`DialogManager`](/underdogcowboy-docs/basics/dialog-manager-in-underdog-cowboy.md) component, responsible for facilitating dialog-based interactions, is tightly integrated with the `LLMConfigManager`. When you create a dialog-based script using the `DialogManager`, the appropriate credentials are automatically fetched and used to communicate with the language models.

This integration ensures consistency and eliminates the need for you to manually manage the credentials within your dialog-based applications. The `DialogManager` seamlessly handles the credential management, allowing you to focus on developing the conversational logic and interaction flows.

By leveraging the `LLMConfigManager`, the Timeline Editor and the DialogManager components provide a streamlined and reliable way to integrate language models into your applications, simplifying the overall development process and reducing the risk of credential-related issues.

## Secure Credential Storage with Keyring

The `LLMConfigManager` utilizes the `keyring` module to securely store sensitive information, such as API keys and passwords, associated with the various LLM providers.

### Storing Sensitive Data

When the user provides sensitive credentials, such as an API key or password, the `LLMConfigManager` stores these values in the system's secure keyring storage instead of saving them directly in the configuration file.

### Benefits

By using the `LLMConfigManager`, you can:

1. **Centralize Credential Management**: Store and manage all your LLM credentials in a single, secure location, making it easier to maintain and update them as needed.
2. **Simplify Configuration Updates**: Quickly switch between different LLM configurations (e.g., model versions, parameters) without having to manually update the credentials in multiple places.
3. **Ensure Consistency**: The integration with the `DialogManager` guarantees that the correct credentials are used across your dialog-based applications, reducing the risk of errors or inconsistencies.
4. **Improve Scalability**: As your LLM-powered applications grow, the `LLMConfigManager` helps you manage the increasing complexity of credential and configuration management.

Overall, the `LLMConfigManager` is a valuable tool that streamlines the integration of LLMs into your dialog-based AI applications, promoting modularity, maintainability, and flexibility.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://underdogcowboy.gitbook.io/underdogcowboy-docs/tools/llmconfigmanager.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
