
    j;                         U d dl mZmZmZmZmZmZmZmZ erd dl	Z
eeeeeef      f   ZddddddZeeef   ed<   deeeef      d	ed
   fdZy)    )TYPE_CHECKINGAnyDictIterableListMappingUnioncastNSystemMessageHumanMessage	AIMessage)systemuser	assistanthumanai_ROLE_TO_MESSAGE_CLASSmessagesreturnz#langchain_core.messages.BaseMessagec           	         ddl }t        j                         D ci c]  \  }}|t        |j                  |       }}}g }| D ]  }|}d|vr$t        |j                  d      t              r|d   }|j                  d      xs7 |j                  d      xs$ |j                  d      xs |j                  d      }|t        d      t        |      j                         }d|vrt        d      |d   }	t        |	t        t        f      st        d	t        |	      d
|       t        t        |	      }
||v r||   }|j!                   ||
             |dk(  rm|j                  d      xs |j                  d      }t        |t              st        d      |j!                  |j                  j#                  |
|             |dk(  rm|j                  d      xs |j                  d      }t        |t              st        d      |j!                  |j                  j%                  |
|             t        d|        |S c c}}w )a  Convert OpenAI-style chat messages to LangChain's primitives.

    Args:
        messages: Iterable of message dictionaries in the OpenAI schema. Each
            dictionary must include a ``role`` key and a ``content`` value that is
            either a string or a list of content blocks (``{"type": ..., ...}``).

    Returns:
        A list of LangChain ``BaseMessage`` instances preserving the original
        content structure.

    Raises:
        ValueError: If a message role is unsupported or required metadata is
            missing (for example ``tool_call_id`` on ``tool`` messages).
        TypeError: If a content payload is not a string or list.
    r   Ncontentdataroletypez4Message payload must include either 'role' or 'type'z.Message payload must include a 'content' fieldz!Unsupported message content type z
 for role )r   tooltool_call_idz1Tool messages must include a 'tool_call_id' field)r   r   functionnamez-Function messages must include a 'name' field)r   r   zUnsupported message role: )langchain_core.messagesr   itemsgetattrr   
isinstancegetr   
ValueErrorstrlowerlist	TypeErrorr   r
   ContentTypeappendToolMessageFunctionMessage)r   langchain_corer   
class_namerole_mappinglangchain_messagesmessagepayload
role_valuecontent_rawr   message_clsr   r   s                 /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/models/langchain/message_converters.pyconvert_to_langchain_messagesr7      sv   ( # !7 < < > >D* 	gn--z:: >  
 GI%, G#
7;;v3F(PfoG KK #{{6"#{{6"# {{6"	 	 STT:$$&G#MNNi(+T{33D4E3H
SWRXY  {K0<&t,K%%k'&BC6>";;~6U'++n:ULlC0 !TUU%%''33#!- 4  :;;v&='++f*=DdC( !PQQ%%''77# 8  5dV<==u x Es   !I)typingr   r   r   r   r   r   r	   r
   r   r-   r%   r)   r   __annotations__r7        r6   <module>r<      s    Q Q Q"Cd38n--. 
- S) XwsCx()X	
/0Xr;   