Skip to content

Conversation

@ronakice
Copy link
Member

@ronakice ronakice commented Jun 1, 2025

No description provided.

… done so far and provide feedback for Jules to continue.
This commit introduces support for using language models via OpenRouter.ai.

Key changes include:

1.  **Core LLM Handlers (`LLMHandler`, `AsyncLLMHandler`):**
    *   Modified to recognize "openrouter" as an `api_type`.
    *   Can automatically detect OpenRouter usage if the model name is prefixed with "openrouter/".
    *   Handle OpenRouter API key retrieval (from `OPENROUTER_API_KEY` env var or direct `api_keys` param).
    *   Set the correct API base URL (`https://openrouter.ai/api/v1` by default, configurable via `api_base` param).
    *   Initialize OpenAI/AsyncOpenAI clients appropriately for OpenRouter.
    *   Support API key rotation for OpenRouter keys.

2.  **API Key Utilities (`utils/api.py`):**
    *   Added `get_openrouter_api_key()` function to fetch keys from the environment.

3.  **Examples (`examples/e2e.py`, `examples/async_e2e.py`):**
    *   Added command-line arguments (`--api_type`, `--api_base`, `--api_key`) to allow easy configuration and testing of different API providers, including OpenRouter.
    *   Updated example instantiation of `Nuggetizer`/`AsyncNuggetizer` to pass these through.

4.  **Testing (`tests/core/test_llm.py`):**
    *   Created new test suite for `LLMHandler` and `AsyncLLMHandler`.
    *   Added comprehensive unit tests for OpenRouter integration, covering various initialization scenarios (model prefix, `api_type` parameter, custom base URL, direct API key), API key error handling, and API key rotation.

5.  **Documentation (`README.md`):**
    *   Updated to include instructions on configuring and using OpenRouter models.
    *   Added details on setting the `OPENROUTER_API_KEY` environment variable.
    *   Provided examples of initializing `Nuggetizer` with OpenRouter models.
    *   Updated example command lines to show OpenRouter usage.

This integration allows you to leverage a wider range of models available through OpenRouter, enhancing the flexibility of the nuggetizer library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants