pydantic_evals.generation
Utilities for generating example datasets for pydantic_evals.
This module provides functions for generating sample datasets for testing and examples, using LLMs to create realistic test data with proper structure.
            generate_dataset
  
      async
  
generate_dataset(
    *,
    dataset_type: type[
        Dataset[InputsT, OutputT, MetadataT]
    ],
    path: Path | str | None = None,
    custom_evaluator_types: Sequence[
        type[Evaluator[InputsT, OutputT, MetadataT]]
    ] = (),
    model: Model | KnownModelName = "openai:gpt-4o",
    n_examples: int = 3,
    extra_instructions: str | None = None
) -> Dataset[InputsT, OutputT, MetadataT]
Use an LLM to generate a dataset of test cases, each consisting of input, expected output, and metadata.
This function creates a properly structured dataset with the specified input, output, and metadata types. It uses an LLM to attempt to generate realistic test cases that conform to the types' schemas.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                path
             | 
            
                  Path | str | None
             | 
            
               Optional path to save the generated dataset. If provided, the dataset will be saved to this location.  | 
            
                  None
             | 
          
                dataset_type
             | 
            
                  type[Dataset[InputsT, OutputT, MetadataT]]
             | 
            
               The type of dataset to generate, with the desired input, output, and metadata types.  | 
            required | 
                custom_evaluator_types
             | 
            
                  Sequence[type[Evaluator[InputsT, OutputT, MetadataT]]]
             | 
            
               Optional sequence of custom evaluator classes to include in the schema.  | 
            
                  ()
             | 
          
                model
             | 
            
                  Model | KnownModelName
             | 
            
               The Pydantic AI model to use for generation. Defaults to 'gpt-4o'.  | 
            
                  'openai:gpt-4o'
             | 
          
                n_examples
             | 
            
                  int
             | 
            
               Number of examples to generate. Defaults to 3.  | 
            
                  3
             | 
          
                extra_instructions
             | 
            
                  str | None
             | 
            
               Optional additional instructions to provide to the LLM.  | 
            
                  None
             | 
          
Returns:
| Type | Description | 
|---|---|
                  Dataset[InputsT, OutputT, MetadataT]
             | 
            
               A properly structured Dataset object with generated test cases.  | 
          
Raises:
| Type | Description | 
|---|---|
                  ValidationError
             | 
            
               If the LLM's response cannot be parsed as a valid dataset.  | 
          
Source code in pydantic_evals/pydantic_evals/generation.py
              32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82  |  |