o
    i                  
   @  s<  d dl mZ d dlZd dlm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 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 )    )annotationsN)overload)AsyncOpenAI)ModelProfile)	UserError)cached_async_http_client)amazon_model_profile)anthropic_model_profile)cohere_model_profile)deepseek_model_profile)google_model_profile)grok_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 OpenRouter provider, you can use the `openai` optional group — `pip install "pydantic-ai-slim[openai]"`c                   @  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Z
e	d%ddZ
e	d&ddZ
e	d'ddZ
e	ddd(ddZ
ddddd)d dZ
dS )*OpenRouterProviderzProvider for OpenRouter API.returnstrc                 C     dS )N
openrouter selfr   r   f/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/openrouter.pyname%      zOpenRouterProvider.namec                 C  r   )Nzhttps://openrouter.ai/api/v1r   r   r   r   r   base_url)   r    zOpenRouterProvider.base_urlr   c                 C  s   | j S N)_clientr   r   r   r   client-   s   zOpenRouterProvider.client
model_nameModelProfile | Nonec                 C  sd   t ttttttttt	t
d}d }|dd\}}||v r*|dd^}}|| |}ttd|S )N)googleopenai	anthropic	mistralaiqwenzx-aicohereamazondeepseekz
meta-llama
moonshotai/   :)json_schema_transformer)r   r   r	   r   r   r   r
   r   r   r   r   splitr   r   update)r   r%   provider_to_profileprofileprovider_r   r   r   model_profile1   s$   z OpenRouterProvider.model_profileNonec                 C     d S r"   r   r   r   r   r   __init__K      zOpenRouterProvider.__init__api_keyc                C  r<   r"   r   )r   r?   r   r   r   r=   N   r>   http_clienthttpx.AsyncClientc                C  r<   r"   r   )r   r?   r@   r   r   r   r=   Q   r>   c                C  r<   r"   r   )r   r@   r   r   r   r=   T   r>   N)openai_clientrB   AsyncOpenAI | Nonec                C  r<   r"   r   )r   rB   r   r   r   r=   W   r>   )r?   rB   r@   
str | Nonehttpx.AsyncClient | Nonec                C  sr   |pt d}|s|d u rtd|d ur|| _d S |d ur)t| j||d| _d S tdd}t| j||d| _d S )NOPENROUTER_API_KEYzSet the `OPENROUTER_API_KEY` environment variable or pass it via `OpenRouterProvider(api_key=...)`to use the OpenRouter provider.)r!   r?   r@   r   )r8   )osgetenvr   r#   r   r!   r   )r   r?   rB   r@   r   r   r   r=   Z   s   

)r   r   )r   r   )r%   r   r   r&   )r   r;   )r?   r   r   r;   )r?   r   r@   rA   r   r;   )r@   rA   r   r;   )rB   rC   r   r;   )r?   rD   rB   rC   r@   rE   r   r;   )__name__
__module____qualname____doc__propertyr   r!   r$   r:   r   r=   r   r   r   r   r   "   s.    
r   ),
__future__r   _annotationsrG   typingr   httpxr(   r   pydantic_air   pydantic_ai.exceptionsr   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.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>    