
    jQ	                        U d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZ ddlZ ej                  e      Z eh d      Zded<   	 	 	 	 ddZdd	Zdd
Z	 	 	 	 	 	 ddZy)z9Adapt OpenAI-style messages to Anthropic API conventions.    )annotationsN)AnyDictListOptionalSetTupleType>   modeltoolstop_ktop_psystemmessagesmetadata
max_tokenstemperaturetool_choicestop_sequenceszfrozenset[str]_SUPPORTED_PARAMSc                    g }g }| D ]I  }|j                  d      dk(  r"|j                  |j                  dd             9|j                  |       K |rdj                  |      nd}||fS )zSeparate system messages from conversation messages.

    Anthropic requires system content as a top-level parameter rather than
    a message with role="system".
    roler   content z

N)getappendjoin)r   system_parts
non_systemmsgsystem_texts        /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/models/anthropic/message_adapter.pyextract_system_messagesr#      sn     !L')J776?h&	2 67c"	 
 0<&++l+K
""    c                T    | j                         }|j                  dd       dd|diS )zBuild an Anthropic ``output_config`` dict from a pydantic model.

    Uses the native ``json_schema`` output format (SDK >=0.85) which
    constrains the model to produce JSON matching the schema directly,
    without the tool_use indirection.
    titleNformatjson_schema)typeschema)model_json_schemapop)r   r*   s     r"   pydantic_to_output_configr-   1   s8     $$&F
JJw!
 r$   c                D    | j                  d      r| t        d      d  S | S )Nz
anthropic/)
startswithlen)
model_names    r"   strip_anthropic_prefixr2   B   s)    \*#l+-..r$   c                    i }| j                         D ]?  \  }}|t        v r|||<   ||vst        j                  d|       |j	                  |       A |S )Nz.Dropping unsupported Anthropic parameter '%s'.)itemsr   LOGGERdebugadd)paramsalready_warnedfilteredkeyvalues        r"   filter_unsupported_paramsr=   H   s`      "Hlln
U##!HSM&LL@ s# % Or$   )r   zList[Dict[str, Any]]returnz*Tuple[Optional[str], List[Dict[str, Any]]])r   zType[pydantic.BaseModel]r>   Dict[str, Any])r1   strr>   r@   )r8   r?   r9   zSet[str]r>   r?   )__doc__
__future__r   loggingtypingr   r   r   r   r   r	   r
   pydantic	getLogger__name__r5   	frozensetr   __annotations__r#   r-   r2   r=    r$   r"   <module>rK      s    ? "  > > > 			8	$ %.% > "#"#/#&" r$   