
    j                        d Z ddlmZ ddlmZmZmZmZ ddZ	 	 	 	 	 	 	 	 	 	 ddZ	ddZ
	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 dd	Zy
)z-Utility helpers shared across LiteLLM models.    )annotations)AnyCallableDictSetc                    t        | t              r| S t        | d      r&t        | j                        r	 | j	                         S i }t        | dd      }|||d<   t        | dd      }|||d<   |S # t
        $ r Y 7w xY w)a  Produce a dict view of a LiteLLM choice regardless of response type.

    LiteLLM may return raw dicts, Pydantic models, or dataclasses. Normalising to a
    dict here keeps downstream parsing logic consistent and backwards compatible with
    older client versions.
    
model_dumpmessageNlogprobs)
isinstancedicthasattrcallabler	   	TypeErrorgetattr)choice
normalisedr
   r   s       |/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/models/litellm/util.pynormalise_choicer      s     &$v|$&2C2C)D	$$&& "$Jfi.G '
9vz40H!)
:  		s   A1 1	A=<A=c                    t        |       }|j                  d      rt        |||       y|j                  d      rt        |||       yy)zAdjust/drop params for specific model families before calling LiteLLM.

    Currently handles:
    - GPT-5: only honours temperature=1 and does not return log probabilities.
    - DashScope Qwen: enforces constraints for logprobs / top_logprobs
    zgpt-5Nz
dashscope/)_normalize_model_name
startswith_apply_gpt5_filters_apply_qwen_dashscope_filters)
model_nameparamsalready_warnedwarnnormalized_model_names        r   apply_model_specific_filtersr    !   sN     2*=''0FND9''5%fndC 6    c                H    d| vr| S | j                  dd      \  }}|dv r|S | S )z>Normalize provider-prefixed model names for capability checks./   )openai	anthropic)split)r   providermodel_without_providers      r   r   r   8   s=    
*'1'7'7Q'?$H$**%%r!   c                   g }d| v r7| d   }	 t        |      }|t        |dz
        dkD  r|j	                  d|f       dD ]  }|| v s|j	                  || |   f        t        | |||       y# t        t        f$ r d}Y jw xY w)zApply GPT-5 specific parameter filters.

    Only honours temperature=1 and does not return log probabilities.
    Removing those eagerly avoids provider errors while the callback surfaces a
    one-time warning to the caller.
    temperatureNg      ?gư>r   top_logprobs)floatr   
ValueErrorabsappend%_drop_unsupported_params_with_warning)r   r   r   unsupportedvaluenumeric_valueparams          r   r   r   D   s     *,K}%	!!%LM  C(;$<t$Cu56-F?ve}56 . *	 :& 	! M	!s   A/ /BBc                h    g }dD ]  }|| v s|j                  || |   f        t        | |||       y)z]Apply Qwen/DashScope specific parameter filters.

    Does not return log probabilities.
    r,   N)r1   r2   )r   r   r   r3   r6   s        r   r   r   g   sG     *,K-F?ve}56 . *	r!   c                z    |D ]6  \  }}| j                  |d       ||v r |||       |j                  |       8 y)z@Remove unsupported params and emit warnings once per param name.N)popadd)r   unsupported_paramsr   r   r6   r4   s         r   r2   r2      sC     +u

5$N"UE5! +r!   N)r   r   returnDict[str, Any])
r   strr   r=   r   Set[str]r   Callable[[str, Any], None]r<   None)r   r>   r<   r>   )r   r=   r   r?   r   r@   r<   rA   )
r   r=   r;   zlist[tuple[str, Any]]r   r?   r   r@   r<   rA   )__doc__
__future__r   typingr   r   r   r   r   r    r   r   r   r2    r!   r   <module>rF      s    3 " + +2  %	
 
.	    %  
	 F % 
	0""-" " %	"
 
"r!   