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:
gemini- Google’s AI models with multimodal supportopenai- OpenAI models including GPT-4huggingface- Open-source models from Hugging Faceollama- Local model execution using Ollamarhesis- Models served by Rhesis
To use a specific model, provide its name in the format provider/model_name:
The above code is equivalent to:
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
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
Note: Batch processing is currently available for LiteLLM-based providers (OpenAI, Gemini, and other supported providers).
Embedders
Embedders generate vector representations (embeddings) of text, which are useful for semantic search, similarity comparison, and clustering tasks.
Using the get_embedder function
The easiest way to use embedders is through the get_embedder function. When called without arguments, it returns the default OpenAI 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.
When to use embedders:
- Semantic similarity search
- Clustering similar documents or test cases
- Finding related test inputs
- Building retrieval-augmented generation (RAG) systems
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:
See the Model entity documentation for more details on managing model configurations.