This repository demonstrates how to create and set up Clarifai local runners for custom model development. It contains a sample text-to-text model that performs string manipulation operations.
Before setting up this repository, ensure you have:
- Python 3.11+ installed
- pip package manager
- Git
- A Clarifai account
The Clarifai CLI provides several commands for local model development:
Install the latest version of the Clarifai Python SDK:
pip install -U clarifaiclarifai loginFill the details requested during login
To setup a new codebase:
clarifai model initElse if you have a codebase on git already:
clarifai model init <codebase-path> --github-repo <user>/<repo> --github-pat <github-token>This sets up your codebase to develop.
Now, you can start your local runner:
clarifai model local-runnerThis connects your local model to the Clarifai platform for testing while keeping the model running locally.
Refer this guide on how to obtain one from the platform.
Once your runner is started, you can test it with a simple prediction:
import os
from clarifai.client import Model
from clarifai.runners.utils import data_types
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
model = Model("https://clarifai.com/<user-id>/local-dev-runner-app/models/local-dev-model",
deployment_id = 'local-dev-deployment', # Only needed for dedicated deployed models
base_url='https://api.clarifai.com',
)
# Example model prediction from different model methods:
response = model.predict(prompt="What is the future of AI?", number_of_letters=3)
print(response)To create your own model:
- Modify the
MyModelclass in1/model.py - Implement your custom logic in the model methods
- Update the
config.yamlwith your model details - Test locally using the provided commands
- Upload to Clarifai platform
To add additional Python packages:
- Add them to
requirements.txt - Run
pip install -r requirements.txt - Import and use them in your model code
- Import Errors: Ensure all dependencies are installed with
pip install -r requirements.txt - Model Not Loading: Check that your model class inherits from
ModelClassand implementsload_model() - Configuration Errors: Verify your
config.yamlhas valid user_id, app_id, and model_id values - "inference_compute_info not found" Error: Ensure your
config.yamlincludes the completeinference_compute_infosection as shown in the configuration example
- Check the Clarifai Documentation
- Use
clarifai --helpfor CLI command help - Use
clarifai model --helpfor model-specific commands