o
    i                     @  s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ dZededZ	 ededZ	 ededZ	 ddddddd&d$d%ZdS )'zUtilities 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.
    )annotations)Sequence)Path)Any)ValidationError)TypeVar)Agentmodels)strip_markdown_fences)Dataset)	Evaluator)generate_datasetInputsT)defaultOutputT	MetadataTN zopenai:gpt-4o   )pathcustom_evaluator_typesmodel
n_examplesextra_instructionsdataset_type*type[Dataset[InputsT, OutputT, MetadataT]]r   Path | str | Noner   6Sequence[type[Evaluator[InputsT, OutputT, MetadataT]]]r   $models.Model | models.KnownModelNamer   intr   
str | Nonereturn$Dataset[InputsT, OutputT, MetadataT]c              
     s   |  |}t|d| d| dtdd}||pdI dH }t|j}	z
| j|	d|d	}W n tyD }
 z
td
|j  |
d}
~
ww |durP|j	||d |S )a1  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.

    Args:
        path: Optional path to save the generated dataset. If provided, the dataset will be saved to this location.
        dataset_type: The type of dataset to generate, with the desired input, output, and metadata types.
        custom_evaluator_types: Optional sequence of custom evaluator classes to include in the schema.
        model: The Pydantic AI model to use for generation. Defaults to 'gpt-4o'.
        n_examples: Number of examples to generate. Defaults to 3.
        extra_instructions: Optional additional instructions to provide to the LLM.

    Returns:
        A properly structured Dataset object with generated test cases.

    Raises:
        ValidationError: If the LLM's response cannot be parsed as a valid dataset.
    z@Generate an object that is in compliance with this JSON schema:
z


Include z example cases. You must not include any characters in your response before the opening { of the JSON object, or after the closing }.   )system_promptoutput_typeretrieszPlease generate the object.Njson)fmtr   zRaw response from model:
)r   )
!model_json_schema_with_evaluatorsr   strrunr
   output	from_textr   printto_file)r   r   r   r   r   r   output_schemaagentresultr+   er   r   _/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_evals/generation.pyr   !   s,   

r   )r   r   r   r   r   r   r   r   r   r   r   r   r    r!   )__doc__
__future__r   collections.abcr   pathlibr   typingr   pydanticr   typing_extensionsr   pydantic_air   r	   pydantic_ai._utilsr
   pydantic_evalsr   #pydantic_evals.evaluators.evaluatorr   __all__r   r   r   r   r   r   r   r3   <module>   s0    