o
    i                  
   @  s8  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 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$m%Z% d dl&m'Z' d dl(m)Z) zd dlm	Z	 W n e*y Z+ ze*de+dZ+[+ww G dd de)e	 Z,dS )    )annotations)overload)AsyncClient)AsyncOpenAI)ModelProfile)cached_async_http_client)amazon_model_profile)anthropic_model_profile)cohere_model_profile)deepseek_model_profile)google_model_profile)grok_model_profile)groq_model_profile)meta_model_profile)mistral_model_profile)moonshotai_model_profile)OpenAIJsonSchemaTransformerOpenAIModelProfileopenai_model_profile)qwen_model_profile)Provideru   Please install the `openai` package to use the LiteLLM provider, you can use the `openai` optional group — `pip install "pydantic-ai-slim[openai]"`Nc                   @  s   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e	dddd#ddZ
e	dddd$ddZ
e	d%ddZ
dddddd&ddZ
dS )'LiteLLMProviderzProvider for LiteLLM API.returnstrc                 C  s   dS )Nlitellm selfr   r   c/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/litellm.pyname$   s   zLiteLLMProvider.namec                 C  s   t | jjS N)r   clientbase_urlr   r   r   r   r"   (   s   zLiteLLMProvider.base_urlr   c                 C  s   | j S r    )_clientr   r   r   r   r!   ,   s   zLiteLLMProvider.client
model_nameModelProfile | Nonec                 C  st   t tttttttttttt	t
td}d }d|v r*|dd\}}||v r*|| |}|d u r2t|}ttd|S )N)	anthropicopenaigoogle	mistralaimistralcohereamazonbedrockz
meta-llamametagroqdeepseek
moonshotaizx-aiqwen/   )json_schema_transformer)r	   r   r   r   r
   r   r   r   r   r   r   r   splitr   r   update)r   r$   provider_to_profileprofileprovider_prefixmodel_suffixr   r   r   model_profile0   s0   zLiteLLMProvider.model_profileN)api_keyapi_baser=   
str | Noner>   Nonec                C     d S r    r   )r   r=   r>   r   r   r   __init__T   s   zLiteLLMProvider.__init__http_clientAsyncHTTPClientc                C  rA   r    r   )r   r=   r>   rC   r   r   r   rB   \   s   openai_clientc                C  rA   r    r   )r   rE   r   r   r   rB   e   s   )r=   r>   rE   rC   AsyncOpenAI | NoneAsyncHTTPClient | Nonec                C  sT   |dur	|| _ dS |durt||pd|d| _ dS tdd}t||p#d|d| _ dS )a  Initialize a LiteLLM provider.

        Args:
            api_key: API key for the model provider. If None, LiteLLM will try to get it from environment variables.
            api_base: Base URL for the model provider. Use this for custom endpoints or self-hosted models.
            openai_client: Pre-configured OpenAI client. If provided, other parameters are ignored.
            http_client: Custom HTTP client to use.
        Nzlitellm-placeholder)r"   r=   rC   r   )provider)r#   r   r   )r   r=   r>   rE   rC   r   r   r   rB   h   s   


)r   r   )r   r   )r$   r   r   r%   )r=   r?   r>   r?   r   r@   )r=   r?   r>   r?   rC   rD   r   r@   )rE   r   r   r@   )
r=   r?   r>   r?   rE   rF   rC   rG   r   r@   )__name__
__module____qualname____doc__propertyr   r"   r!   r<   r   rB   r   r   r   r   r   !   s0    
$r   )-
__future__r   _annotationstypingr   httpxr   rD   r'   r   pydantic_air   pydantic_ai.modelsr   pydantic_ai.profiles.amazonr   pydantic_ai.profiles.anthropicr	   pydantic_ai.profiles.coherer
   pydantic_ai.profiles.deepseekr   pydantic_ai.profiles.googler   pydantic_ai.profiles.grokr   pydantic_ai.profiles.groqr   pydantic_ai.profiles.metar   pydantic_ai.profiles.mistralr   pydantic_ai.profiles.moonshotair   pydantic_ai.profiles.openair   r   r   pydantic_ai.profiles.qwenr   pydantic_ai.providersr   ImportError_import_errorr   r   r   r   r   <module>   s<    