o
    ưiM$                     @   s   d dl mZmZ d dlmZmZmZmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ e
r8d dlmZ G dd	 d	eZG d
d deZdS )    )ABCabstractmethod)AnyDictListOptionalTuple)TYPE_CHECKING	TypedDict)AllMessageValues)
PromptSpec)StandardCallbackDynamicParams)Loggingc                   @   sV   e Zd ZU ee ed< ee ed< ee ed< eeee	f  ed< eee  ed< dS )PromptManagementClient	prompt_idprompt_templateprompt_template_modelprompt_template_optional_paramscompleted_messagesN)
__name__
__module____qualname__r   str__annotations__r   r   r   r    r   r   b/home/app/Keep/.python/lib/python3.10/site-packages/litellm/integrations/prompt_management_base.pyr      s   
 r   c                    @   s  e Zd ZeedefddZedee dee de	de
fddZe				d+dee dee d
ee de	dee dee defddZe						d,dee d
ee de	dee dee dee defddZdee dee dee fddZ						d,ded
ee dee de	dee dee dee defddZ						d,dee d
ee dee de	dee dee dee defddZdededefddZ		d-dedee deded ee
 d!ee
 fd"d#Z								d.dedee dedee d
ee de	dee dee dee d ee
 d!ee
 deeee ef fd$d%Z										d/dedee dedee d
ee de	d&d'dee d(eee  dee dee d ee
 d!ee
 deeee ef fd)d*Zd	S )0PromptManagementBasereturnc                 C      d S Nr   )selfr   r   r   integration_name   s   z%PromptManagementBase.integration_namer   prompt_specdynamic_callback_paramsc                 C   r   r   r   )r    r   r"   r#   r   r   r   should_run_prompt_management   s   z1PromptManagementBase.should_run_prompt_managementNprompt_variablesprompt_labelprompt_versionc                 C   r   r   r   )r    r   r"   r%   r#   r&   r'   r   r   r   _compile_prompt_helper%   s   
z+PromptManagementBase._compile_prompt_helperc                    s   d S r   r   )r    r   r%   r#   r"   r&   r'   r   r   r   async_compile_prompt_helper1   s   
z0PromptManagementBase.async_compile_prompt_helperr   client_messagesc                 C   s   || S r   r   )r    r   r*   r   r   r   merge_messages=   s   z#PromptManagementBase.merge_messagesc                 C   sr   | j ||||||d}z|d | }	W n ty2 }
 ztd|
 d| d| d| d| 
d }
~
ww |	|d< |S 	N)r   r"   r%   r#   r&   r'   r   zError compiling prompt: z. Prompt id=z, prompt_variables=z, client_messages=z, dynamic_callback_params=r   )r(   	Exception
ValueError)r    r   r%   r*   r#   r&   r'   r"   compiled_prompt_clientmessageser   r   r   compile_promptD   s$   	 z#PromptManagementBase.compile_promptc                    sz   | j ||||||dI d H }z|d | }	W n ty6 }
 ztd|
 d| d| d| d| 
d }
~
ww |	|d< |S r,   )r)   r-   r.   )r    r   r%   r*   r#   r"   r&   r'   r/   r0   r1   r   r   r   async_compile_promptb   s&   
	 z)PromptManagementBase.async_compile_promptprompt_management_clientmodelc                 C   s(   |d d ur
|d S | d| jdS )Nr   z{}/ )replaceformatr!   )r    r4   r5   r   r   r   _get_model_from_prompt   s   z+PromptManagementBase._get_model_from_promptFr0   non_default_paramsignore_prompt_manager_model%ignore_prompt_manager_optional_paramsc           
      C   sN   |d p|}|d pi }i ||s|ni }	|s | j ||d}n|}|||	fS )Nr   r   )r4   r5   )r9   )
r    r   r0   r:   r5   r;   r<   r   r   Zupdated_non_default_paramsr   r   r   post_compile_prompt_processing   s    	
	
z3PromptManagementBase.post_compile_prompt_processingc                 C   sV   |d u rt d| j|||ds|||fS | j||||||	d}| j|||||
|dS )Nz6prompt_id is required for Prompt Management Base classr   r"   r#   )r   r%   r*   r#   r&   r'   r   r0   r:   r5   r;   r<   )r.   r$   r2   r=   )r    r5   r0   r:   r   r%   r#   r"   r&   r'   r;   r<   r   r   r   r   get_chat_completion_prompt   s0   
	z/PromptManagementBase.get_chat_completion_promptlitellm_logging_objLiteLLMLoggingObjtoolsc              	      sP   | j |||ds|||fS | j||||||
|dI d H }| j||||||dS )Nr>   )r   r%   r*   r#   r"   r&   r'   r?   )r$   r3   r=   )r    r5   r0   r:   r   r%   r#   rA   r"   rC   r&   r'   r;   r<   r   r   r   r    async_get_chat_completion_prompt   s0   

z5PromptManagementBase.async_get_chat_completion_prompt)NN)NNN)FF)NNNFF)NNNNFF)r   r   r   propertyr   r   r!   r   r   r   boolr$   dictintr   r(   r)   r   r   r+   r2   r3   r9   r=   r   r@   r   rD   r   r   r   r   r      sr   
	
$	


)	

3	

r   N)abcr   r   typingr   r   r   r   r   Ztyping_extensionsr	   r
   Zlitellm.types.llms.openair   Z"litellm.types.prompts.init_promptsr   Zlitellm.types.utilsr   Z*litellm.litellm_core_utils.litellm_loggingr   rB   r   r   r   r   r   r   <module>   s    