o
    i}                  
   @  s  d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ 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 d dlmZ zd dlmZ W n e yw Z! ze de!dZ![!ww G dd dee Z"dS )    )annotationsN)AsyncOpenAI)ModelProfile)	UserError)cached_async_http_client)cohere_model_profile)deepseek_model_profile)google_model_profile)harmony_model_profile)meta_model_profile)mistral_model_profile)OpenAIJsonSchemaTransformerOpenAIModelProfile)qwen_model_profile)Provideru   Please install the `openai` package to use the Ollama provider, you can use the `openai` optional group — `pip install "pydantic-ai-slim[openai]"`c                   @  sX   e Zd ZdZedddZedddZedd	d
ZdddZ				ddddZ	dS )OllamaProviderz(Provider for local or remote Ollama API.returnstrc                 C  s   dS )Nollama selfr   r   b/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/ollama.pyname!   s   zOllamaProvider.namec                 C  s   t | jjS N)r   clientbase_urlr   r   r   r   r   %   s   zOllamaProvider.base_urlr   c                 C  s   | j S r   )_clientr   r   r   r   r   )   s   zOllamaProvider.client
model_nameModelProfile | Nonec              	   C  sV   t tttttttd}d }| D ]\}}| }|	|r"||}qt
td|S )N)llamagemmaqwenqwqdeepseekmistralcommandzgpt-oss)json_schema_transformer)r   r	   r   r   r   r   r
   itemslower
startswithr   r   update)r   r   prefix_to_profileprofileprefixprofile_funcr   r   r   model_profile-   s    
zOllamaProvider.model_profileNr   
str | Noneapi_keyopenai_clientAsyncOpenAI | Nonehttp_clienthttpx.AsyncClient | NoneNonec                 C  s   |dur!|du sJ d|du sJ d|du sJ d|| _ dS |p'td}|s.td|p6tdp6d}|durEt|||d	| _ dS td
d}t|||d	| _ dS )a  Create a new Ollama provider.

        Args:
            base_url: The base url for the Ollama requests. If not provided, the `OLLAMA_BASE_URL` environment variable
                will be used if available.
            api_key: The API key to use for authentication, if not provided, the `OLLAMA_API_KEY` environment variable
                will be used if available.
            openai_client: An existing
                [`AsyncOpenAI`](https://github.com/openai/openai-python?tab=readme-ov-file#async-usage)
                client to use. If provided, `base_url`, `api_key`, 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`z1Cannot provide both `openai_client` and `api_key`OLLAMA_BASE_URLzwSet the `OLLAMA_BASE_URL` environment variable or pass it via `OllamaProvider(base_url=...)`to use the Ollama provider.OLLAMA_API_KEYzapi-key-not-set)r   r2   r5   r   )provider)r   osgetenvr   r   r   )r   r   r2   r3   r5   r   r   r   __init__C   s   

zOllamaProvider.__init__)r   r   )r   r   )r   r   r   r   )NNNN)
r   r1   r2   r1   r3   r4   r5   r6   r   r7   )
__name__
__module____qualname____doc__propertyr   r   r   r0   r=   r   r   r   r   r      s    
r   )#
__future__r   _annotationsr;   httpxopenair   pydantic_air   pydantic_ai.exceptionsr   pydantic_ai.modelsr   pydantic_ai.profiles.coherer   pydantic_ai.profiles.deepseekr   pydantic_ai.profiles.googler	   pydantic_ai.profiles.harmonyr
   pydantic_ai.profiles.metar   pydantic_ai.profiles.mistralr   pydantic_ai.profiles.openair   r   pydantic_ai.profiles.qwenr   pydantic_ai.providersr   ImportError_import_errorr   r   r   r   r   <module>   s6    