
    g#                    \   U 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Zd dlZd dlmZmZ ddlmZ e G d	 d
             Ze G d d             Z ej.                  e	 ej0                  d            Zded<   e G d d             Z ej.                  eej:                      ej0                  d            Ze G d d             Zeeeeeef    ej@                  d      f   Z!	 e G d d             Z"e G d d             Z#e G d d             Z$e G d d             Z%e G d d              Z&eee#e&f    ej@                  d      f   Z'	 e G d! d"             Z(ee"e(f   Z)	  ej.                  eee) ej@                  d#      f       ej0                  d            Z*y)$    )annotations)	dataclassfield)datetime)	AnnotatedAnyLiteralUnioncastN)Selfassert_never   )now_utcc                  <    e Zd ZU dZded<   	 dZded<   	 dZded	<   y)
SystemPromptPartzA system prompt, generally written by the application developer.

    This gives the model context and guidance on how to respond.
    strcontentN
str | Nonedynamic_refzsystem-promptzLiteral['system-prompt']	part_kind)__name__
__module____qualname____doc____annotations__r   r        I/var/www/openai/venv/lib/python3.12/site-packages/pydantic_ai/messages.pyr   r      s0    
 L$"K"
 +:I'9Rr   r   c                  J    e Zd ZU dZded<   	  ee      Zded<   	 dZded	<   y
)UserPromptPartzA user prompt, generally written by the end user.

    Content comes from the `user_prompt` parameter of [`Agent.run`][pydantic_ai.Agent.run],
    [`Agent.run_sync`][pydantic_ai.Agent.run_sync], and [`Agent.run_stream`][pydantic_ai.Agent.run_stream].
    r   r   default_factoryr   	timestampzuser-promptzLiteral['user-prompt']r   N)	r   r   r   r   r   r   _now_utcr#   r   r   r   r   r    r    "   s1     L$9Ix9&(5I%5Rr   r    T)defer_build)configzpydantic.TypeAdapter[Any]tool_return_tac                  x    e Zd ZU dZded<   	 ded<   	 dZded<   	  ee	      Zd
ed<   	 dZ	ded<   	 ddZ
ddZy)ToolReturnPartzAA tool return message, this encodes the result of running a tool.r   	tool_namer   r   Nr   tool_call_idr!   r   r#   ztool-returnzLiteral['tool-return']r   c                    t        | j                  t              r| j                  S t        j	                  | j                        j                         S N)
isinstancer   r   r'   	dump_jsondecodeselfs    r   model_response_strz!ToolReturnPart.model_response_strJ   s8    dllC(<<!++DLL9@@BBr   c                    t        | j                  t              r!t        j	                  | j                  d      S dt        j	                  | j                  d      iS )Njson)modereturn_value)r.   r   dictr'   dump_pythonr1   s    r   model_response_objectz$ToolReturnPart.model_response_objectP   sJ    dllD)!--dll-HH"N$>$>t||RX$>$YZZr   returnr   r<   dict[str, Any])r   r   r   r   r   r+   r   r$   r#   r   r3   r:   r   r   r   r)   r)   7   sN    KN,L#L*#V9Ix90(5I%5RC[r   r)   c                  t    e Zd ZU dZded<   	 dZded<   	 dZded<   	  ee      Z	d	ed
<   	 dZ
ded<   	 ddZy)RetryPromptParta  A message back to a model asking it to try again.

    This can be sent for a number of reasons:

    * Pydantic validation of tool arguments failed, here content is derived from a Pydantic
      [`ValidationError`][pydantic_core.ValidationError]
    * a tool raised a [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] exception
    * no tool was found for the tool name
    * the model returned plain text when a structured response was expected
    * Pydantic validation of a structured response failed, here content is derived from a Pydantic
      [`ValidationError`][pydantic_core.ValidationError]
    * a result validator raised a [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] exception
    z&list[pydantic_core.ErrorDetails] | strr   Nr   r*   r+   r!   r   r#   zretry-promptzLiteral['retry-prompt']r   c                    t        | j                  t              r| j                  }nMt        j	                  | j                  ddhid      }t        | j                         d|j                          }| dS )N__all__ctx   )excludeindentz validation errors: z

Fix the errors and try again.)r.   r   r   error_details_tar/   lenr0   )r2   descriptionjson_errorss      r   model_responsezRetryPromptPart.model_response~   sq    dllC(,,K*44T\\IX]W^K_hi4jK .//CKDVDVDXCYZK?@@r   r;   )r   r   r   r   r   r*   r+   r   r$   r#   r   rK   r   r   r   r@   r@   [   sV     43 !Iz 7#L*#V9Ix96)7I&7RAr   r@   r   c                  ,    e Zd ZU dZded<   	 dZded<   y)ModelRequestzkA request generated by PydanticAI and sent to a model, e.g. a message from the PydanticAI app to the model.zlist[ModelRequestPart]partsrequestzLiteral['request']kindN)r   r   r   r   r   rP   r   r   r   rM   rM      s    u!!((D
(Ur   rM   c                  ,    e Zd ZU dZded<   	 dZded<   y)TextPartz#A plain text response from a model.r   r   textzLiteral['text']r   N)r   r   r   r   r   r   r   r   r   rR   rR      s    -L+!'I'Rr   rR   c                      e Zd ZU dZded<   y)ArgsJsonz Tool arguments as a JSON string.r   	args_jsonNr   r   r   r   r   r   r   r   rU   rU      s    *N%r   rU   c                      e Zd ZU dZded<   y)ArgsDictz&Tool arguments as a Python dictionary.r>   	args_dictNrW   r   r   r   rY   rY      s    0+r   rY   c                  v    e Zd ZU dZded<   	 ded<   	 dZded<   	 d	Zd
ed<   	 eddd       ZddZ	ddZ
ddZy)ToolCallPartzA tool call from a model.r   r*   zArgsJson | ArgsDictargsNr   r+   z	tool-callzLiteral['tool-call']r   c                    t        |t              r | |t        |      |      S t        |t              r | |t	        |      |      S t        |       y)z+Create a `ToolCallPart` from raw arguments.N)r.   r   rU   r8   rY   r   )clsr*   r]   r+   s       r   from_raw_argszToolCallPart.from_raw_args   sF     dC y(4.,??d#y(4.,??r   c                   t        | j                  t              r| j                  j                  S t	        j
                  | j                  j                        }t        |t              sJ d       t        t        t        t        f   |      S )zReturn the arguments as a Python dictionary.

        This is just for convenience with models that require dicts as input.
        zargs should be a dict)r.   r]   rY   rZ   pydantic_core	from_jsonrV   r8   r   r   r   )r2   r]   s     r   args_as_dictzToolCallPart.args_as_dict   sg    
 dii*99&&&&&tyy':':;$%>'>>%DcND))r   c                    t        | j                  t              r| j                  j                  S t	        j
                  | j                  j                        j                         S )zReturn the arguments as a JSON string.

        This is just for convenience with models that require JSON strings as input.
        )r.   r]   rU   rV   rb   to_jsonrZ   r0   r1   s    r   args_as_json_strzToolCallPart.args_as_json_str   sF    
 dii*99&&&$$TYY%8%89@@BBr   c                    t        | j                  t              r-t        | j                  j                  j                               S t        | j                  j                        S r-   )r.   r]   rY   anyrZ   valuesboolrV   r1   s    r   has_contentzToolCallPart.has_content   sC    dii*tyy**11344		++,,r   r-   )r*   r   r]   zstr | dict[str, Any]r+   r   r<   r   r=   r;   )r<   rk   )r   r   r   r   r   r+   r   classmethodr`   rd   rg   rl   r   r   r   r\   r\      sW    #N'

  $L*#V&1I#1R 	*C-r   r\   c                  r    e Zd ZU dZded<   	  ee      Zded<   	 dZded	<   	 e	ddd       Z
e	dd       Zy
)ModelResponsezMA response from a model, e.g. a message from the model to the PydanticAI app.zlist[ModelResponsePart]rN   r!   r   r#   responsezLiteral['response']rP   Nc                B     | t        |      g|xs
 t                     S )N)r#   )rR   r$   )r_   r   r#   s      r   	from_textzModelResponse.from_text   s    HW%&)2IxzJJr   c                     | |g      S r-   r   )r_   	tool_calls     r   from_tool_callzModelResponse.from_tool_call  s    I;r   r-   )r   r   r#   zdatetime | Noner<   r   )rt   r\   r<   r   )r   r   r   r   r   r   r$   r#   rP   rm   rr   ru   r   r   r   ro   ro      sZ    W"")9Ix9
 !+D
*UK K    r   ro   rP   )+
__future__r   _annotationsdataclassesr   r   r   typingr   r   r	   r
   r   pydanticrb   typing_extensionsr   r   _utilsr   r$   r   r    TypeAdapter
ConfigDictr'   r   r)   listErrorDetailsrG   r@   DiscriminatorModelRequestPartrM   rR   rU   rY   r\   ModelResponsePartro   ModelMessageModelMessagesTypeAdapterr   r   r   <module>r      sQ   2 (  7 7   0 ' S S S& S S S" -AH,@,@M`XM`M`mqMr,s) s [ [ [@ (8'']-G-G(HQdQYQdQdquQvw  (A (A (AV 	
NNO
KLNdhNdNdepNqq  4 V V V S S S & & & , , , 4- 4- 4-n eHl$:;=SX=S=ST_=``a  )      0 \=01 1/8//<!7!7!7!??	@AJ](J]J]jnJo  `r   