o
    g                     @   s\  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	m
Z
 d dlmZmZmZ d dlmZmZmZ eeZdZi ddd	d	d
d
dddddddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<Zd=d>d?d<ZG d@dA dAeeZG dBdC dCeZG dDdE dEeZdS )F    N)ABCabstractmethod)AnyDictOptionalUnion)	constants)RequestParametersTaskProviderHelper_as_dict)build_hf_headers	get_tokenloggingzhttps://api.together.xyzzdatabricks/dbrx-instructzdeepseek-ai/DeepSeek-R1zdeepseek-ai/DeepSeek-V3z!deepseek-ai/deepseek-llm-67b-chatzgoogle/gemma-2-9b-itzgoogle/gemma-2b-itzgoogle/gemma-2-27b-itzmeta-llama/Llama-2-13b-chat-hfzmeta-llama/Llama-2-7b-chat-hfz(meta-llama/Llama-3.2-11B-Vision-Instructzmeta-llama/Llama-Vision-Freez meta-llama/Llama-3.2-3B-Instructz&meta-llama/Llama-3.2-3B-Instruct-Turboz(meta-llama/Llama-3.2-90B-Vision-Instructz.meta-llama/Llama-3.2-90B-Vision-Instruct-Turboz!meta-llama/Llama-3.3-70B-Instructz'meta-llama/Llama-3.3-70B-Instruct-Turboz$meta-llama/Meta-Llama-3-70B-Instructzmeta-llama/Llama-3-70b-chat-hfz#meta-llama/Meta-Llama-3-8B-Instructz)meta-llama/Meta-Llama-3-8B-Instruct-Turboz'meta-llama/Meta-Llama-3.1-405B-Instructz.meta-llama/Llama-3.2-11B-Vision-Instruct-Turboz&meta-llama/Meta-Llama-3.1-70B-Instructz,meta-llama/Meta-Llama-3.1-70B-Instruct-Turboz%meta-llama/Meta-Llama-3.1-8B-Instructz+meta-llama/Meta-Llama-3.1-8B-Instruct-Turbomicrosoft/WizardLM-2-8x22B"mistralai/Mistral-7B-Instruct-v0.3%mistralai/Mixtral-8x22B-Instruct-v0.1$mistralai/Mixtral-8x7B-Instruct-v0.1+NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO)nvidia/Llama-3.1-Nemotron-70B-Instruct-HFQwen/Qwen2-72B-InstructzQwen/Qwen2.5-72B-Instruct-TurbozQwen/Qwen2.5-7B-Instruct-TurboQwen/Qwen2.5-Coder-32B-InstructQwen/QwQ-32B-Previewz-scb10x/scb10x-llama3-typhoon-v1-5-8b-instructz(scb10x/scb10x-llama3-typhoon-v1-5x-4f316)r   r   r   r   r   r   r   zQwen/Qwen2.5-72B-InstructzQwen/Qwen2.5-7B-Instructr   r   z'scb10x/llama-3-typhoon-v1.5-8b-instructz-scb10x/llama-3-typhoon-v1.5x-70b-instruct-awqmeta-llama/Llama-2-70b-hfmeta-llama/Meta-Llama-3-8Bmistralai/Mixtral-8x7B-v0.1)r   r   r   zblack-forest-labs/FLUX.1-cannyzblack-forest-labs/FLUX.1-depthblack-forest-labs/FLUX.1-devzblack-forest-labs/FLUX.1-reduxzblack-forest-labs/FLUX.1-pro(stabilityai/stable-diffusion-xl-base-1.0)z"black-forest-labs/FLUX.1-Canny-devz"black-forest-labs/FLUX.1-Depth-devr   z"black-forest-labs/FLUX.1-Redux-devz black-forest-labs/FLUX.1-schnellr   )conversationalztext-generationtext-to-imagezv1/chat/completionszv1/completionszv1/images/generationsc                   @   s   e Zd ZdZdefddZdddedeeef d	ed
ee dee deeeef  de	fddZ
d
ee defddZdeeef defddZededeeef deeef fddZdS )TogetherTaskz"Base class for Together API tasks.taskc                 C   s
   || _ d S N)r    )selfr     r#   d/var/www/visachat/venv/lib/python3.10/site-packages/huggingface_hub/inference/_providers/together.py__init__J   s   
zTogetherTask.__init__N)extra_payloadinputs
parametersheadersmodelapi_keyr&   returnc          
      C   s   |d u rt  }|d u rtdi t|d|}|dr*tjjdd}td nt	}td | 
|}d|v r>||d< | j||d	}	t| d
t| j  | j||	d |dS )Nz]You must provide an api_key to work with Together API or log in with `huggingface-cli login`.)tokenhf_together)providerz5Calling Together provider through Hugging Face proxy.z#Calling Together provider directly.r*   )r(   /)urlr    r*   jsondatar)   )r   
ValueErrorr   
startswithr   INFERENCE_PROXY_TEMPLATEformatloggerinfoBASE_URL
_map_model_prepare_payloadr	   PER_TASK_ROUTESr    )
r"   r'   r(   r)   r*   r+   r&   base_urlmapped_modelpayloadr#   r#   r$   prepare_requestM   s0   



zTogetherTask.prepare_requestc                 C   s`   |d u rt d| jtvrt d| j dt| j |}|d u r.t d| d| j d|S )Nz-Please provide a model available on Together.zTask z not supported with Together.zModel z) is not supported with Together for task .)r5   r    SUPPORTED_MODELSget)r"   r*   r@   r#   r#   r$   r<   t   s   
zTogetherTask._map_modelresponsec                 C   s   |S r!   r#   )r"   rF   r#   r#   r$   get_response~      zTogetherTask.get_responsec                 C   s   d S r!   r#   r"   r'   r(   r#   r#   r$   r=      rH   zTogetherTask._prepare_payload)__name__
__module____qualname____doc__strr%   r   r   r   r	   rB   r<   r   bytesrG   r   r=   r#   r#   r#   r$   r   G   s.    
	
'
,r   c                   @   s2   e Zd Zdedeeef deeef fddZdS )TogetherTextGenerationTaskr'   r(   r,   c                 C   s   d|idd |  D S )Nmessagesc                 S      i | ]\}}|d ur||qS r!   r#   .0kvr#   r#   r$   
<dictcomp>       z?TogetherTextGenerationTask._prepare_payload.<locals>.<dictcomp>itemsrI   r#   r#   r$   r=      s   z+TogetherTextGenerationTask._prepare_payloadN)rJ   rK   rL   r   r   rN   r=   r#   r#   r#   r$   rP      s    *rP   c                       s\   e Zd Z fddZdedeeef deeef fddZdee	ef defd	d
Z
  ZS )TogetherTextToImageTaskc                    s   t  d d S )Nr   )superr%   )r"   	__class__r#   r$   r%      s   z TogetherTextToImageTask.__init__r'   r(   r,   c                 C   s    |dddd |  D }|S )Nbase64)promptresponse_formatc                 S   rR   r!   r#   rS   r#   r#   r$   rW      rX   z<TogetherTextToImageTask._prepare_payload.<locals>.<dictcomp>rY   )r"   r'   r(   rA   r#   r#   r$   r=      s   z(TogetherTextToImageTask._prepare_payloadrF   c                 C   s   t |}t|d d d S )Nr4   r   b64_json)r   r_   	b64decode)r"   rF   response_dictr#   r#   r$   rG      s   z$TogetherTextToImageTask.get_response)rJ   rK   rL   r%   r   r   rN   r=   r   rO   rG   __classcell__r#   r#   r]   r$   r[      s    &"r[   )r_   abcr   r   typingr   r   r   r   huggingface_hubr   !huggingface_hub.inference._commonr	   r
   r   huggingface_hub.utilsr   r   r   
get_loggerrJ   r9   r;   rD   r>   r   rP   r[   r#   r#   r#   r$   <module>   s    
	
!2>