o
    i$                  
   @  s   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 zd dlmZ W n ey_ Z zededZ[ww ddlmZ G dd dee ZdS )    )annotationsN)overload)AsyncClient)ModelProfile)	UserError)deepseek_model_profile)google_model_profile)meta_model_profile)mistral_model_profile)moonshotai_model_profile)qwen_model_profile)AsyncInferenceClientu   Please install the `huggingface_hub` package to use the HuggingFace provider, you can use the `huggingface` optional group — `pip install 'pydantic-ai-slim[huggingface]'`   )Providerc                   @  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Z
e	ddd'ddZ
e	ddd(ddZ
e	ddd)ddZ
e	ddd*ddZ
					d+d,d!dZ
dS )-HuggingFaceProviderzProvider for Hugging Face.returnstrc                 C  s   dS )Nhuggingface selfr   r   g/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/huggingface.pyname   s   zHuggingFaceProvider.namec                 C  s   | j jS N)clientmodelr   r   r   r   base_url#   s   zHuggingFaceProvider.base_urlr   c                 C  s   | j S r   )_clientr   r   r   r   r   '   s   zHuggingFaceProvider.client
model_nameModelProfile | Nonec                 C  sN   t tttttd}d|vrd S | }|dd\}}||v r%|| |S d S )N)zdeepseek-aigoogleqwenz
meta-llama	mistralai
moonshotai/r   )r   r   r   r	   r
   r   lowersplit)r   r   provider_to_profileproviderr   r   r   model_profile+   s   	z!HuggingFaceProvider.model_profileN)api_keyr   r*   
str | NoneNonec                C     d S r   r   )r   r   r*   r   r   r   __init__?      zHuggingFaceProvider.__init__provider_namec                C  r-   r   r   )r   r0   r*   r   r   r   r.   A   r/   	hf_clientc                C  r-   r   r   )r   r1   r*   r   r   r   r.   C   r/   c                C  r-   r   r   )r   r1   r   r*   r   r   r   r.   E   r/   c                C  r-   r   r   )r   r1   r0   r*   r   r   r   r.   G   r/   c                C  r-   r   r   )r   r*   r   r   r   r.   I   r/   AsyncInferenceClient | Nonehttp_clientAsyncClient | Nonec                 C  sl   |pt d}|du rtd|durtd|dur#|dur#td|du r1t|||d| _dS || _dS )a  Create a new Hugging Face provider.

        Args:
            base_url: The base url for the Hugging Face requests.
            api_key: The API key to use for authentication, if not provided, the `HF_TOKEN` environment variable
                will be used if available.
            hf_client: An existing
                [`AsyncInferenceClient`](https://huggingface.co/docs/huggingface_hub/v0.29.3/en/package_reference/inference_client#huggingface_hub.AsyncInferenceClient)
                client to use. If not provided, a new instance will be created.
            http_client: (currently ignored) An existing `httpx.AsyncClient` to use for making HTTP requests.
            provider_name : Name of the provider to use for inference. available providers can be found in the [HF Inference Providers documentation](https://huggingface.co/docs/inference-providers/index#partners).
                defaults to "auto", which will select the first available provider for the model, the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
                If `base_url` is passed, then `provider_name` is not used.
        HF_TOKENNzySet the `HF_TOKEN` environment variable or pass it via `HuggingFaceProvider(api_key=...)`to use the HuggingFace provider.zR`http_client` is ignored for HuggingFace provider, please use `hf_client` instead.z3Cannot provide both `base_url` and `provider_name`.)r*   r(   r   )osgetenvr   
ValueErrorr   r   )r   r   r*   r1   r3   r0   r   r   r   r.   L   s   
)r   r   )r   r   )r   r   r   r   )r   r   r*   r+   r   r,   )r0   r   r*   r+   r   r,   )r1   r   r*   r+   r   r,   )r1   r   r   r   r*   r+   r   r,   )r1   r   r0   r   r*   r+   r   r,   )r*   r+   r   r,   )NNNNN)r   r+   r*   r+   r1   r2   r3   r4   r0   r+   r   r,   )__name__
__module____qualname____doc__propertyr   r   r   r)   r   r.   r   r   r   r   r      s6    
r   )
__future__r   _annotationsr6   typingr   httpxr   pydantic_air   pydantic_ai.exceptionsr   pydantic_ai.profiles.deepseekr   pydantic_ai.profiles.googler   pydantic_ai.profiles.metar	   pydantic_ai.profiles.mistralr
   pydantic_ai.profiles.moonshotair   pydantic_ai.profiles.qwenr   huggingface_hubr   ImportError_import_error r   r   r   r   r   r   <module>   s0    