
    Ah)                     N    S SK JrJr  S SKJr  S SKJr  S SKJr   " S S\5      r	g)    )AnyUnion)parse_json_markdown)override)StringEvaluatorc                   
  ^  \ rS rSrSrS\SS4U 4S jjr\S\4S j5       r	\S\4S j5       r
\S\4S	 j5       rS
\S\\\S\\\\4   4S jrS\S\S\4S jr\  SS\\\4   S\\\4   S\\\4   S\S\4
S jj5       rSrU =r$ )JsonSchemaEvaluator	   aW  An evaluator that validates a JSON prediction against a JSON schema reference.

This evaluator checks if a given JSON prediction conforms to the provided JSON schema.
If the prediction is valid, the score is True (no errors). Otherwise, the score is False (error occurred).

Attributes:
    requires_input (bool): Whether the evaluator requires input.
    requires_reference (bool): Whether the evaluator requires reference.
    evaluation_name (str): The name of the evaluation.

Examples:
    evaluator = JsonSchemaEvaluator()
    result = evaluator.evaluate_strings(
        prediction='{"name": "John", "age": 30}',
        reference={
            "type": "object",
            "properties": {
                "name": {"type": "string"},
                "age": {"type": "integer"}
            }
        }
    )
    assert result["score"] is not None

kwargsreturnNc                 l   > [         TU ]  5          SSKng! [         a  nSn[        U5      UeSnAff = f)zInitializes the JsonSchemaEvaluator.

Args:
    kwargs: Additional keyword arguments.

Raises:
    ImportError: If the jsonschema package is not installed.
r   NziThe JsonSchemaEvaluator requires the jsonschema package. Please install it with `pip install jsonschema`.)super__init__
jsonschemaImportError)selfr   r   emsg	__class__s        `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/evaluation/parsing/json_schema.pyr   JsonSchemaEvaluator.__init__$   sB     		* 	*D  c")	*s    
3.3c                     g)z-Returns whether the evaluator requires input.F r   s    r   requires_input"JsonSchemaEvaluator.requires_input7   s         c                     g)z1Returns whether the evaluator requires reference.Tr   r   s    r   requires_reference&JsonSchemaEvaluator.requires_reference<   s     r   c                     g)z#Returns the name of the evaluation.json_schema_validationr   r   s    r   evaluation_name#JsonSchemaEvaluator.evaluation_nameA   s     (r   nodec                 2   [        U[        5      (       a  [        U5      $ [        US5      (       a*  [	        UR
                  5      (       a  UR                  5       $ [        US5      (       a*  [	        UR                  5      (       a  UR                  5       $ U$ )Nmodel_json_schemaschema)
isinstancestrr   hasattrcallabler'   r(   )r   r%   s     r   _parse_jsonJsonSchemaEvaluator._parse_jsonF   ss    dC  &t,,4,--(4;Q;Q2R2R))++4""x'<'<;;= r   
predictionr(   c                 j    SSK JnJn   U" XS9  SS0$ ! U a  nS[        U5      S.s S nA$ S nAff = f)Nr   )ValidationErrorvalidate)instancer(   F)score	reasoningr4   T)r   r1   r2   repr)r   r/   r(   r1   r2   r   s         r   	_validateJsonSchemaEvaluator._validateQ   s?    8	:j8   	:"a99	:s    2-22input	referencec                 h    U R                  U5      nU R                  U5      nU R                  XV5      $ )N)r-   r7   )r   r/   r9   r:   r   parsed_predictionr(   s          r   _evaluate_strings%JsonSchemaEvaluator._evaluate_stringsZ   s5     !,,Z8!!),~~/88r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   r   propertyboolr   r   r*   r#   r   dictlistfloatintr-   r7   r   r=   __static_attributes____classcell__)r   s   @r   r	   r	   	   s   4* * *&    D   ( ( (	 	dD$tSRU.U(V 	C     "&%)		9#s(O	9 S#X	9 c?		9
 	9 
	9 	9r   r	   N)
typingr   r   langchain_core.utils.jsonr   typing_extensionsr   langchain.evaluation.schemar   r	   r   r   r   <module>rP      s     9 & 7[9/ [9r   