
    "i0                    z    S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
Jr  S
S jr    SS jr      SS	 jrg)z+Utility function to validate Ollama models.    )annotationsN)unquoteurlparse)ConnectError)ClientResponseErrorc                T  ^  U R                  5       nUS    Vs/ s H  o3S   PM	     nn[        U4S jU 5       5      (       d%  ST ST SSR                  U5       3n[        U5      eg	s  snf ! [         a  nSn[        U5      UeS	nAf[
         a  nS
n[        U5      UeS	nAff = f)zValidate that a model exists in the local Ollama instance.

Args:
    client: The Ollama client.
    model_name: The name of the model to validate.

Raises:
    ValueError: If the model is not found or if there's a connection issue.
modelsmodelc              3  d   >#    U  H%  nTU:H  =(       d    UR                  T S 35      v   M'     g7f):N)
startswith).0m
model_names     Y/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langchain_ollama/_utils.py	<genexpr>!validate_model.<locals>.<genexpr>   s0      
GR!J!O=q||zl!,<=={s   -0zModel `zA` not found in Ollama. Please pull the model (using `ollama pull z:`) or specify a valid model name. Available local models: z, zxFailed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/downloadNzLReceived an error from the Ollama API. Please check your Ollama server logs.)listanyjoin
ValueErrorr   r   )clientr   responser   model_namesmsges    `     r   validate_modelr      s    %;;=>Fx>P!Q>PU.>P!Q 
GR
 
 
 * &--7L 977;yy7M6NP 
 S/!
 "R  %B 	 o1$ %4 	 o1$%s4   A/ A*AA/ *A/ /
B'9BB'B""B'c                   U (       d  g[        U 5      nUR                  (       a"  UR                  (       a  UR                  (       d  gUR                  (       d  U S4$ UR
                  =(       d    Sn[        UR                  5      n[        U5      nU SU 3n[        R                  " UR                  5       5      R                  5       nSSU 30nUR                  =(       d    SnUR                  (       a  USUR                   3-  nUR                   SU 3nUR                  (       a  XR                  -  nUR                  (       a  USUR                   3-  nUR                  (       a  US	UR                   3-  nX4$ )
a  Parse URL and extract `userinfo` credentials for headers.

Handles URLs of the form: `https://user:password@host:port/path`

Args:
    url: The URL to parse.

Returns:
    A tuple of `(cleaned_url, headers_dict)` where:
    - `cleaned_url` is the URL without authentication credentials if any were
        found. Otherwise, returns the original URL.
    - `headers_dict` contains Authorization header if credentials were found.
)NNN r   AuthorizationzBasic z://?#)r   schemenetlochostnameusernamepasswordr   base64	b64encodeencodedecodeportpathqueryfragment)	urlparsedr(   r'   credentialsencoded_credentialsheaderscleaned_netloccleaned_urls	            r   parse_url_with_authr8   2   s@     c]F==V__??Dy $"H v'Hx HJaz*K **;+=+=+?@GGI&)<(= >?G __*N{{Afkk]++]]O3~&67K{{{{"||6<<.))6??+,,    c                b    U(       a(  U R                  S0 5      nUR                  U5        X S'   gg)zMerge authentication headers into client kwargs in-place.

Args:
    client_kwargs: The client kwargs dict to update.
    auth_headers: Headers to merge (typically from `parse_url_with_auth`).
r5   N)getupdate)client_kwargsauth_headersr5   s      r   merge_auth_headersr?   e   s2     ##Ir2|$#*i  r9   )r   r   r   strreturnNone)r1   z
str | NonerA   z(tuple[str | None, dict[str, str] | None])r=   dictr>   zdict[str, str] | NonerA   rB   )__doc__
__future__r   r)   urllib.parser   r   httpxr   ollamar   r   r   r8   r?    r9   r   <module>rJ      sR    1 "  *  (#%L0 	0 -0 f++'+ 
+r9   