
    j                     N    d dl mZmZ ddlmZmZ  G d dej                        Zy)    )AnyOptional   )base_metricscore_resultc                        e Zd ZdZ	 	 	 	 	 ddedee   dededee   f
 fdZ	 ddedee   d	ed
e	j                  fdZ xZS )Containsa_  
    A metric that checks if a reference string is contained within an output string.

    This metric returns a score of 1.0 if the reference string is found within the output string,
    and 0.0 otherwise. The comparison can be made case-sensitive or case-insensitive.

    Args:
        case_sensitive: Whether the comparison should be case-sensitive. Defaults to False.
        reference: Optional default reference string. If provided, it will be used unless
            a reference is explicitly passed to `score()`.
        name: The name of the metric. Defaults to "contains_metric".
        track: Whether to track the metric. Defaults to True.
        project_name: Optional project name to track the metric in for the cases when there are
            no parent span/trace to inherit project name from.

    Examples:
        >>> # Using a default reference at initialization
        >>> contains_metric = Contains(reference="world")
        >>> result = contains_metric.score("Hello, World!")
        >>> print(result.value)
        1.0

        >>> # Overriding the default reference at score time
        >>> result = contains_metric.score("Hello, World!", reference="there")
        >>> print(result.value)
        0.0

        >>> # If no reference is set at all, score() raises an error
        >>> contains_metric = Contains()
        >>> contains_metric.score("Hello")
        Traceback (most recent call last):
            ...
        ValueError: No reference string provided. Either pass `reference` to `score()` or set a default reference when creating the metric.

        >>> # Empty reference string is invalid
        >>> contains_metric = Contains(reference="")
        >>> contains_metric.score("Hello")
        Traceback (most recent call last):
            ...
        ValueError: Invalid reference string provided. Reference must be a non-empty string.
    case_sensitive	referencenametrackproject_namec                 F    t         |   |||       || _        || _        y )N)r   r   r   )super__init___case_sensitive_default_reference)selfr
   r   r   r   r   	__class__s         /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/metrics/heuristics/contains.pyr   zContains.__init__1   s2     	% 	 	

  ."+    outputignored_kwargsreturnc                 `   ||n| j                   }|t        d      |dk(  rt        d      | j                  r|n|j                         }| j                  r|n|j                         }||v r!t	        j
                  d| j                        S t	        j
                  d| j                        S )aC  
        Calculate the score based on whether the reference string is contained in the output string.

        Args:
            output: The output string to check.
            reference: The reference string to look for in the output. If None, falls back to the
                default reference provided at initialization.
            **ignored_kwargs: Additional keyword arguments that are ignored.

        Returns:
            score_result.ScoreResult: A ScoreResult object with a value of 1.0 if the reference
                is found in the output, 0.0 otherwise.
        zwNo reference string provided. Either pass `reference` to `score()` or set a default reference when creating the metric. zHInvalid reference string provided. Reference must be a non-empty string.g      ?)valuer   g        )r   
ValueErrorr   lowerr   ScoreResultr   )r   r   r   r   refr   s         r   scorezContains.scoreA   s    " %0id6M6M ; J 
 "9Z  ..FLLN))csyy{%<++#DIIFF''c		BBr   )FNcontains_metricTN)N)__name__
__module____qualname____doc__boolr   strr   r   r   r    r"   __classcell__)r   s   @r   r	   r	      s    (X  %#'%&*,, C=, 	,
 , sm," 7;%C%C&.sm%CNQ%C		!	!%Cr   r	   N)typingr   r   r   r   r   
BaseMetricr	    r   r   <module>r.      s!      (`C{%% `Cr   