
    g\                        d dl mZ d dlmZ d dlmZmZ d dlm	Z
 ddlmZ ddlmZmZmZ 	 d d	lmZ ddlmZ ed   Z	 eeef   Z	  ed       G d de             Zy# e$ rZ ed
      edZ[ww xY w)    )annotations)	dataclass)LiteralUnion)AsyncClient   )ToolDefinition   )
AgentModelModelcached_async_http_client)AsyncOpenAIu   Please install `openai` to use the OpenAI model, you can use the `openai` optional group — `pip install 'pydantic-ai-slim[openai]'`N)OpenAIModel)	codellamagemmagemma2llama3zllama3.1zllama3.2zllama3.2-visionzllama3.3mistralzmistral-nemomixtralphi3qwqqwenqwen2zqwen2.5
starcoder2F)initc                  l    e Zd ZU dZded<   ded<   ddddd		 	 	 	 	 	 	 	 	 dd
Z	 	 	 	 	 	 	 	 ddZddZy)OllamaModela  A model that implements Ollama using the OpenAI API.

    Internally, this uses the [OpenAI Python client](https://github.com/openai/openai-python) to interact with the Ollama server.

    Apart from `__init__`, all methods are private or match those of the base class.
    OllamaModelName
model_namer   openai_modelzhttp://localhost:11434/v1/ollamaN)base_urlapi_keyopenai_clienthttp_clientc                   || _         |%|J d       |J d       t        ||      | _        y|xs
 t               }t	        |||      }t        ||      | _        y)aR  Initialize an Ollama model.

        Ollama has built-in compatability for the OpenAI chat completions API ([source](https://ollama.com/blog/openai-compatibility)), so we reuse the
        [`OpenAIModel`][pydantic_ai.models.openai.OpenAIModel] here.

        Args:
            model_name: The name of the Ollama model to use. List of models available [here](https://ollama.com/library)
                You must first download the model (`ollama pull <MODEL-NAME>`) in order to use the model
            base_url: The base url for the ollama requests. The default value is the ollama default
            api_key: The API key to use for authentication. Defaults to 'ollama' for local instances,
                but can be customized for proxy setups that require authentication
            openai_client: An existing
                [`AsyncOpenAI`](https://github.com/openai/openai-python?tab=readme-ov-file#async-usage)
                client to use, if provided, `base_url` and `http_client` must be `None`.
            http_client: An existing `httpx.AsyncClient` to use for making HTTP requests.
        Nz2Cannot provide both `openai_client` and `base_url`z5Cannot provide both `openai_client` and `http_client`)r   r$   )r"   r#   r%   )r   r   r    r   r   )selfr   r"   r#   r$   r%   http_client_
oai_clients           N/var/www/openai/venv/lib/python3.12/site-packages/pydantic_ai/models/ollama.py__init__zOllamaModel.__init__E   st    2 %$#Y%YY#&_(__& +zQ^ _D 'D*B*DL$hUabJ +zQ[ \D    c               Z   K   | j                   j                  |||       d {   S 7 w)N)function_toolsallow_text_resultresult_tools)r    agent_model)r'   r.   r/   r0   s       r*   r1   zOllamaModel.agent_modeli   s9      &&22)/% 3 
 
 	
 
s   "+)+c                     d| j                    S )Nzollama:)r   )r'   s    r*   namezOllamaModel.namev   s    )**r,   )
r   r   r"   z
str | Noner#   strr$   zAsyncOpenAI | Noner%   zAsyncHTTPClient | None)r.   list[ToolDefinition]r/   boolr0   r5   returnr   )r7   r4   )__name__
__module____qualname____doc____annotations__r+   r1   r3    r,   r*   r   r   9   s        <,0.2"]#"] 	"]
 "] *"] ,"]H
 -
  	

 +
 

+r,   r   )
__future__r   _annotationsdataclassesr   typingr   r   httpxr   AsyncHTTPClienttoolsr	    r   r   r   openair   ImportErrorer   CommonOllamaModelNamesr4   r   r   r=   r,   r*   <module>rJ      s    2 ! ! 0 " "    & .34 =+% =+ =+S  
	_ s   A A1#	A,,A1