Thank you for your interest in contributing to OpenRouter Runner! We welcome all contributions, big or small. This guide will provide you with detailed steps for setting up your environment, adding new models, deploying, and testing. If you have any questions, please feel free to reach out to us on Discord.
- Install pnpm
- Install Poetry
- Create a Modal account
- (Optional) Create a GCP Account
- Ensure you have a Hugging Face Account
Setting up your development environment is the first step to contributing. Here's how you can get started:
-
Install Poetry: Poetry is a tool for dependency management and packaging in Python. Install it by following the instructions on the official Poetry installation page.
-
Install pnpm: pnpm is a fast, disk space-efficient package manager. To install it, follow the instructions on the official pnpm installation page.
-
Setup Modal CLI: The Modal CLI is essential for interacting with the Modal platform. Install it using the following command:
pip install modal
-
Run Scripts with pnpm: Once you have pnpm installed, you can run scripts as follows:
pnpm run script-name
Replace
script-name
with the name of the script you want to execute. -
(OPTIONAL) Setup linting: To ensure PR consistency, install our lightweight pre-commit hooks:
pre-commit install
Properly setting up your environment and secrets is crucial for a secure and efficient development workflow. Here's how to do it:
-
Set Your Current Directory: Ensure that your terminal's current working directory is the
/modal
directory within the project. This is where you'll be running most of your commands. Change it using thecd
command:cd path/to/modal
-
Create a Development Environment in Modal: A separate development environment in Modal allows you to test and develop without affecting the production. Set it up using:
modal environment create dev
This command creates a new environment named 'dev'.
-
Configure Modal CLI: Configure the Modal CLI to use your newly created development environment:
modal config set-environment dev
-
Create Modal Secrets:
- Hugging Face Token: To update models you'll need to have a Hugging Face Token and store it. You'd run this script to store the secret in your Modal account.
modal secret create huggingface HUGGINGFACE_TOKEN=<your huggingface token>
- Runner API Key: You'll also need to create a unique runner API key, create one and then add it to Modal as follows:
modal secret create runner-api RUNNER_API_KEY=<generate a strong key>
Replace
<your huggingface token>
and<generate a strong key>
with your actual tokens. - Hugging Face Token: To update models you'll need to have a Hugging Face Token and store it. You'd run this script to store the secret in your Modal account.
-
Verify Secrets: After setting up your secrets, verify that they are correctly stored in your Modal dashboard under the secrets tab.
Important
Keep your API keys and secrets secure. Do not share them in public repositories or with unauthorized persons.
When adding a new model to OpenRouter Runner, you'll be integrating external AI models to enhance the capabilities of the system. Here's how to do it step by step:
-
Identify the Model: Determine if the open-source model you wish to add is supported by an existing engine and can run in an existing container. Find the model's Hugging Face ID or equivalent identifier.
-
Update the Container List:
- If the model is compatible with existing infrastructure, simply add its identifier to the relevant list in
runner/containers/__init__.py
.
existing_model_ids = [ ..., "new-model-id", # Add your new model ID here. ]
- If the model is compatible with existing infrastructure, simply add its identifier to the relevant list in
-
Handle Unsupported Models:
- If the model isn't supported by existing engines or containers, you'll need to add a new engine and add a new container.
Important
Always verify the model's license and ensure it's compatible with OpenRouter Runner's usage.
Creating a new engine involves setting up the logic to interact with different types of AI models or adapting existing models to new requirements. Here's a detailed guide based on the structure of engines like the one you provided:
-
Understand the Existing Engine Structure:
- Familiarize yourself with the structure and components of an existing engine, like the
vllm.py
. Notice how it uses parameters (VllmParams
), handles generation withgenerate
, and manages asynchronous operations.
- Familiarize yourself with the structure and components of an existing engine, like the
-
Copy an Existing Engine as a Template:
- Use an existing engine file as a starting point. Copy it and rename it to reflect your new engine.
cp path/to/runner/engines/vllm.py path/to/runner/engines/new_engine.py
-
Customize the Engine Parameters:
- If your engine requires different initialization parameters, create or modify a parameter class similar to
VllmParams
. This class should inherit fromBaseModel
and define the necessary configuration for your model.
class NewEngineParams(BaseModel): # Define your parameters here model: str # ... other parameters ...
- If your engine requires different initialization parameters, create or modify a parameter class similar to
-
Implement the New Engine Logic:
- Modify the
NewEngine
class to suit your requirements. Pay special attention to thegenerate
method, as this is where the main logic for model interaction occurs. - Ensure to handle exceptions and edge cases effectively, as shown in the provided snippet.
class NewEngine(BaseEngine): def __init__(self, params: NewEngineParams): # Initialize your engine with the provided parameters @method() async def generate(self, payload: Payload, params): # Implement the generation logic for your new engine # This might include setting up asynchronous calls, handling streaming data, etc.
- Modify the
-
Proceed to Container Creation:
- After successfully creating your new engine, the next step is to incorporate it into a new container. The container will provide the necessary runtime environment for your engine to execute. Follow the guidelines in the add a new container section to create a container that leverages your new engine.
Tip
Developing a new engine requires an understanding of asynchronous programming in Python, especially for handling real-time data streaming and large-scale model interactions. If you're new to this, consider reviewing resources on async programming in Python and the specific libraries your project uses.
By following these detailed steps, contributors will have a clearer understanding of how to approach engine development, ensuring that new engines are robust, efficient, and well-integrated into the OpenRouter Runner system.
Adding a new container is necessary when your model requires a different environment, software, or hardware configuration. Follow these steps to create and integrate a new container:
-
Copy an Existing Container:
- Use an existing container as your template.
cp path/to/runner/containers/existing_container.py path/to/runner/containers/new_container.py
-
Customize the Container:
- Modify the
new_container.py
file. Adjust the class name, Docker image, machine type, and any other settings to suit your new model's needs.
class NewContainer(BaseContainer): def __init__(self, ...): # Set up the new container's specific configurations. # Implement any additional methods required for the new container.
- Modify the
-
Register the Container:
- In
./containers/__init__.py
, import your new container class and add your model's ID to the system.
from .new_container import NewContainer new_model_ids = ["your-new-model-id"]
- In
-
Include in Model Download List:
- Ensure the
all_models
list in the same__init__.py
file includes your new list of model IDs.
all_models = [ ..., *new_model_ids ]
- Ensure the
-
Testing Your Container:
- After setting up your new container, refer to the Configuration and Testing section to test it thoroughly.
Tip
Creating a new container may require knowledge of Docker, cloud environments, and the specific needs of the model you're adding.
For detailed steps on setting up your environment and testing your models, please refer to the Configuration and Testing section in the Runner README. Here's a brief overview:
-
Set Up Environment Variables: Create a
.env.dev
file in the root of your project and include necessary details likeAPI_URL
,RUNNER_API_KEY
, andMODEL
. -
Install Dependencies: Ensure all required tools and libraries are installed as per the instructions in the Runner README.
-
Run Your Application for Testing: Follow the steps to start your OpenRouter Runner and test the models using the provided scripts.
Note
For comprehensive instructions, including how to load environment variables, choose test scripts, and interpret the results, please refer to the detailed guide in the Runner README.
To deploy your OpenRouter Runner to Modal and monitor its performance, please see the Deploying section in the Runner README. A summary of the steps includes:
-
Deploy to Modal: Use the
modal deploy runner
command to package your configurations and models into a live application. -
Monitor and Troubleshoot: Keep an eye on your application's performance and logs through the Modal dashboard. Refer to the Runner README for detailed steps on how to access and interpret these logs.
Tip
Always test your changes in a development environment before deploying to production. For a detailed guide on deployment best practices, refer to the Runner README.
Your contributions are invaluable to us. Please adhere to our contributing guide and code of conduct to maintain a healthy and welcoming community. For detailed instructions on adding models, engines, containers, and more, refer to the Runner Setup Guide.