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 zd dlm Z  W n e!yu Z" ze!de"dZ"["ww dddZ#dddZ$G dd dee  Z%dS )    )annotationsN)overload)ModelProfile)	UserError)cached_async_http_client)deepseek_model_profile)google_model_profile)groq_model_profile)meta_model_profile)mistral_model_profile)moonshotai_model_profile)openai_model_profile)qwen_model_profile)Provider)	AsyncGroqu   Please install the `groq` package to use the Groq provider, you can use the `groq` optional group — `pip install "pydantic-ai-slim[groq]"`
model_namestrreturnModelProfile | Nonec                 C  s   t dddt| S )zJGet the model profile for an MoonshotAI model used with the Groq provider.Tsupports_json_object_outputsupports_json_schema_output)r   updater   r    r   `/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/groq.pygroq_moonshotai_model_profile   s   r   c                 C  s&   | dv rt dddt| S t| S )zCGet the model profile for a Meta model used with the Groq provider.>   llama-4-scout-17b-16e-instruct"llama-4-maverick-17b-128e-instructTr   )r   r   r
   r   r   r   r   meta_groq_model_profile%   s
   r   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"ddZ
e	ddddd#ddZ
dddddd$ddZ
dS )%GroqProviderzProvider for Groq API.r   r   c                 C  s   dS )Ngroqr   selfr   r   r   name2   s   zGroqProvider.namec                 C  s   t | jjS N)r   clientbase_urlr"   r   r   r   r'   6   s   zGroqProvider.base_urlr   c                 C  s   | j S r%   )_clientr"   r   r   r   r&   :   s   zGroqProvider.clientr   r   c              
   C  sf   t ttttttttd	}|	 D ] \}}|
 }||r0|dr*|t|d  }||  S qd S )N)	llamazmeta-llama/gemmaqwendeepseekmistralzmoonshotai/z	compound-zopenai//)r
   r   r   r   r   r   r   r	   r   itemslower
startswithendswithlen)r#   r   prefix_to_profileprefixprofile_funcr   r   r   model_profile>   s$   

zGroqProvider.model_profileN)groq_clientr8   AsyncGroq | NoneNonec                C     d S r%   r   )r#   r8   r   r   r   __init__T   s   zGroqProvider.__init__)api_keyr'   http_clientr=   
str | Noner'   r>   httpx.AsyncClient | Nonec                C  r;   r%   r   )r#   r=   r'   r>   r   r   r   r<   W   s   )r=   r'   r8   r>   c                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}|p/tdd}|s6td|durDt|||d	| _ dS td
d}t|||d	| _ dS )a  Create a new Groq provider.

        Args:
            api_key: The API key to use for authentication, if not provided, the `GROQ_API_KEY` environment variable
                will be used if available.
            base_url: The base url for the Groq requests. If not provided, the `GROQ_BASE_URL` environment variable
                will be used if available. Otherwise, defaults to Groq's base url.
            groq_client: An existing
                [`AsyncGroq`](https://github.com/groq/groq-python?tab=readme-ov-file#async-usage)
                client to use. If provided, `api_key` and `http_client` must be `None`.
            http_client: An existing `AsyncHTTPClient` to use for making HTTP requests.
        Nz3Cannot provide both `groq_client` and `http_client`z/Cannot provide both `groq_client` and `api_key`z0Cannot provide both `groq_client` and `base_url`GROQ_API_KEYGROQ_BASE_URLzhttps://api.groq.comzoSet the `GROQ_API_KEY` environment variable or pass it via `GroqProvider(api_key=...)`to use the Groq provider.)r'   r=   r>   r!   )provider)r(   osgetenvr   r   r   )r#   r=   r'   r8   r>   r   r   r   r<   \   s   

)r   r   )r   r   r   r   r   r   )r8   r9   r   r:   )r=   r?   r'   r?   r>   r@   r   r:   )
r=   r?   r'   r?   r8   r9   r>   r@   r   r:   )__name__
__module____qualname____doc__propertyr$   r'   r&   r7   r   r<   r   r   r   r   r    /   s&    
r    rF   )&
__future__r   _annotationsrD   typingr   httpxpydantic_air   pydantic_ai.exceptionsr   pydantic_ai.modelsr   pydantic_ai.profiles.deepseekr   pydantic_ai.profiles.googler   pydantic_ai.profiles.groqr	   pydantic_ai.profiles.metar
   pydantic_ai.profiles.mistralr   pydantic_ai.profiles.moonshotair   pydantic_ai.profiles.openair   pydantic_ai.profiles.qwenr   pydantic_ai.providersr   r!   r   ImportError_import_errorr   r   r    r   r   r   r   <module>   s:    


