
    Zi                     F   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SKJ
r
  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJrJr  S SKrS SKJr  S SKJr  \R>                  S:  a	  S S	KJ r J!r!  OS S	K"J r J!r!  S S
K#J$r$   \$RJ                  " S5      r&S SK(r(S SK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErE  \" S5      rF " S S\ R                  \ R                  5      rISrJ " S S\I5      rK " S S\I5      rLS\\\\5\4         S\!\5   4S jrMS\\\\\N\4   \74         S\!\7   4S jrOS!S\\\\\N\4   \A\4         S\!\A   4S jjrPS\\\N\
4      S\\S4   4S jrQS\\N   S\N4S  jrRg! \$RN                   a    Sr& GN
f = f)"    N)sha256)PathLike)Path)AnyCallableDictListLiteralMappingOptionalSequenceTypeTypeVarUnionoverload)JsonSchemaValue)convert_function_to_tool)   	   )AsyncIteratorIterator)metadataollamaz0.0.0)ChatRequestChatResponseCopyRequestCreateRequestDeleteRequestEmbeddingsRequestEmbeddingsResponseEmbedRequestEmbedResponseGenerateRequestGenerateResponseImageListResponseMessageOptionsProcessResponseProgressResponsePullRequestPushRequestResponseErrorShowRequestShowResponseStatusResponseToolWebFetchRequestWebFetchResponseWebSearchRequestWebSearchResponseTc                   f    \ rS rSr SSSSS.S\\   S\S\S\\\\4      S	S4
S
 jjjr	S r
S rSrg)
BaseClientO   NT)follow_redirectstimeoutheadershostr:   r;   r<   returnc                8   0 U=(       d    0 ESSS[          S[        R                  " 5        S[        R                  " 5       R	                  5        S[        R
                  " 5        3S.ER                  5        VVs0 s H  u  pxUc  M
  UR	                  5       U_M     nnn[        R                  " SS5      n	UR                  S	5      (       d  U	(       a  S
U	 3US	'   U" S[        U=(       d    [        R                  " S5      5      UUUS.UD6U l        gs  snnf )z
Creates a httpx client. Default parameters are the same as those defined in httpx
except for the following:
- `follow_redirects`: True
- `timeout`: None
`kwargs` are passed to the httpx client.
zapplication/jsonzollama-python/z ( z	) Python/)zContent-TypeAcceptz
User-AgentNOLLAMA_API_KEYauthorizationBearer OLLAMA_HOST)base_urlr:   r;   r<    )__version__platformmachinesystemlowerpython_versionitemsosgetenvget_parse_host_client)
selfclientr=   r:   r;   r<   kwargskvapi_keys
             h/var/www/eduai.edurigo.com/question_generate/ques_gen_env/lib/python3.13/site-packages/ollama/_client.py__init__BaseClient.__init__P   s*   (=b*$&{m2h6F6F6H5I8??K\KbKbKdJeenow  pG  pG  pI  oJ  K	
 		$! 
 aggil  	 ii($/G;;''G#*7)!4go 4;299]#;<'	
 	DL	s   <	D	Dc                 $    U R                  5         g NcloserT   exc_typeexc_valexc_tbs       rZ   __exit__BaseClient.__exit__x   s    JJL    c                 @   #    U R                  5       I S h  vN   g  N7fr^   r_   ra   s       rZ   	__aexit__BaseClient.__aexit__{   s     
**,s   )rS   r^   )__name__
__module____qualname____firstlineno__r   strboolr   r   r[   re   ri   __static_attributes__rG   rg   rZ   r8   r8   O   sk     &
 "+/& 3-&
 & & gc3h'(& &Prg   r8   zxFailed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/downloadc            +       N  ^  \ rS rSrSTS\\   SS4U 4S jjjrS rS r\	SS	.S
\
\   S\S   S\4S jj5       r\	SS	.S
\
\   S\S   S\\   4S jj5       r\	SS	.S
\
\   S\S\\\\   4   4S jj5       rSS	.S
\
\   S\S\\\\   4   4S jjr\	   SUSSSSSSSSSSSSSSSS.S\S\S\S\S\S\\\      S\S   S\\   S\\   S\\   S\S\\\S   \4      S\\\\\\4         S \\\\\4   \4      S!\\\\4      S"\\   S#\\   S$\\   S\4&S% jjj5       r\	   SUSSSSSSSSSSSSSSSS.S\S\S\S\S\S\\\      S\S   S\\   S\\   S\\   S\S\\\S   \4      S\\\\\\4         S \\\\\4   \4      S!\\\\4      S"\\   S#\\   S$\\   S\\   4&S& jjj5       r   SVSSSSSSSSSSSSSSSS.S\S\\   S\\   S\\   S\\   S\\\      S\S\\   S\\   S\\   S\\   S\\\S   \4      S\\\\\\4         S \\\\\4   \4      S!\\\\4      S"\\   S#\\   S$\\   S\\\\   4   4&S' jjjr\	  SWSSSSSSSSS(.S\S)\\\\\\4   \4         S*\\\\\\4   \\4         S\S   S\\\\S+   4      S\\   S\\   S\\\S   \4      S \\\\\4   \4      S!\\\\4      S\4S, jjj5       r \	  SWSSSSSSSSS(.S\S)\\\\\\4   \4         S*\\\\\\4   \\4         S\S   S\\\\S+   4      S\\   S\\   S\\\S   \4      S \\\\\4   \4      S!\\\\4      S\\   4S- jjj5       r   SWSSSSSSSSS(.S\S)\\\\\\4   \4         S*\\\\\\4   \\4         S\S\\\\S+   4      S\\   S\\   S\\\S   \4      S \\\\\4   \4      S!\\\\4      S\\\\   4   4S. jjjr       SXS\S/\\\\   4   S0\\   S \\\\\4   \4      S!\\\\4      S1\\   S\!4S2 jjr"    SYS\S\\   S \\\\\4   \4      S!\\\\4      S\#4
S3 jjr$\	SSS4.S\S5\S\S   S\%4S6 jj5       r&\	SSS4.S\S5\S\S   S\\%   4S7 jj5       r&SSS4.S\S5\S\S\\%\\%   4   4S8 jjr&\	SSS4.S\S5\S\S   S\%4S9 jj5       r'\	SSS4.S\S5\S\S   S\\%   4S: jj5       r'SSS4.S\S5\S\S\\%\\%   4   4S; jjr'\	         SZSS	.S\S<\\   S=\\   S>\\(\\4      S?\\(\\4      S\\   S@\\\\)\   4      S\\   SA\\\\\4   \4      S)\\\\\\4   \4         S\S   S\%4SB jjj5       r*\	         SZSS	.S\S<\\   S=\\   S>\\(\\4      S?\\(\\4      S\\   S@\\\\)\   4      S\\   SA\\\\\4   \4      S)\\\\\\4   \4         S\S   S\\%   4SC jjj5       r*         SZSS	.S\S<\\   S=\\   S>\\(\\4      S?\\(\\4      S\\   S@\\\\)\   4      S\\   SA\\\\\4   \4      S)\\\\\\4   \4         S\S\\%\\%   4   4SD jjjr*SE\\\+4   S\4SF jr,S\-4SG jr.S\S\/4SH jr0SI\SJ\S\/4SK jr1S\S\24SL jr3S\44SM jr5S[SN\SO\S\64SP jjr7SQ\S\84SR jr9SSr:U =r;$ )\Client   Nr=   r>   c                 F   > [         TU ]  " [        R                  U40 UD6  g r^   )superr[   httpxrs   rT   r=   rV   	__class__s      rZ   r[   Client.__init__   s    	GU\\4262rg   c                 8    U R                   R                  5         g r^   )rS   r`   rT   s    rZ   r`   Client.close   s    LLrg   c                 H    U R                   R                  " U0 UD6nUR                  5         U$ ! [        R                   a:  n[        UR                  R                  UR                  R                  5      S eS nAf[        R                   a    [        [        5      S ef = fr^   rS   requestraise_for_statusrw   HTTPStatusErrorr-   responsetextstatus_codeConnectErrorConnectionErrorCONNECTION_ERROR_MESSAGErT   argsrV   res        rZ   _request_rawClient._request_raw   s    @
,,


/
/ah   M!**//1::+A+ABL @454?@s   -0 B!5A99(B!Fstreamclsr   c                    g r^   rG   rT   r   r   r   rV   s        rZ   _requestClient._request   s     rg   Tc                    g r^   rG   r   s        rZ   r   r      s     rg   c                    g r^   rG   r   s        rZ   r   r      s     "rg   c          	         ^ ^^^ U(       a  UUUU 4S jnU" 5       $ T" S0 T R                   " T0 TD6R                  5       D6$ )Nc               3   &  >#    TR                   R                  " T0 TD6 n  U R                  5         U R                  5        HF  n[        R                  " U5      nUR                  S5      =n(       a  [        U5      eT" S0 UD6v   MH     S S S 5        g ! [        R                   aT  nUR
                  R                  5         [        UR
                  R                  UR
                  R                  5      S eS nAff = f! , (       d  f       g = f7fNerrorrG   )rS   r   r   rw   r   r   readr-   r   r   
iter_linesjsonloadsrQ   	r   r   lineparterrr   r   rV   rT   s	        rZ   innerClient._request.<locals>.inner   s     \\  $1&1QS 
 llnd::d#Dhhw''s'!#&&++	 % 21 && SJJOO

1G1GHdRS 21s@   DD BAD 	DC=)AC88C==D  
D
DrG   r   r   rT   r   r   r   rV   r   s   `` `` rZ   r   r      sB       Wn;""D3F388:;;rg    rK   templatecontextr   thinklogprobstop_logprobsrawformatimagesoptions
keep_alivewidthheightstepsmodelpromptsuffixrK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                    g r^   rG   rT   r   r   r   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                      rZ   generateClient.generate   s    , rg   c                    g r^   rG   r   s                      rZ   r   r      s    , $'rg   c                    U R                  [        SS[        S0 SU_SU_SU_SU_SU_SU_S	U_S
U_SU	_SU
_SU_SU_SU(       a  [        [	        U5      5      OS_SU_SU_SU_SU_SU_6R                  SS9US9$ )a  
Create a response using the requested model.

Raises `RequestError` if a model is not provided.

Raises `ResponseError` if the request could not be fulfilled.

Returns `GenerateResponse` if `stream` is `False`, otherwise returns a `GenerateResponse` generator.
POST/api/generater   r   r   rK   r   r   r   r   r   r   r   r   r   Nr   r   r   r   r   Texclude_noner   r   rG   r   r$   r#   list_copy_images
model_dumpr   s                      rZ   r   r      s    @ ==   	
      "   .4tL()    !" #$ %& 	

%1   rg   toolsr   r   r   r   r   r   r   messagesr   lowmediumhighc                    g r^   rG   rT   r   r   r   r   r   r   r   r   r   r   s              rZ   chatClient.chat4  s     rg   c                    g r^   rG   r   s              rZ   r   r   D  s      #rg   c                    U R                  [        SS[        U[        [	        U5      5      [        [        U5      5      UUUUUU	U
S9
R                  SS9US9$ )a  
Create a chat response using the requested model.

Args:
  tools:
    A JSON schema as a dict, an Ollama Tool or a Python Function.
    Python functions need to follow Google style docstrings to be converted to an Ollama Tool.
    For more information, see: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
  stream: Whether to stream the response.
  format: The format of the response.

Example:
  def add_two_numbers(a: int, b: int) -> int:
    '''
    Add two numbers together.

    Args:
      a: First number to add
      b: Second number to add

    Returns:
      int: The sum of a and b
    '''
    return a + b

  client.chat(model='llama3.2', tools=[add_two_numbers], messages=[...])

Raises `RequestError` if a model is not provided.

Raises `ResponseError` if the request could not be fulfilled.

Returns `ChatResponse` if `stream` is `False`, otherwise returns a `ChatResponse` generator.
r   	/api/chat
r   r   r   r   r   r   r   r   r   r   Tr   r   r   r   r   r   _copy_messages_copy_toolsr   r   s              rZ   r   r   T  so    ^ ==nX./;u%&! 	

%!   rg   inputtruncate
dimensionsc                 `    U R                  [        SS[        UUUUUUS9R                  SS9S9$ Nr   z
/api/embed)r   r   r   r   r   r   Tr   r   r   r"   r!   r   rT   r   r   r   r   r   r   s          rZ   embedClient.embed  sK     == 	

%   rg   c                 \    U R                  [        SS[        UUUUS9R                  SS9S9$ )!
Deprecated in favor of `embed`.
r   /api/embeddingsr   r   r   r   Tr   r   r   r    r   r   rT   r   r   r   r   s        rZ   
embeddingsClient.embeddings  sE     ==	
 	

%  
 
rg   insecurer   r   c                    g r^   rG   rT   r   r   r   s       rZ   pullClient.pull       rg   c                    g r^   rG   r   s       rZ   r   r          $'rg   c                \    U R                  [        SS[        UUUS9R                  SS9US9$ )
Raises `ResponseError` if the request could not be fulfilled.

Returns `ProgressResponse` if `stream` is `False`, otherwise returns a `ProgressResponse` generator.
r   	/api/pullr   r   r   Tr   r   r   r*   r+   r   r   s       rZ   r   r     E     == 	

%  
 
rg   c                    g r^   rG   r   s       rZ   pushClient.push  r   rg   c                    g r^   rG   r   s       rZ   r   r     r   rg   c                \    U R                  [        SS[        UUUS9R                  SS9US9$ )r   r   	/api/pushr   Tr   r   r   r*   r,   r   r   s       rZ   r   r     r   rg   quantizefrom_filesadapterslicense
parametersc                    g r^   rG   rT   r   r  r  r  r  r   r  rK   r	  r   r   s               rZ   createClient.create  s     rg   c                    g r^   rG   r  s               rZ   r  r  (  s     $'rg   c                l    U R                  [        SS[        UUUUUUUUUU	U
S9R                  SS9US9$ )r   r   /api/creater   r   r  r  r  r  r  r   rK   r	  r   Tr   r   r   r*   r   r   r  s               rZ   r  r  9  s]    ( == 	

%#   rg   pathc                 \   [        5       n[        US5       n UR                  S5      nU(       d  OUR                  U5        M,  S S S 5        SUR	                  5        3n[        US5       nU R                  SSU 3US9  S S S 5        U$ ! , (       d  f       NL= f! , (       d  f       U$ = f)Nrb   sha256:r   /api/blobs/content)r   openr   update	hexdigestr   )rT   r  	sha256sumr   chunkdigests         rZ   create_blobClient.create_bloba  s    I	dD	Qy!
	  
 y**,-.F	dD	Q
+fX 6B 
 M 
	 
	 Ms   .B,B
B
B+c                 0    U R                  [        SS5      $ NGETz	/api/tagsr   r&   r|   s    rZ   r   Client.listq  s    == rg   c                     U R                  SS[        US9R                  SS9S9n[        UR                  S:X  a  SS
9$ S	S
9$ NDELETEz/api/deleter   Tr   r      successr   statusr   r   r   r0   r   rT   r   r   s      rZ   deleteClient.deletex  s^    

% 	 	A --3.Y 4; rg   sourcedestinationc           	          U R                  SS[        UUS9R                  SS9S9n[        UR                  S:X  a  SS
9$ S	S
9$ Nr   z	/api/copy)r4  r5  Tr   r   r,  r-  r   r.  r   r   r   r0   r   rT   r4  r5  r   s       rZ   copyClient.copy  sc     	

% 	 	A --3.Y 4; rg   c           	      V    U R                  [        SS[        US9R                  SS9S9$ Nr   z	/api/showr+  Tr   r   r   r/   r.   r   rT   r   s     rZ   showClient.show  s8    ==

%   rg   c                 0    U R                  [        SS5      $ Nr%  z/api/psr   r)   r|   s    rZ   ps	Client.ps  s    == rg   querymax_resultsc           
          U R                   R                  R                  SS5      R                  S5      (       d  [	        S5      eU R                  [        SS[        UUS9R                  SS	9S
9$ )a  
Performs a web search

Args:
  query: The query to search for
  max_results: The maximum number of results to return (default: 3)

Returns:
  WebSearchResponse with the search results
Raises:
  ValueError: If OLLAMA_API_KEY environment variable is not set
rC   r   rD   zAAuthorization header with Bearer token is required for web searchr   !https://ollama.com/api/web_searchrG  rH  Tr   r   )	rS   r<   rQ   
startswith
ValueErrorr   r5   r4   r   rT   rG  rH  s      rZ   
web_searchClient.web_search  ss     <<##OR8CCINNZ[[==) 	

%   rg   urlc           	          U R                   R                  R                  SS5      R                  S5      (       d  [	        S5      eU R                  [        SS[        US9R                  SS	9S
9$ )
Fetches the content of a web page for the provided URL.

Args:
  url: The URL to fetch

Returns:
  WebFetchResponse with the fetched result
rC   r   rD   z@Authorization header with Bearer token is required for web fetchr    https://ollama.com/api/web_fetchrQ  Tr   r   )	rS   r<   rQ   rL  rM  r   r3   r2   r   rT   rQ  s     rZ   	web_fetchClient.web_fetch  sn     <<##OR8CCINNYZZ==(

%   rg   rG   r^   r   r   r   r   NNr   Nr   r   NNNNr   NNN	NNNNNNNNNr   )<rk   rl   rm   rn   r   ro   r[   r`   r   r   r   r6   r
   r   r   rp   r   r   intr   bytesr%   r   r   r(   floatr$   r   r'   r1   r   r   r   r"   r   r    r   r*   r   r   r   r	   r  r   r!  r&   r   r0   r2  r:  r/   r@  r)   rE  r5   rO  r3   rW  rq   __classcell__ry   s   @rZ   rs   rs      sj   38C= 3d 3 3@ 
 #		a EN	 	  
 !		a DM	 {  
 	"	a" 	" Q^" " 	<	a< 	< Q^<6  	 '+" #"&DH;?;?.2 )  	   hsm$ EN D> tn 3- 
 U7:.?@A XeC$5678  eGCH-w678!" ucz*+#$ C=%& SM'( C=)* + .  	' '+  #"&DH;?;?.2 )'' ' 	' ' ' hsm$' DM' D>' tn' 3-' 
' U7:.?@A' XeC$5678'  eGCH-w678!'" ucz*+#'$ C=%'& SM''( C=)'*  !+' '2   	9 !"'+ #"&DH;?;?.2 )99 SM9 SM	9 SM9 sm9 hsm$9 9 D>9 tn9 3-9 
$9 U7:.?@A9 XeC$56789  eGCH-w678!9" ucz*+#9$ C=%9& SM'9( C=)9* x(899:+9v  FJ
 KO"EI#"&DH;?.2 xgc3h&7&@ ABC
 HU738#4dH#DEFG EN E$(? @@AB tn 3- U7:.?@A eGCH-w678 ucz*+    FJ#
 KO EI#"&DH;?.2## xgc3h&7&@ ABC#
 HU738#4dH#DEFG# DM# E$(? @@AB# tn# 3-# U7:.?@A# eGCH-w678# ucz*+# # #" FJ@
 KOEI#"&DH;?.2@@ xgc3h&7&@ ABC@
 HU738#4dH#DEFG@ @ E$(? @@AB@ tn@ 3-@ U7:.?@A@ eGCH-w678@ ucz*+@ \8L112@H ')#;?.2 $ hsm#$ tn	
 eGCH-w678 ucz*+  2  ;?.2 SM eGCH-w678	
 ucz*+ , 
 " 	
 EN   
  '' 	'
 DM'  !' '  	
  x(899:0 
 " 	
 EN   
  '' 	'
 DM'  !' '  	
  x(899:0  #&*)-"/3 >BFJ # sm C=	
 DcN# tCH~& sm eCcN+, SM wsCx0'9:; xgc3h&7&@ ABC EN     #&*)-"/3 >BFJ' !'' sm' C=	'
 DcN#' tCH~&' sm' eCcN+,' SM' wsCx0'9:;' xgc3h&7&@ ABC' DM'  !' '& #&*)-"/3 >BFJ& && sm& C=	&
 DcN#& tCH~&& sm& eCcN+,& SM& wsCx0'9:;& xgc3h&7&@ ABC& & x(899:&PeCI. 3  L 
# 
. 
 3 >   / c  <M 43 #3  rg   rs   c            +       ~  ^  \ rS rSrSTS\\   SS4U 4S jjjrS rS r\	SS	.S
\
\   S\S   S\4S jj5       r\	SS	.S
\
\   S\S   S\\   4S jj5       r\	SS	.S
\
\   S\S\\\\   4   4S jj5       rSS	.S
\
\   S\S\\\\   4   4S jjrSUS\S\S\4S jjrS\S\4S jr\	   SVSSSSSSSSSSSSSSSS.S\S\S\S\S\S\\\      S\S   S\\\\S   4      S \\   S!\\   S"\S#\\\S$   \4      S%\\\\\\4         S&\\\\\4   \4      S'\\\\4      S(\\   S)\\   S*\\   S\4&S+ jjj5       r\	   SVSSSSSSSSSSSSSSSS.S\S\S\S\S\S\\\      S\S   S\\\\S   4      S \\   S!\\   S"\S#\\\S$   \4      S%\\\\\\4         S&\\\\\4   \4      S'\\\\4      S(\\   S)\\   S*\\   S\\   4&S, jjj5       r   SWSSSSSSSSSSSSSSSS.S\S\\   S\\   S\\   S\\   S\\\      S\S\\\\S   4      S \\   S!\\   S"\\   S#\\\S$   \4      S%\\\\\\4         S&\\\\\4   \4      S'\\\\4      S(\\   S)\\   S*\\   S\\\\   4   4&S- jjjr\	  SXSSSSSSSSS..S\S/\\\\\\4   \ 4         S0\\\\\\4   \!\"4         S\S   S\\\\S   4      S \\   S!\\   S#\\\S$   \4      S&\\\\\4   \4      S'\\\\4      S\#4S1 jjj5       r$\	  SXSSSSSSSSS..S\S/\\\\\\4   \ 4         S0\\\\\\4   \!\"4         S\S   S\\\\S   4      S \\   S!\\   S#\\\S$   \4      S&\\\\\4   \4      S'\\\\4      S\\#   4S2 jjj5       r$  SXSSSSSSSSS..S\S/\\\\\\4   \ 4         S0\\\\\\4   \!\"4         S\S\\\\S   4      S \\   S!\\   S#\\\S$   \4      S&\\\\\4   \4      S'\\\\4      S\\#\\#   4   4S3 jjjr$      SYS\S4\\\\   4   S5\\   S&\\\\\4   \4      S'\\\\4      S6\\   S\%4S7 jjr&    SZS\S\\   S&\\\\\4   \4      S'\\\\4      S\'4
S8 jjr(\	SSS9.S\S:\S\S   S\)4S; jj5       r*\	SSS9.S\S:\S\S   S\\)   4S< jj5       r*SSS9.S\S:\S\S\\)\\)   4   4S= jjr*\	SSS9.S\S:\S\S   S\)4S> jj5       r+\	SSS9.S\S:\S\S   S\\)   4S? jj5       r+SSS9.S\S:\S\S\\)\\)   4   4S@ jjr+\	         S[SS	.S\SA\\   SB\\   SC\\,\\4      SD\\,\\4      S\\   SE\\\\-\   4      S\\   SF\\\\\4   \4      S/\\\\\\4   \ 4         S\S   S\)4SG jjj5       r.\	         S[SS	.S\SA\\   SB\\   SC\\,\\4      SD\\,\\4      S\\   SE\\\\-\   4      S\\   SF\\\\\4   \4      S/\\\\\\4   \ 4         S\S   S\\)   4SH jjj5       r.         S[SS	.S\SA\\   SB\\   SC\\,\\4      SD\\,\\4      S\\   SE\\\\-\   4      S\\   SF\\\\\4   \4      S/\\\\\\4   \ 4         S\S\\)\\)   4   4SI jjjr.SJ\\\/4   S\4SK jr0S\14SL jr2S\S\34SM jr4SN\SO\S\34SP jr5S\S\64SQ jr7S\84SR jr9SSr:U =r;$ )\AsyncClienti  Nr=   r>   c                 F   > [         TU ]  " [        R                  U40 UD6  g r^   )rv   r[   rw   rf  rx   s      rZ   r[   AsyncClient.__init__  s    	GU&&77rg   c                 T   #    U R                   R                  5       I S h  vN   g  N7fr^   )rS   acloser|   s    rZ   r`   AsyncClient.close  s     
,,


s   (&(c                 d  #     U R                   R                  " U0 UD6I S h  vN nUR                  5         U$  N! [        R                   a:  n[        UR                  R                  UR                  R                  5      S eS nAf[        R                   a    [        [        5      S ef = f7fr^   r   r   s        rZ   r   AsyncClient._request_raw  s     @$$d5f5
5ah 6    M!**//1::+A+ABL @454?@s1   B0< :< B0< B-5B(B--B0Fr   r   r   c                   #    g 7fr^   rG   r   s        rZ   r   AsyncClient._request  s
         Tc                   #    g 7fr^   rG   r   s        rZ   r   ro    
      rp  c                   #    g 7fr^   rG   r   s        rZ   r   ro    s
      $'rp  c          	         ^ ^^^#    U(       a  UUUU 4S jnU" 5       $ T" S0 T R                   " T0 TD6I S h  vN R                  5       D6$  N7f)Nc                   >#    TR                   R                  " T0 TD6 IS h  vN n  U R                  5         U R                  5         S h  vN n[        R                  " U5      nUR                  S5      =n(       a  [        U5      eT" S0 UD67v   MO   Nt! [        R                   a]  nUR
                  R                  5       I S h  vN    [        UR
                  R                  UR
                  R                  5      S eS nAff = f N
 S S S 5      IS h  vN    g ! , IS h  vN  (       d  f       g = f7fr   )rS   r   r   rw   r   r   areadr-   r   r   aiter_linesr   r   rQ   r   s	        rZ   r   #AsyncClient._request.<locals>.inner  s     <<&&7771S 
 MMO D::d#Dhhw''s'!#&&++ 8 && S**""$$$

1G1GHdRSO 877777s   !D>BD>D$BD$
DDDAD$D>D/DC:DDD$DD$D>D D>$D;*D-+D;7D>rG   r   r   s   `` `` rZ   r   ro    sK        WnC))4:6::@@BCC:s   1AAArG  rH  c           
      t   #    U R                  [        SS[        UUS9R                  SS9S9I Sh  vN $  N7f)z
Performs a web search

Args:
  query: The query to search for
  max_results: The maximum number of results to return (default: 3)

Returns:
  WebSearchResponse with the search results
r   rJ  rK  Tr   r   N)r   r5   r4   r   rN  s      rZ   rO  AsyncClient.web_search  sL      ) 	

%     s   /868rQ  c           	      r   #    U R                  [        SS[        US9R                  SS9S9I Sh  vN $  N7f)rS  r   rT  rU  Tr   r   N)r   r3   r2   r   rV  s     rZ   rW  AsyncClient.web_fetch/  sG      (

%        .757r   r   r   r   r   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                   #    g 7fr^   rG   r   s                      rZ   r   AsyncClient.generateB  s
     , rp  c                   #    g 7fr^   rG   r   s                      rZ   r   r  Z  s
     , ),rp  c                  #    U R                  [        SS[        S0 SU_SU_SU_SU_SU_SU_S	U_S
U_SU	_SU
_SU_SU_SU(       a  [        [	        U5      5      OS_SU_SU_SU_SU_SU_6R                  SS9US9I Sh  vN $  N7f)a  
Create a response using the requested model.

Raises `RequestError` if a model is not provided.

Raises `ResponseError` if the request could not be fulfilled.

Returns `GenerateResponse` if `stream` is `False`, otherwise returns an asynchronous `GenerateResponse` generator.
r   r   r   r   r   rK   r   r   r   r   r   r   r   r   r   Nr   r   r   r   r   Tr   r   rG   r   r   s                      rZ   r   r  r  s    >    	
      "   .4tL()    !" #$ %& 	

%1     s   B B	BB	r   r   r   c                   #    g 7fr^   rG   r   s              rZ   r   AsyncClient.chat  s
      rp  c                   #    g 7fr^   rG   r   s              rZ   r   r    s
      %(rp  c                   #    U R                  [        SS[        U[        [	        U5      5      [        [        U5      5      UUUUUU	U
S9
R                  SS9US9I Sh  vN $  N7f)a  
Create a chat response using the requested model.

Args:
  tools:
    A JSON schema as a dict, an Ollama Tool or a Python Function.
    Python functions need to follow Google style docstrings to be converted to an Ollama Tool.
    For more information, see: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
  stream: Whether to stream the response.
  format: The format of the response.

Example:
  def add_two_numbers(a: int, b: int) -> int:
    '''
    Add two numbers together.

    Args:
      a: First number to add
      b: Second number to add

    Returns:
      int: The sum of a and b
    '''
    return a + b

  await client.chat(model='llama3.2', tools=[add_two_numbers], messages=[...])

Raises `RequestError` if a model is not provided.

Raises `ResponseError` if the request could not be fulfilled.

Returns `ChatResponse` if `stream` is `False`, otherwise returns an asynchronous `ChatResponse` generator.
r   r   r   Tr   r   Nr   r   s              rZ   r   r    s|     ` nX./;u%&! 	

%!     s   AA%A#A%r   r   r   c                 |   #    U R                  [        SS[        UUUUUUS9R                  SS9S9I S h  vN $  N7fr   r   r   s          rZ   r   AsyncClient.embed  sX       	

%     s   3<:<c                 x   #    U R                  [        SS[        UUUUS9R                  SS9S9I Sh  vN $  N7f)r   r   r   r   Tr   r   Nr   r   s        rZ   r   AsyncClient.embeddings&  sR      	
 	

%  
 
 
 
   1:8:r   r   c                   #    g 7fr^   rG   r   s       rZ   r   AsyncClient.pull<  rr  rp  c                   #    g 7fr^   rG   r   s       rZ   r   r  E  
      ),rp  c                x   #    U R                  [        SS[        UUUS9R                  SS9US9I Sh  vN $  N7f)r   r   r   r   Tr   r   Nr   r   s       rZ   r   r  N  R       	

%  
 
 
 
r  c                   #    g 7fr^   rG   r   s       rZ   r   AsyncClient.pushf  rr  rp  c                   #    g 7fr^   rG   r   s       rZ   r   r  o  r  rp  c                x   #    U R                  [        SS[        UUUS9R                  SS9US9I Sh  vN $  N7f)r   r   r  r   Tr   r   Nr  r   s       rZ   r   r  x  r  r  r  r  r  r  r  r	  c                   #    g 7fr^   rG   r  s               rZ   r  AsyncClient.create  s
      rp  c                   #    g 7fr^   rG   r  s               rZ   r  r    s
      ),rp  c                   #    U R                  [        SS[        UUUUUUUUUU	U
S9R                  SS9US9I Sh  vN $  N7f)r   r   r  r  Tr   r   Nr  r  s               rZ   r  r    sj     *  	

%#     s   9AA Ar  c                   ^#    [        5       n[        R                  " TS5      I S h  vN  IS h  vN n UR                  S5      I S h  vN nU(       d  OUR	                  U5        M4  S S S 5      IS h  vN   SUR                  5        3nU4S jnU R                  SSU 3U" 5       S9I S h  vN   U$  N N No NF! , IS h  vN  (       d  f       N[= f N(7f)Nr  r  r  c                   >#    [         R                  " TS5      I S h  vN  IS h  vN n  U R                  S5      I S h  vN nU(       d  OU7v   M(  S S S 5      IS h  vN   g  NG N@ N( N! , IS h  vN  (       d  f       g = f7f)Nr  r  )anyio	open_filer   )r   r  r  s     rZ   upload_bytes-AsyncClient.create_blob.<locals>.upload_bytes  s_     tT2222ay))%+	  322) 3222sf   BA&BA(BA.A*A.B A,!B(B*A.,B.B4A75BBr   r  r  )r   r  r  r   r  r  r   )rT   r  r  r   r  r   r  s    `     rZ   r!  AsyncClient.create_blob  s     I__T40000AffY''
	  10 y**,-.F 

Fk&$:LN

SSSM' 1' 1000" Tsr   %CB7CB9CB?B;B?+C6B=79C0C1C9C;B?=C?CCCCc                 L   #    U R                  [        SS5      I S h  vN $  N7fr$  r&  r|   s    rZ   r   AsyncClient.list  s)           $"$c                    #    U R                  SS[        US9R                  SS9S9I S h  vN n[        UR                  S:X  a  SS
9$ S	S
9$  N!7fr)  r0  r1  s      rZ   r2  AsyncClient.delete  sk     

%    	A --3.Y 4; 	s   )AA"Ar4  r5  c           	         #    U R                  SS[        UUS9R                  SS9S9I S h  vN n[        UR                  S:X  a  SS
9$ S	S
9$  N!7fr7  r8  r9  s       rZ   r:  AsyncClient.copy  sp      	

%    	A --3.Y 4; 	s   *AA"Ac           	      r   #    U R                  [        SS[        US9R                  SS9S9I S h  vN $  N7fr=  r>  r?  s     rZ   r@  AsyncClient.show  sE     

%     r}  c                 L   #    U R                  [        SS5      I S h  vN $  N7frC  rD  r|   s    rZ   rE  AsyncClient.ps  s)        r  rG   r^   r_  rY  rZ  r[  r\  r]  r^  )<rk   rl   rm   rn   r   ro   r[   r`   r   r   r   r6   r
   r   r   rp   r   r`  r5   rO  r3   rW  r   r   ra  r%   r   r   r(   rb  r$   r   r'   r1   r   r   r   r"   r   r    r   r*   r   r   r   r	   r  r   r!  r&   r   r0   r2  r:  r/   r@  r)   rE  rq   rc  rd  s   @rZ   rf  rf    s   88C= 8d 8 8 @ 
 #		a EN	 	  
 !		a DM	 Q  
 	'	a' 	' Qa  !' ' 	D	aD 	D Qa  !D6C c BS * )9 &  	 '+"EI#"&DH;?;?.2 )  	   hsm$ EN E$(? @@AB tn 3- 
 U7:.?@A XeC$5678  eGCH-w678!" ucz*+#$ C=%& SM'( C=)* + .  	, '+ EI#"&DH;?;?.2 ),, , 	, , , hsm$, DM, E$(? @@AB, tn, 3-, 
, U7:.?@A, XeC$5678,  eGCH-w678!," ucz*+#,$ C=%,& SM',( C=),* %&+, ,2   	8 !"'+EI#"&DH;?;?.2 )88 SM8 SM	8 SM8 sm8 hsm$8 8 E$(? @@AB8 tn8 3-8 
$8 U7:.?@A8 XeC$56788  eGCH-w678!8" ucz*+#8$ C=%8& SM'8( C=)8* }-=>>?+8t  FJ
 KO"EI#"&DH;?.2 xgc3h&7&@ ABC
 HU738#4dH#DEFG EN E$(? @@AB tn 3- U7:.?@A eGCH-w678 ucz*+    FJ(
 KO EI#"&DH;?.2(( xgc3h&7&@ ABC(
 HU738#4dH#DEFG( DM( E$(? @@AB( tn( 3-( U7:.?@A( eGCH-w678( ucz*+( \"( (" FJA
 KOEI#"&DH;?.2AA xgc3h&7&@ ABCA
 HU738#4dH#DEFGA A E$(? @@ABA tnA 3-A U7:.?@AA eGCH-w678A ucz*+A \=667AJ ')#;?.2 $ hsm#$ tn	
 eGCH-w678 ucz*+  2  ;?.2 SM eGCH-w678	
 ucz*+ , 
 " 	
 EN   
  ,, 	,
 DM, %&, ,  	
  }-=>>?0 
 " 	
 EN   
  ,, 	,
 DM, %&, ,  	
  }-=>>?0  #&*)-"/3 >BFJ # sm C=	
 DcN# tCH~& sm eCcN+, SM wsCx0'9:; xgc3h&7&@ ABC EN     #&*)-"/3 >BFJ, !,, sm, C=	,
 DcN#, tCH~&, sm, eCcN+,, SM, wsCx0'9:;, xgc3h&7&@ ABC, DM, %&, ,& #&*)-"/3 >BFJ' '' sm' C=	'
 DcN#' tCH~&' sm' eCcN+,' SM' wsCx0'9:;' xgc3h&7&@ ABC' ' }-=>>?'RE#t)$4  ., 
 
 
s   c l   rg   rf  r   r>   c              #   t   #    U =(       d    /  H%  n[        U[        5      (       a  UO[        US9v   M'     g 7f)N)value)
isinstancer%   )r   images     rZ   r   r   $  s.     ||eeU++%U1CC s   68r   c              #   
  #    U =(       d    /  Hj  n[         R                  " [        U5      R                  5        VVs0 s H*  u  p#U(       d  M  X"S:X  a  [	        [        U5      5      OU_M,     snn5      v   Ml     g s  snnf 7f)Nr   )r'   model_validatedictrN   r   r   )r   messagerW   rX   s       rZ   r   r   )  sh     Rg

 
 DHMDWDWDY_DYDA]^7q=$|A
a7DY_   _s   ;BA= A=.Br   c              #      #    U =(       d    /  H6  n[        U5      (       a  [        U5      O[        R                  " U5      v   M8     g 7fr^   )callabler   r1   r  )r   unprocessed_tools     rZ   r   r   0  s=     +2+8@AQ8R8R
"#3
4X\XkXkl|X}} &s   AA	sc                     [        U [        [        45      (       a%   [        U 5      =nR                  5       (       a  U$  g g ! [         a     g f = fr^   )r  ro   r   exists	Exception)r  ps     rZ   _as_pathr  5  sU    C;
Aw,!			 	  
! 
  
		
s   !A 
AAr=   c                    U =(       d    SSpU R                  S5      u  p#nU(       d  SU pBOUS:X  a  SnOUS:X  a  Sn[        R                  R                  U SU 35      nUR                  =(       d    Sn UR
                  =(       d    Un [        [        R                  " U 5      [        R                  5      (       a  S	U  S
3n UR                  R                  S5      =n(       a  U SU  SU SU 3$ U SU  SU 3$ ! [         a     NEf = f)ap  
>>> _parse_host(None)
'http://127.0.0.1:11434'
>>> _parse_host('')
'http://127.0.0.1:11434'
>>> _parse_host('1.2.3.4')
'http://1.2.3.4:11434'
>>> _parse_host(':56789')
'http://127.0.0.1:56789'
>>> _parse_host('1.2.3.4:56789')
'http://1.2.3.4:56789'
>>> _parse_host('http://1.2.3.4')
'http://1.2.3.4:80'
>>> _parse_host('https://1.2.3.4')
'https://1.2.3.4:443'
>>> _parse_host('https://1.2.3.4:56789')
'https://1.2.3.4:56789'
>>> _parse_host('example.com')
'http://example.com:11434'
>>> _parse_host('example.com:56789')
'http://example.com:56789'
>>> _parse_host('http://example.com')
'http://example.com:80'
>>> _parse_host('https://example.com')
'https://example.com:443'
>>> _parse_host('https://example.com:56789')
'https://example.com:56789'
>>> _parse_host('example.com/')
'http://example.com:11434'
>>> _parse_host('example.com:56789/')
'http://example.com:56789'
>>> _parse_host('example.com/path')
'http://example.com:11434/path'
>>> _parse_host('example.com:56789/path')
'http://example.com:56789/path'
>>> _parse_host('https://example.com:56789/path')
'https://example.com:56789/path'
>>> _parse_host('example.com:56789/path/')
'http://example.com:56789/path'
>>> _parse_host('[0001:002:003:0004::1]')
'http://[0001:002:003:0004::1]:11434'
>>> _parse_host('[0001:002:003:0004::1]:56789')
'http://[0001:002:003:0004::1]:56789'
>>> _parse_host('http://[0001:002:003:0004::1]')
'http://[0001:002:003:0004::1]:80'
>>> _parse_host('https://[0001:002:003:0004::1]')
'https://[0001:002:003:0004::1]:443'
>>> _parse_host('https://[0001:002:003:0004::1]:56789')
'https://[0001:002:003:0004::1]:56789'
>>> _parse_host('[0001:002:003:0004::1]/')
'http://[0001:002:003:0004::1]:11434'
>>> _parse_host('[0001:002:003:0004::1]:56789/')
'http://[0001:002:003:0004::1]:56789'
>>> _parse_host('[0001:002:003:0004::1]/path')
'http://[0001:002:003:0004::1]:11434/path'
>>> _parse_host('[0001:002:003:0004::1]:56789/path')
'http://[0001:002:003:0004::1]:56789/path'
>>> _parse_host('https://[0001:002:003:0004::1]:56789/path')
'https://[0001:002:003:0004::1]:56789/path'
>>> _parse_host('[0001:002:003:0004::1]:56789/path/')
'http://[0001:002:003:0004::1]:56789/path'
r   i,  z://httpP   httpsi  z	127.0.0.1[]/:)	partitionurllibparseurlsplithostnameportr  	ipaddress
ip_addressIPv6AddressrM  r  strip)r=   r  scheme_hostportsplitr  s          rZ   rR   rR   ?  s   @ zr5u-&X	tHDD
,,

6(#hZ 8
9%		&;$		t$)&&t,i.C.CDDa[d ZZc""T"XSavQtf--83tfAdV	$$ 
 s   9C> >
D
Dr^   )S
contextlibr  r   rO   rI   sysurllib.parser  hashlibr   r   pathlibr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r  pydantic.json_schemar   ollama._utilsr   version_infor   r   collections.abc	importlibr   versionrH   PackageNotFoundErrorrw   ollama._typesr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   AbstractContextManagerAbstractAsyncContextManagerr8   r   rs   rf  r   ro   r   r   r  rR   rG   rg   rZ   <module>r     s      	  
         0 2f,,5   *+        > CL-22J4Z4Z -` V N	Z N	bN	* N	bD(5+<"=> D8E? D
XhuWS#X5F5O/P&QR W_`gWh ~xwsCx/@$/P)Q RS ~_ghl_m ~
sH}-. 5t3D W%hsm W% W%o( $$ +s   F
 
F F 