o
    i                     @  s   d dl mZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZ ddl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 erXd dlmZ d dlmZ G dd deddZe	G dd deZ dS )    )annotations)AsyncIterator)asynccontextmanager)KW_ONLY	dataclass)TYPE_CHECKINGAnycast   )_mcp
exceptions)
RunContext)ModelMessageModelResponse)ModelSettings   )ModelModelRequestParametersStreamedResponse)ServerSession)ModelPreferencesc                   @  s   e Zd ZU dZded< dS )MCPSamplingModelSettingsz0Settings used for an MCP Sampling model request.r   mcp_model_preferencesN)__name__
__module____qualname____doc____annotations__ r   r   e/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/models/mcp_sampling.pyr      s   
 r   F)totalc                   @  sj   e Zd ZU dZded< 	 ded< dZded< 	 dddZe	dd ddZe	d!ddZ
e	d!ddZdS )"MCPSamplingModelzA model that uses MCP Sampling.

    [MCP Sampling](https://modelcontextprotocol.io/docs/concepts/sampling)
    allows an MCP server to make requests to a model by calling back to the MCP client that connected to it.
    r   sessionr   _i @  intdefault_max_tokensmessageslist[ModelMessage]model_settingsModelSettings | Nonemodel_request_parametersr   returnr   c              	     s   t |\}}| ||\}}tt|pi }| jj||d| j||d|d|ddI d H }|j	dkrEt
t |jg|jdS td|j	 d	)
N
max_tokenstemperaturer   stop_sequences)r,   system_promptr-   model_preferencesr.   	assistant)parts
model_namezDUnexpected result from MCP sampling, expected "assistant" role, got .)r   map_from_pai_messagesprepare_requestr	   r   r"   create_messagegetr%   roler   map_from_sampling_contentcontentmodelr   UnexpectedModelBehavior)selfr&   r(   r*   r/   sampling_messagesr#   resultr   r   r   request0   s(   
zMCPSamplingModel.requestNrun_contextRunContext[Any] | NoneAsyncIterator[StreamedResponse]c                 C s
   t d)Nz'MCP Sampling does not support streaming)NotImplementedError)r>   r&   r(   r*   rB   r   r   r   request_streamM   s   zMCPSamplingModel.request_streamstrc                 C     dS )zThe model name.

        Since the model name isn't known until the request is made, this property always returns `'mcp-sampling'`.
        zmcp-samplingr   r>   r   r   r   r3   X   s   zMCPSamplingModel.model_namec                 C  rH   )z-The system / model provider, returns `'MCP'`.MCPr   rI   r   r   r   system`   s   zMCPSamplingModel.system)r&   r'   r(   r)   r*   r   r+   r   )N)
r&   r'   r(   r)   r*   r   rB   rC   r+   rD   )r+   rG   )r   r   r   r   r   r%   rA   r   rF   propertyr3   rK   r   r   r   r   r!      s   
 

r!   N)!
__future__r   _annotationscollections.abcr   
contextlibr   dataclassesr   r   typingr   r   r	    r   r   _run_contextr   r&   r   r   settingsr   r   r   r   mcpr   	mcp.typesr   r   r!   r   r   r   r   <module>   s     	