o
    ưi'                     @   st   d Z ddlmZmZmZmZmZ ddlZddlm	Z	 ddl
mZmZ ddlmZ ddlmZmZ G dd	 d	e	ZdS )
zY
Re rank api

LiteLLM supports the re rank API format, no paramter transformation occurs
    )AnyDictListOptionalUnionN)BaseLLM)_get_httpx_clientget_async_httpx_client)TogetherAIRerankConfig)RerankRequestRerankResponsec                   @   s   e Zd Z					ddedededeeeeeef f  dee	 d	eee  d
ee
 dee	 dee
 defddZdeeef dedefddZdS )TogetherAIRerankNTFmodelapi_keyquery	documentstop_nrank_fieldsreturn_documentsmax_chunks_per_doc	_is_asyncreturnc
                 C   s   t  }
t||||||d}|jdd}|d urtd|	r#| ||S |
jdddd| d|d	}|jd
kr<t|j|	 }t
 |S )N)r   r   r   r   r   r   T)Zexclude_nonez.TogetherAI does not support max_chunks_per_doc"https://api.together.xyz/v1/rerankapplication/jsonBearer acceptzcontent-typeauthorizationheadersjson   )r   r   dict
ValueErrorasync_rerankpoststatus_code	Exceptiontextr    r
   _transform_response)selfr   r   r   r   r   r   r   r   r   clientZrequest_datarequest_data_dictresponse_json_response r/   ^/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/together_ai/rerank/handler.pyrerank   s4   



zTogetherAIRerank.rerankr,   c                    s\   t tjjd}|jdddd| d|dI d H }|jdkr$t|j| }t	 
|S )N)Zllm_providerr   r   r   r   r   r!   )r	   litellmZLlmProvidersZTOGETHER_AIr%   r&   r'   r(   r    r
   r)   )r*   r,   r   r+   r-   r.   r/   r/   r0   r$   D   s    


zTogetherAIRerank.async_rerank)NNTNF)__name__
__module____qualname__strr   r   r   r   r   intboolr   r1   r$   r/   r/   r/   r0   r      sD    
	

0
r   )__doc__typingr   r   r   r   r   r2   Zlitellm.llms.baser   Z&litellm.llms.custom_httpx.http_handlerr   r	   Z.litellm.llms.together_ai.rerank.transformationr
   Zlitellm.types.rerankr   r   r   r/   r/   r/   r0   <module>   s    