�
lMg�V � �L � d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm Z m
Z
mZmZm
Z
mZmZmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJ d dlKmLZL d d lMmNZN d
dlOmPZPmQZQ erd dlRZSd dlTmUZUmVZV d d
lWmXZX ej� eZ� Z[ ej� d� Z] G d� d� Z^ G d� d� Z_ G d� de_� Z` G d� de_� Zay)� N)
�
TYPE_CHECKING�Any�
AsyncIterable�Dict�List�Literal�Optional�Set�Union�overload)�CaseInsensitiveDict)�ALL_INFERENCE_API_FRAMEWORKS�INFERENCE_ENDPOINT�MAIN_INFERENCE_API_FRAMEWORKS)�InferenceTimeoutError)�TASKS_EXPECTING_IMAGES�ContentT�ModelStatus�&_async_stream_chat_completion_response�&_async_stream_text_generation_response�_b64_encode�
_b64_to_image�_bytes_to_dict�_bytes_to_image�_bytes_to_list�_fetch_recommended_models�'_get_unsupported_text_generation_kwargs�
_import_numpy�_open_as_binary�_prepare_payload�'_set_unsupported_text_generation_kwargs�raise_text_generation_error)� AudioClassificationOutputElement�"AudioClassificationOutputTransform�AudioToAudioOutputElement� AutomaticSpeechRecognitionOutput�ChatCompletionInputGrammarType� ChatCompletionInputStreamOptions�ChatCompletionInputToolType�ChatCompletionOutput�ChatCompletionStreamOutput�&DocumentQuestionAnsweringOutputElement�FillMaskOutputElement� ImageClassificationOutputElement�ImageSegmentationOutputElement�ImageToTextOutput�ObjectDetectionOutputElement�QuestionAnsweringOutputElement�SummarizationOutput�#TableQuestionAnsweringOutputElement�TextClassificationOutputElement�!TextClassificationOutputTransform�TextGenerationInputGrammarType�TextGenerationOutput�TextGenerationStreamOutput�TextToImageTargetSize�TextToSpeechEarlyStoppingEnum� TokenClassificationOutputElement�ToolElement�TranslationOutput�$VisualQuestionAnsweringOutputElement�#ZeroShotClassificationOutputElement�(ZeroShotImageClassificationOutputElement)�build_hf_headers)�_deprecate_arguments� )�_async_yield_from�_import_aiohttp)�ClientResponse�
ClientSession)�ImagezAThe following `model_kwargs` are not used by the model: \[(.*?)\]c 6 �< � e Zd ZdZ d�ddddddddd�dee deeedf dee dee eef d ee eef d
edee
dee d
ee ddfd�Zd� Ze
dddddd�deeee ef dee dee dee ded defd�� Ze
dddddd�deeee ef dee dee dee ded dee fd�� Ze
dddddd�deeee ef dee dee dee dedeeee f fd�� Zdddddd�deeee ef dee dee dee dedeeee f fd�Zd� Zd� Zd� Zd� Zdddd �d!edee d"ee d#ed$ dee f
d%�Zdd&�d!edee dee fd'�Zdd&�d!edee defd(�Ze
ddddddddddddddddddd)�d*ee dee ded d+ee d,eee d-ee d.ee d/ee d0ee d1ee d2ee d3eee d4ee d5ee d6eee!ef d7ee d8eee" d9ee d:ee de#f(d;�� Z$e
ddddddddddddddddddd)�d*ee dee ded d+ee d,eee d-ee d.ee d/ee d0ee d1ee d2ee d3eee d4ee d5ee d6eee!ef d7ee d8eee" d9ee d:ee dee% f(d<�� Z$e
ddddddddddddddddddd)�d*ee dee ded+ee d,eee d-ee d.ee d/ee d0ee d1ee d2ee d3eee d4ee d5ee d6eee!ef d7ee d8eee" d9ee d:ee dee#ee% f f(d=�� Z$ddddddddddddddddddd)�d*ee dee ded+ee d,eee d-ee d.ee d/ee d0ee d1ee d2ee d3eee d4ee d5ee d6eee!ef d7ee d8eee" d9ee d:ee dee#ee% f f(d>�Z$d�dee defd?�Z&dddddddddd@� dAedBedee dCee dDee dEee dFee dGee dHee d"ee dIeeeee ef dee' fdJ�Z(ddddddK�dLedMee dNee dOee dPeedQ dee ddRfdS�Z)ddddT�dLedee dUeee d"ee dee* f
dV�Z+ddddW�dAedee d#eedX d"ee dee, f
dY�Z-ddddddZ�dAedee d[ee d\ee d]eed^ d_ee dee. fd`�Z/ d�ddddddda�dAedbee dcee ddee deee dfee dgee dee ddhfdi�Z0dd&�dAedee de1fdj�Z2 d�dkedeedl ee f de eee f fdm�Z3dddn�dAedee d_ee dee4 fdo�Z5dddddddddp�dBedqedee dree dCee dDee dFee dGee dHee d"ee dee6ee6 f fds�Z7dd&�dteduee dee dee fdv�Z8 e9dwdxgdy�z� dddddd{�dLedxee ee
f dee d|ee d}ee ee
f d~eed de:fd��� Z;ddd��d�e ee
f d�edee dxee ee
f de<f
d��Z=dd&�d�e ee
f dee dee fd��Z>dd&�d�e ee
f dee dee fd��Z?dddd �dLedee d"ee d#ed� dee@ f
d��ZAe
ddddddddddddddddddddddd��dbed�ed ded dee d�ee d�ee d�ee d�ee d+ee d�eeB d�ee d�ee d�ee d2ee d3eee d�eee d5ee d"ee d�ee d:ee dOee d�ee d�ee def0d��� ZCe
ddddddddddddddddddddddd��dbed�ed ded dee d�ee d�ee d�ee d�ee d+ee d�eeB d�ee d�ee d�ee d2ee d3eee d�eee d5ee d"ee d�ee d:ee dOee d�ee d�ee deDf0d��� ZCe
ddddddddddddddddddddddd��dbed�ed ded dee d�ee d�ee d�ee d�ee d+ee d�eeB d�ee d�ee d�ee d2ee d3eee d�eee d5ee d"ee d�ee d:ee dOee d�ee d�ee dee f0d��� ZCe
ddddddddddddddddddddddd��dbed�ed ded dee d�ee d�ee d�ee d�ee d+ee d�eeB d�ee d�ee d�ee d2ee d3eee d�eee d5ee d"ee d�ee d:ee dOee d�ee d�ee deeE f0d��� ZCe
ddddddddddddddddddddddd��dbed�ed dedee d�ee d�ee d�ee d�ee d+ee d�eeB d�ee d�ee d�ee d2ee d3eee d�eee d5ee d"ee d�ee d:ee dOee d�ee d�ee deeDeeE f f0d��� ZCddddddddddddddddddddddd��dbed�ededee d�ee d�ee d�ee d�ee d+ee d�eeB d�ee d�ee d�ee d2ee d3eee d�eee d5ee d"ee d�ee d:ee dOee d�ee d�ee deeeDee eeE f f0d��ZCdddddddddd�� dbedcee ddee deee dfee dgee dee d�ee d�eeF d2ee ddhfd��ZGdddddddddddddddddd��dLedee d�ee d�eeed�f d�ee d�ee d�ee d�ee d�ee d�ee d�ee d�ee d�ee d5ee d"ee d:ee d�ee d�ee def&d��ZHddddd��dLedee d�eed� d�eee d�ee deeI fd��ZJddddddd��dLedee d�ee d�ee d|ee d~eed d}ee ee
f deKfd��ZLddd��dAedBedee d"ee deeM f
d��ZNdddd��dLed�ee d�ed�ee dee deeO fd��ZPddd��dAed�ee dee d�ee deeQ f
d��ZRd�dee dd�fdZSd�dee dee defdÄZTeUdedefdĄ� ZVdd&�dee de ee
f fdńZWd�dee defdƄZXd�dee deYfdDŽZZe[d�dȄ� Z\y)��AsyncInferenceClienta6
Initialize a new Inference Client.
[`InferenceClient`] aims to provide a unified experience to perform inference. The client can be used
seamlessly with either the (free) Inference API or self-hosted Inference Endpoints.
Args:
model (`str`, `optional`):
The model to run inference with. Can be a model id hosted on the Hugging Face Hub, e.g. `meta-llama/Meta-Llama-3-8B-Instruct`
or a URL to a deployed Inference Endpoint. Defaults to None, in which case a recommended model is
automatically selected for the task.
Note: for better compatibility with OpenAI's client, `model` has been aliased as `base_url`. Those 2
arguments are mutually exclusive. If using `base_url` for chat completion, the `/chat/completions` suffix
path will be appended to the base URL (see the [TGI Messages API](https://huggingface.co/docs/text-generation-inference/en/messages_api)
documentation for details). When passing a URL as `model`, the client will not append any suffix path to it.
token (`str` or `bool`, *optional*):
Hugging Face token. Will default to the locally saved token if not provided.
Pass `token=False` if you don't want to send your token to the server.
Note: for better compatibility with OpenAI's client, `token` has been aliased as `api_key`. Those 2
arguments are mutually exclusive and have the exact same behavior.
timeout (`float`, `optional`):
The maximum number of seconds to wait for a response from the server. Loading a new model in Inference
API can take up to several minutes. Defaults to None, meaning it will loop until the server is available.
headers (`Dict[str, str]`, `optional`):
Additional headers to send to the server. By default only the authorization and user-agent headers are sent.
Values in this dictionary will override the default values.
cookies (`Dict[str, str]`, `optional`):
Additional cookies to send to the server.
trust_env ('bool', 'optional'):
Trust environment settings for proxy configuration if the parameter is `True` (`False` by default).
proxies (`Any`, `optional`):
Proxies to use for the request.
base_url (`str`, `optional`):
Base URL to run inference. This is a duplicated argument from `model` to make [`InferenceClient`]
follow the same pattern as `openai.OpenAI` client. Cannot be used if `model` is set. Defaults to None.
api_key (`str`, `optional`):
Token to use for authentication. This is a duplicated argument from `token` to make [`InferenceClient`]
follow the same pattern as `openai.OpenAI` client. Cannot be used if `token` is set. Defaults to None.
NF)�token�timeout�headers�cookies� trust_env�proxies�base_url�api_key�modelrL rM rN rO rP rQ rR rS �returnc �J � |�
|�t d� �|�
| �t d� �|| _ |�|n| | _ t t | j �� � | _ |�| j
j
|� || _ || _ || _ || _
|| _ t � | _
y )Nad Received both `model` and `base_url` arguments. Please provide only one of them. `base_url` is an alias for `model` to make the API compatible with OpenAI's client. If using `base_url` for chat completion, the `/chat/completions` suffix path will be appended to the base url. When passing a URL as `model`, the client will not append any suffix path to it.z�Received both `token` and `api_key` arguments. Please provide only one of them. `api_key` is an alias for `token` to make the API compatible with OpenAI's client. It has the exact same behavior as `token`.)rL )�
ValueErrorrT rL r
rB rN �updaterO rM rP rQ rR �dict� _sessions)
�selfrT rL rM rN rO rP rQ rR rS s
�~C:\Users\noahv\Documents\GitHub\clickup-operator\.venv\Lib\site-packages\huggingface_hub/inference/_generated/_async_client.py�__init__zAsyncInferenceClient.__init__� s� � � ���!5��d��
� ���!4��>��
� %*��
�6;�6G�U�W��
�*�+;�$�*�*�+M�N������L�L����(�������"������ !��
� HL�v��� c �X � d| j r| j nd� d| j � d�S )Nz<InferenceClient(model='� z', timeout=z)>)rT rM �r[ s r\ �__repr__zAsyncInferenceClient.__repr__� s- � �)��
�
�$�*�*��)K�;�W[�Wc�Wc�Vd�df�g�gr^ .)�json�datarT �task�streamrc rd re rf c � � K � y �w�N� �r[ rc rd rT re rf s r\ �postzAsyncInferenceClient.post� s � �� � �� �Tc � � K � y �wrh ri rj s r\ rk zAsyncInferenceClient.post� s � �� � #�rl c � � K � y �wrh ri rj s r\ rk zAsyncInferenceClient.post� s � �� � .1�rl c � �2 K � t � }| j ||� }|�|�t j d� t � }|t
v r d|vrd|d<