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mZmZ d dlmZ zd dlmZ W n eym Z  zede dZ [ ww G dd dee Z!dS )    )annotationsN)overload)ModelProfile)	UserError)cached_async_http_client)cohere_model_profile)deepseek_model_profile)grok_model_profile)meta_model_profile)mistral_model_profile)OpenAIJsonSchemaTransformerOpenAIModelProfileopenai_model_profile)Provider)AsyncOpenAIu   Please install the `openai` package to use the GitHub Models 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&ddZ
ddddd'ddZ
dS )(GitHubProviderzProvider for GitHub Models API.

    GitHub Models provides access to various AI models through an OpenAI-compatible API.
    See <https://docs.github.com/en/github-models> for more information.
    returnstrc                 C     dS )Ngithub selfr   r   b/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/github.pyname#      zGitHubProvider.namec                 C  r   )Nz"https://models.github.ai/inferencer   r   r   r   r   base_url'   r   zGitHubProvider.base_urlr   c                 C  s   | j S N)_clientr   r   r   r   client+   s   zGitHubProvider.client
model_nameModelProfile | Nonec                 C  sn   t tttttd}d }d|vrt|S | dd\}}||v r/|dd^}}|| |}tt	d
|S )N)xaimeta	microsoftz
mistral-aicoheredeepseek/   :)json_schema_transformer)r	   r
   r   r   r   r   lowersplitr   r   update)r   r    provider_to_profileprofileprovider_r   r   r   model_profile/   s   	zGitHubProvider.model_profileNonec                 C     d S r   r   r   r   r   r   __init__H      zGitHubProvider.__init__api_keyc                C  r4   r   r   )r   r7   r   r   r   r5   K   r6   http_clienthttpx.AsyncClientc                C  r4   r   r   )r   r7   r8   r   r   r   r5   N   r6   N)openai_clientr:   AsyncOpenAI | Nonec                C  r4   r   r   )r   r:   r   r   r   r5   Q   r6   )r7   r:   r8   
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 )a  Create a new GitHub Models provider.

        Args:
            api_key: The GitHub token to use for authentication. If not provided, the `GITHUB_API_KEY`
                environment variable will be used if available.
            openai_client: An existing `AsyncOpenAI` client to use. If provided, `api_key` and `http_client` must be `None`.
            http_client: An existing `httpx.AsyncClient` to use for making HTTP requests.
        GITHUB_API_KEYNz}Set the `GITHUB_API_KEY` environment variable or pass it via `GitHubProvider(api_key=...)` to use the GitHub Models provider.)r   r7   r8   r   )r0   )osgetenvr   r   r   r   r   )r   r7   r:   r8   r   r   r   r5   T   s   

)r   r   )r   r   )r    r   r   r!   )r   r3   )r7   r   r   r3   )r7   r   r8   r9   r   r3   )r:   r;   r   r3   )r7   r<   r:   r;   r8   r=   r   r3   )__name__
__module____qualname____doc__propertyr   r   r   r2   r   r5   r   r   r   r   r      s*    
r   )"
__future__r   _annotationsr?   typingr   httpxpydantic_air   pydantic_ai.exceptionsr   pydantic_ai.modelsr   pydantic_ai.profiles.coherer   pydantic_ai.profiles.deepseekr   pydantic_ai.profiles.grokr	   pydantic_ai.profiles.metar
   pydantic_ai.profiles.mistralr   pydantic_ai.profiles.openair   r   r   pydantic_ai.providersr   openair   ImportError_import_errorr   r   r   r   r   <module>   s2    