o
    i~                     @  s  d Z ddlmZ ddlZddlmZmZ ddlm	Z	m
Z
mZmZ ddlZddlmZ ddlmZ e	rVd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Zedddddd8ddZ edddddd9ddZ edddddd:d!dZ edddd"d;d%dZ edddddd<d(dZ edddd"d=d+dZ ed, Z!dddddd>d.dZ d?d0d1Z"d@d3d4Z#dAd6d7Z$dS )Bz8This module implements the Pydantic AI Gateway provider.    )annotationsN)	AwaitableCallable)TYPE_CHECKINGAnyLiteraloverload)	UserError)cached_async_http_client)
BaseClient)Client)	AsyncGroq)AsyncOpenAI)AsyncAnthropicClient)Providerz"https://gateway.pydantic.dev/proxy)routeapi_keybase_urlhttp_clientupstream_providerILiteral['openai', 'openai-chat', 'openai-responses', 'chat', 'responses']r   
str | Noner   r   r   httpx.AsyncClient | NonereturnProvider[AsyncOpenAI]c               C     d S N r   r   r   r   r   r   r   c/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/gateway.pygateway_provider      	r    Literal['groq']Provider[AsyncGroq]c               C  r   r   r   r   r   r   r   r    &   r!   Literal['anthropic']Provider[AsyncAnthropicClient]c               C  r   r   r   r   r   r   r   r    2   r!   )r   r   r   Literal['bedrock', 'converse']Provider[BaseClient]c               C  r   r   r   r   r   r   r   r   r   r   r    >      "Literal['gemini', 'google-vertex']Provider[GoogleClient]c               C  r   r   r   r   r   r   r   r    I   r!   strProvider[Any]c               C  r   r   r   r(   r   r   r   r    U   r)   )openaigroq	anthropicbedrockgoogle-vertexopenai-chatopenai-responseschat	responsesconversegeminiUpstreamProvider | strc               C  s4  |pt d}|std|pt dt}|ptd|  d}dt|gi|_|du r/t| }t||}| dv rEd	d
l	m
} ||||dS | dkrVd	dlm} ||||dS | dkrpddlm} d	dlm} |||||ddS | dv rd	dlm}	 |	||ddS | dv rd	dlm}
 |
d|||dS td|  )a  Create a new Gateway provider.

    Args:
        upstream_provider: The upstream provider to use.
        route: The name of the provider or routing group to use to handle the request. If not provided, the default
            routing group for the API format will be used.
        api_key: The API key to use for authentication. If not provided, the `PYDANTIC_AI_GATEWAY_API_KEY`
            environment variable will be used if available.
        base_url: The base URL to use for the Gateway. If not provided, the `PYDANTIC_AI_GATEWAY_BASE_URL`
            environment variable will be used if available. Otherwise, defaults to `https://gateway.pydantic.dev/proxy`.
        http_client: The HTTP client to use for the Gateway.
    PYDANTIC_AI_GATEWAY_API_KEYzSet the `PYDANTIC_AI_GATEWAY_API_KEY` environment variable or pass it via `gateway_provider(..., api_key=...)` to use the Pydantic AI Gateway provider.PYDANTIC_AI_GATEWAY_BASE_URLzgateway/providerrequestN)r.   r3   r4   r5   r6      )OpenAIProvider)r   r   r   r/   )GroqProviderr0   r   )AsyncAnthropic)AnthropicProvider)
auth_tokenr   r   )anthropic_clientr1   r7   )BedrockProviderzpydantic-ai-gateway)r   r   region_name)r2   r8   )GoogleProviderT)vertexair   r   r   zUnknown upstream provider: )osgetenvr	   GATEWAY_BASE_URLr
   _request_hookevent_hooksnormalize_gateway_provider_merge_url_pathr.   r@   r/   rA   r0   rB   rC   r1   rG   googlerI   )r   r   r   r   r   r@   rA   rB   rC   rG   rI   r   r   r   r    p   sD   
3Callable[[httpx.Request], Awaitable[httpx.Request]]c                   s   d fdd}|S )zzRequest hook for the gateway provider.

    It adds the `"traceparent"` and `"Authorization"` headers to the request.
    r>   httpx.Requestr   c                   sD   ddl m} i }|| | j| d| jvr d  | jd< | S )Nr   )injectAuthorizationzBearer )opentelemetry.propagaterU   headersupdate)r>   rU   rX   r   r   r   _hook   s   
z_request_hook.<locals>._hookN)r>   rT   r   rT   r   )r   r[   r   rZ   r   rN      s   rN   pathc                 C  s   |  dd |d S )zvMerge a base URL and a path.

    Args:
        base_url: The base URL to merge.
        path: The path to merge.
    /)rstriplstrip)r   r\   r   r   r   rQ      s   rQ   r=   c                 C  s4   | dv rdS | dv rdS | dv rdS | dv rdS | S )	zdNormalize a gateway provider name.

    Args:
        provider: The provider name to normalize.
    )r.   r3   r5   r.   )r4   r6   r4   )r8   r2   r2   rF   r1   r   r<   r   r   r   rP      s   rP   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r"   r   r   r   r   r   r   r   r   r   r#   )r   r$   r   r   r   r   r   r   r   r   r   r%   )
r   r&   r   r   r   r   r   r   r   r'   )r   r*   r   r   r   r   r   r   r   r   r   r+   )
r   r,   r   r   r   r   r   r   r   r-   )r   r9   r   r   r   r   r   r   r   r   r   r-   )r   r,   r   rS   )r   r,   r\   r,   r   r,   )r=   r,   r   r,   )%__doc__
__future__r   _annotationsrK   collections.abcr   r   typingr   r   r   r   httpxpydantic_ai.exceptionsr	   pydantic_ai.modelsr
   botocore.clientr   google.genair   GoogleClientr/   r   r.   r   pydantic_ai.models.anthropicr   pydantic_ai.providersr   rM   r    UpstreamProviderrN   rQ   rP   r   r   r   r   <module>   sz    


H

