o
    #1 i=*                     @   s  U d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZ e jd	ed
d dedefddZG dd deeZG dd deZG dd deZ G dd deZ!G dd deZ"G dd de"Z#G dd deZ$ee
e!e e"e$f eddf Z%ee
e!e e#e$f eddf Z&e	d e%d!Z'e	d"e d!Z(e	d#e"d!Z)e	d$e$d!Z*e	d%e!d!Z+e
e(e)e*e+f Z,ee-d&< dS )'    N)Enum)AnyDictListLiteralOptionalTypeVarUnion)Field)	Annotated	TypeAlias)MistralBase)ContentChunk	TextChunk
ThinkChunkUserContentChunk_convert_openai_content_chunks)ToolCalloncezN.*has moved to 'mistral_common.protocol.instruct.chunk'\. It will be removed.*)actioncategorymessagenamereturnc                 C   s  |  dt  d}| dkrddlm} t|t |S | dkr,ddlm} t|t |S | dkr>dd	lm} t|t |S | d
krPddlm} t|t |S | dkrbddlm	} t|t |S | dkrtddlm
} t|t |S | dkrddlm} t|t |S | dkrddlm}	 t|t |	S | dkrddlm}
 t|t |
S | dkrddlm} t|t |S tdt  d|  )NzQ has moved to 'mistral_common.protocol.instruct.chunk'. It will be removed from 'z' in 1.10.0.AudioURLr   )r   AudioURLChunk)r   AudioURLType)r   
AudioChunk)r   BaseContentChunk)r   
ChunkTypes)r   ImageURL)r    ImageURLChunk)r!   
ImageChunk)r"   RawAudio)r#   zmodule z has no attribute )__name__&mistral_common.protocol.instruct.chunkr   warningswarnFutureWarningr   r   r   r   r   r    r!   r"   r#   AttributeError)r   msgr   r   r   r   r   r   r    r!   r"   r#    r+   u/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/mistral_common/protocol/instruct/messages.py__getattr__   sV   r-   c                   @   s    e Zd ZdZdZdZdZdZdS )RoleszEnum for the roles of the messages.

    Attributes:
       system: The system role.
       user: The user role.
       assistant: The assistant role.
       tool: The tool role.

    Examples:
        >>> role = Roles.user
    systemuser	assistanttoolN)r$   
__module____qualname____doc__r/   r0   r1   r2   r+   r+   r+   r,   r.   T   s    r.   c                   @   s   e Zd ZU dZeejejejej	f e
d< deeeeeeeeeeeef f f  f f fddZedeeeeeeeeeeeef f f  f f dd fddZd	S )
BaseMessagezXBase class for all messages.

    Attributes:
       role: The role of the message.
    roler   c                 C   s   t dt| j )zaConverts the message to the OpenAI format.

        Should be implemented by subclasses.
        z%to_openai method not implemented for )NotImplementedErrortyper$   selfr+   r+   r,   	to_openaip   s   zBaseMessage.to_openaiopenai_messagec                 C   s   t d| j d)ziConverts the OpenAI message to the Mistral format.

        Should be implemented by subclasses.
        z'from_openai method not implemented for .)r8   r$   clsr=   r+   r+   r,   from_openaiw   s   zBaseMessage.from_openaiN)r$   r3   r4   r5   r   r.   r/   r0   r1   r2   __annotations__r   strr	   r   r   r<   classmethodrA   r+   r+   r+   r,   r6   g   s   
 :.r6   c                   @   s   e Zd ZU dZejZeej ed< e	e
ee f ed< dee
e	e
eee
e	e
ee
ef f f  f f fddZedee
e	e
eee
e	e
ee
ef f f  f f dd fdd	Zd
S )UserMessagezUser message.

    Attributes:
        content: The content of the message.

    Examples:
        >>> message = UserMessage(content="Can you help me to write a poem?")
    r7   contentr   c                 C   s2   t | jtr| j| jdS | jdd | jD dS )*Converts the message to the OpenAI format.r7   rF   c                 S      g | ]}|  qS r+   r<   .0chunkr+   r+   r,   
<listcomp>       z)UserMessage.to_openai.<locals>.<listcomp>)
isinstancerF   rC   r7   r:   r+   r+   r,   r<      s   zUserMessage.to_openair=   c                 C   s:   t |d tr| |S | |d dd |d D dS )2Converts the OpenAI message to the Mistral format.rF   r7   c                 S      g | ]}t |qS r+   r   rK   r+   r+   r,   rN      rO   z+UserMessage.from_openai.<locals>.<listcomp>rH   )rP   rC   model_validater?   r+   r+   r,   rA      s   
zUserMessage.from_openaiN)r$   r3   r4   r5   r.   r0   r7   r   rB   r	   rC   r   r   r   r   r<   rD   rA   r+   r+   r+   r,   rE      s   
 	:.rE   c                   @   s   e Zd ZU dZejZeej ed< e	e
ee	eef  f ed< dee
e	e
eee
e	e
ee
ef f f  f f fddZedee
e	e
eee
e	e
ee
ef f f  f f dd fdd	Zd
S )SystemMessagezSystem message.

    Attributes:
        content: The content of the message.

    Examples:
        >>> message = SystemMessage(content="You are a helpful assistant.")
    r7   rF   r   c                 C   s   |   S )rG   )
model_dumpr:   r+   r+   r,   r<      s   zSystemMessage.to_openair=   c                 C   s
   |  |S )rQ   )rT   r?   r+   r+   r,   rA      s   
zSystemMessage.from_openaiN)r$   r3   r4   r5   r.   r/   r7   r   rB   r	   rC   r   r   r   r   r   r<   rD   rA   r+   r+   r+   r,   rU      s   
 	:.rU   c                   @   s   e Zd ZU dZejZeej ed< dZ	e
eeeeeef  f  ed< dZe
ee  ed< dZeed< deeeeeeeeeeeef f f  f f fd	d
Zedeeeeeeeeeeeef f f  f f dd fddZdS )AssistantMessagea<  Assistant message.

    Attributes:
        role: The role of the message.
        content: The content of the message.
        tool_calls: The tool calls of the message.
        prefix: Whether the message is a prefix.

    Examples:
        >>> message = AssistantMessage(content="Hello, how can I help you?")
    r7   NrF   
tool_callsFprefixr   c                 C   sd   d| j i}| jdu rnt| jtr| j|d< n
dd | jD |d< | jdur0dd | jD |d< |S )rG   r7   NrF   c                 S   rI   r+   rJ   rK   r+   r+   r,   rN      rO   z.AssistantMessage.to_openai.<locals>.<listcomp>c                 S   rI   r+   rJ   )rL   Z	tool_callr+   r+   r,   rN      rO   rX   )r7   rF   rP   rC   rX   )r;   Zout_dictr+   r+   r,   r<      s   

zAssistantMessage.to_openair=   c                 C   s   | dd}|durdd |D nd}| dd}d}|du s$t|tr'|}nt|tr4dd |D }n	tdt| | |d ||d	S )
rQ   rX   Nc                 S   s   g | ]}t |qS r+   )r   rA   )rL   Zopenai_tool_callr+   r+   r,   rN      s    z0AssistantMessage.from_openai.<locals>.<listcomp>rF   c                 S   rR   r+   rS   rK   r+   r+   r,   rN      rO   zUnknown content type: r7   )r7   rF   rX   )getrP   rC   list
ValueErrorr9   rT   )r@   r=   Zopenai_tool_callsZtools_callsZopenai_contentrF   r+   r+   r,   rA      s(   
zAssistantMessage.from_openai)r$   r3   r4   r5   r.   r1   r7   r   rB   rF   r   r	   rC   r   r   r   rX   r   rY   boolr   r   r<   rD   rA   r+   r+   r+   r,   rW      s   
 $:.rW   c                   @   s"   e Zd ZU dZdZee ed< dS )FinetuningAssistantMessagezAssistant message for finetuning.

    Attributes:
        weight: The weight of the message to train on.

    Examples:
        >>> message = FinetuningAssistantMessage(content="Hello, how can I help you?", weight=0.5)
    Nweight)r$   r3   r4   r5   r_   r   floatrB   r+   r+   r+   r,   r^      s   
 	r^   c                   @   s   e Zd ZU dZeed< ejZe	ej ed< dZ
ee ed< dZee ed< deeeeeeeeeeeef f f  f f fdd	Zed
eeeeeeeeeeeef f f  f f dd fddZdS )ToolMessagea5  Tool message.

    Attributes:
        content: The content of the message.
        tool_call_id: The tool call id of the message.
        name: The name of the tool. (Deprecated in V3 tokenization)

    Examples:
       >>> message = ToolMessage(content="Hello, how can I help you?", tool_call_id="123")
    rF   r7   Ntool_call_idr   r   c                 C   s    | j dus	J d| jdhdS )rG   N0tool_call_id must be provided for tool messages.r   )exclude)rb   rV   r:   r+   r+   r,   r<     s   zToolMessage.to_openaimessagesc                 C   s    |  |}|jdusJ d|S )rQ   Nrc   )rT   rb   )r@   re   Ztool_messager+   r+   r,   rA   $  s   
zToolMessage.from_openai)r$   r3   r4   r5   rC   rB   r.   r2   r7   r   rb   r   r   r   r	   r   r   r<   rD   rA   r+   r+   r+   r,   ra     s   
 :Dra   r7   )ZdiscriminatorChatMessageType)boundUserMessageTypeAssistantMessageTypeToolMessageTypeSystemMessageTypeUATS).r&   enumr   typingr   r   r   r   r   r   r	   Zpydanticr
   Ztyping_extensionsr   r   Zmistral_common.baser   r%   r   r   r   r   r   Z+mistral_common.protocol.instruct.tool_callsr   filterwarningsr(   rC   r-   r.   r6   rE   rU   rW   r^   ra   ZChatMessageZFinetuningMessagerf   rh   ri   rj   rk   rl   rB   r+   r+   r+   r,   <module>   sB   
 $	9"B 