o
    ưi!                     @   s   d dl Z d dlmZmZmZ d dlZd dlmZmZm	Z	 d dl
mZ ddlmZ e Zdddi fdeded	ed
ededededeeeef  fddZdd Zdd ZdS )    N)CallableOptionalUnion)AsyncHTTPHandlerHTTPHandler_get_httpx_client)ModelResponse   )NLPCloudConfigmodelmessagesapi_basemodel_responseprint_verboseoptional_paramslitellm_paramsclientc                 C   s   t j||| |||	d}tj }| D ]\}}||vr |||< q|}d}| } ||  | }t j| |||	|d}|jd ||||dd |d u sLt|t	sOt
 }|j||t|d|v r_|d ndd}d|v rq|d d	u rqt|S t j| ||||||||	|d

S )N)api_keyheadersr   r   r   r   z/generation)r   r   r   r   r   )Zcomplete_input_dictr   r   )inputr   Zadditional_argsstreamF)r   datar   T)
r   Zraw_responser   logging_objr   Zrequest_datar   r   r   encoding)
nlp_configZvalidate_environmentlitellmr
   Z
get_configitemsZtransform_requestZpre_call
isinstancer   r   postjsondumpsclean_and_iterate_chunksZtransform_response)r   r   r   r   r   r   r   r   r   r   Z	logger_fnZdefault_max_tokens_to_sampler   r   configkvZcompletion_url_fragment_1Zcompletion_url_fragment_2Zcompletion_urlr   response r&   Z/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/nlp_cloud/chat/handler.py
completion   sl   

	
r(   c                 c   sl    d}| j ddD ] }|s n||7 }d|v r)|dd}|dV  d}d|v sq	|r4|dV  d S d S )N    i   )
chunk_size    zutf-8)iter_contentreplacedecode)r%   bufferchunkr&   r&   r'   r!   o   s   r!   c                   C   s   d S )Nr&   r&   r&   r&   r'   	embedding   s   r1   )r   typingr   r   r   r   Z&litellm.llms.custom_httpx.http_handlerr   r   r   Zlitellm.utilsr   Ztransformationr
   r   strlistdictr(   r!   r1   r&   r&   r&   r'   <module>   s<    	

^