Models
Models are core components of the SDK that enable you to create and manage test sets for Gen AI applications. Models also play a crucial role in the evaluation process, serving as LLM judges to assess and validate outputs.
Using the get_model function
The easiest way to use models is through the get_model function. When called without any arguments, this function returns the default Rhesis model.
To use a different provider, you can pass the provider name as an argument. This will use the default model for that provider.
Supported providers (highlights):
rhesis- Rhesis-hosted default modelsopenai,anthropic,gemini,vertex_ai- major hosted providersazure_ai- Azure AI Studio deployments via LiteLLMazure- Azure OpenAI deployments via LiteLLMlitellm_proxy- OpenAI-compatible LiteLLM Proxy endpointopenrouter,mistral,cohere,groq,perplexity,replicate,together_aiollama,huggingface,lmformatenforcer- local/self-hosted options
Use get_model(...) for the most stable cross-provider API.
To use a specific model, provide its name in the format provider/model_name:
The above code is equivalent to:
Provider-specific connection options
Some providers accept extra connection parameters:
| Provider | Required fields | Optional fields | Notes |
|---|---|---|---|
litellm_proxy | model_name | api_base, api_key | api_base defaults to LITELLM_PROXY_BASE_URL env var or http://0.0.0.0:4000 |
azure_ai | model_name, api_base, api_key | — | api_base/api_key can be supplied via AZURE_AI_API_BASE/AZURE_AI_API_KEY env vars |
azure | model_name, api_base, api_key | api_version | api_base/api_key/api_version can be supplied via AZURE_API_BASE/AZURE_API_KEY/AZURE_API_VERSION env vars |
Direct import
Alternatively, you can access models by importing the model class directly. When you provide a model name as an argument, that specific model will be used. If no model name is provided, the default model for that provider will be used.
Generate content with models
All models share a consistent interface. The primary function is generate, which accepts:
prompt: The text prompt for generationschema: (optional) A Pydantic schema defining the structure of the generated text
Language model generation APIs (v0.6.9+)
Language-model providers in the SDK are async-first. You can use:
| Method | Execution style | Typical use |
|---|---|---|
generate(...) | Synchronous convenience wrapper | Scripts and notebooks without explicit async code |
a_generate(...) | Native async call | Async services, workers, and concurrent pipelines |
generate_batch(...) | Multi-prompt batch call | High-throughput generation for datasets or evaluations |
generate(...) internally bridges to a_generate(...). If your application is already async, prefer a_generate(...) directly.
Generate text using prompt only:
Generate structured output using schemas:
Batch Processing
For improved performance when processing multiple prompts, use the generate_batch method. This method leverages parallel processing to efficiently handle multiple requests simultaneously.
Basic batch generation:
Batch generation with structured output:
Generate multiple completions per prompt:
When to use batch processing:
- Processing large test sets or datasets
- Running evaluations across multiple inputs
- Generating multiple test variations
- Any scenario requiring parallel LLM calls
Batch processing is available for LiteLLM-based providers and rhesis language models.
Using models with synthesizers and metrics
Models become most useful when combined with synthesizers and metrics:
Saving models to the platform
You can save an LLM configuration to the Rhesis platform as a Model entity. This allows you to:
- Store model configurations centrally for team sharing
- Set default models for test generation and evaluation
- Retrieve configurations across different scripts
You can also retrieve saved configurations and convert them back to LLM instances:
Embedders
Embedders generate vector representations (embeddings) of text, which are useful for semantic search, similarity comparison, and clustering tasks.
Using the get_model function
The easiest way to use embedders is through the get_model function with embedding models. When called with an embedding model, it automatically detects the type and returns an embedder.
To use a specific model, provide the model name:
The above code is equivalent to:
Direct import
You can also import the embedder class directly:
Generate embeddings
All embedders share a consistent interface with two main methods:
Generate embedding for a single text:
Generate embeddings for multiple texts:
Configuring embedding dimensions
Some embedding models (like OpenAI’s text-embedding-3 family) support configurable output dimensions. Smaller dimensions reduce storage and computation costs while maintaining most of the semantic information.
See the Model entity documentation for more details on managing model configurations.