UFO supports and welcomes the integration of custom LLM models. If you have a custom LLM model that you would like to use with UFO, follow the steps below to configure it.
Create a custom LLM model and serve it on your local or remote environment. Ensure your model has an accessible API endpoint.
Create a Python script under the ufo/llm directory and implement your own LLM model class by inheriting the BaseService class from ufo/llm/base.py.
Reference Example: See PlaceHolderService in ufo/llm/placeholder.py as a template.
You must implement the chat_completion method:
def chat_completion(
self,
messages: List[Dict[str, str]],
n: int = 1,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs: Any,
) -> Tuple[List[str], Optional[float]]:
"""
Generates completions for a given list of messages.
Args:
messages: The list of messages to generate completions for.
n: The number of completions to generate for each message.
temperature: Controls the randomness (higher = more random).
max_tokens: The maximum number of tokens in completions.
top_p: Controls diversity (higher = more diverse).
**kwargs: Additional keyword arguments.
Returns:
Tuple[List[str], Optional[float]]:
- List of generated completions for each message
- Cost of the API call (None if not applicable)
Raises:
Exception: If an error occurs while making the API request.
"""
# Your implementation here
passKey Implementation Points:
- Handle message formatting according to your model's API
- Process visual inputs if
VISUAL_MODEis enabled - Implement retry logic for failed requests
- Calculate and return cost if applicable
Configure the HOST_AGENT and APP_AGENT in the config/ufo/agents.yaml file to use your custom model.
If the file doesn't exist, copy it from the template:
Copy-Item config\ufo\agents.yaml.template config\ufo\agents.yamlEdit config/ufo/agents.yaml with your custom model configuration:
HOST_AGENT:
VISUAL_MODE: True # Set based on your model's capabilities
API_TYPE: "custom_model" # Use custom model type
API_BASE: "http://your-endpoint:port" # Your model's API endpoint
API_KEY: "YOUR_API_KEY" # Your API key (if required)
API_MODEL: "your-model-name" # Your model identifier
APP_AGENT:
VISUAL_MODE: True
API_TYPE: "custom_model"
API_BASE: "http://your-endpoint:port"
API_KEY: "YOUR_API_KEY"
API_MODEL: "your-model-name"Configuration Fields:
VISUAL_MODE: Set toTrueif your model supports visual inputsAPI_TYPE: Use"custom_model"for custom implementationsAPI_BASE: Your custom model's API endpoint URLAPI_KEY: Authentication key (if your model requires it)API_MODEL: Model identifier or name
For detailed configuration options, see:
- Agent Configuration Guide - Complete agent settings reference
- Model Configuration Overview - Compare different LLM providers
Update the model factory in ufo/llm/__init__.py to include your custom model class:
from ufo.llm.your_model import YourModelService
# Add to the model factory mapping
MODEL_FACTORY = {
# ... existing models ...
"custom_model": YourModelService,
}After configuration, you can start using UFO with your custom model. Refer to the Quick Start Guide for detailed instructions on running your first tasks.
Testing Your Integration:
- Test with simple requests first
- Verify visual mode works (if applicable)
- Check error handling and retry logic
- Monitor response quality and latency