o
    ưidW                  /   @   s  d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ ddl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mZmZmZmZ dd	lm Z  dd
l!m"Z" e"																	d.dee# dee# dee deee  dee# dee	e#ef  dee$ dee$ dee$ deee#  dee	e#ef  dee# dee# dee	e#ef  dee	e#ef  deee%ej&f  dee# deeee f f$ddZ'e"																	d.dee# dee# dee deee  dee# dee	e#ef  dee$ dee$ dee$ deee#  dee	e#ef  dee# dee# dee	e#ef  dee	e#ef  deee%ej&f  dee# deee
e eeeeeee f f f f$dd Z(e"			d/d!e#dee	e#ef  deee%ej&f  dee# def
d"d#Z)e"			d/d!e#dee	e#ef  deee%ej&f  dee# deeeeeef f f
d$d%Z*e"			d/d!e#dee	e#ef  deee%ej&f  dee# def
d&d'Z+e"			d/d!e#dee	e#ef  deee%ej&f  dee# deeeeeef f f
d(d)Z,e"			d/d!e#dee	e#ef  deee%ej&f  dee# def
d*d+Z-e"			d/d!e#dee	e#ef  deee%ej&f  dee# deeeeeef f f
d,d-Z.dS )0a  
LiteLLM Interactions API - Main Module

Per OpenAPI spec (https://ai.google.dev/static/api/interactions.openapi.json):
- Create interaction: POST /{api_version}/interactions
- Get interaction: GET /{api_version}/interactions/{interaction_id}
- Delete interaction: DELETE /{api_version}/interactions/{interaction_id}

Usage:
    import litellm
    
    # Create an interaction with a model
    response = litellm.interactions.create(
        model="gemini-2.5-flash",
        input="Hello, how are you?"
    )
    
    # Create an interaction with an agent
    response = litellm.interactions.create(
        agent="deep-research-pro-preview-12-2025",
        input="Research the current state of cancer research"
    )
    
    # Async version
    response = await litellm.interactions.acreate(...)
    
    # Get an interaction
    response = litellm.interactions.get(interaction_id="...")
    
    # Delete an interaction
    result = litellm.interactions.delete(interaction_id="...")
    N)partial)AnyAsyncIterator	CoroutineDictIteratorListOptionalUnion)interactions_http_handler)InteractionsAPIRequestUtils$get_provider_interactions_api_config)Logging)CancelInteractionResultDeleteInteractionResultInteractionInputInteractionsAPIResponse InteractionsAPIStreamingResponseInteractionTool)GenericLiteLLMParams)clientmodelagentinputtoolssystem_instructiongeneration_configstreamstore
backgroundresponse_modalitiesresponse_formatresponse_mime_typeprevious_interaction_idextra_headers
extra_bodytimeoutcustom_llm_providerreturnc              
      s>  t  }zt }d|d< |du r#| r#tj| |ddd\}}}}n|du r)d}ttfi d| d|d	|d
|d|d|d|d|d|d|	d|
d|d|d|d|d|d||}t	 }t|j
|}|d|I dH }t|r|I dH }|W S |}|W S  ty } z
tj| ||||dd}~ww )a  
    Async: Create a new interaction using Google's Interactions API.
    
    Per OpenAPI spec, provide either `model` or `agent`.
    
    Args:
        model: The model to use (e.g., "gemini-2.5-flash")
        agent: The agent to use (e.g., "deep-research-pro-preview-12-2025")
        input: The input content (string, content object, or list)
        tools: Tools available for the model
        system_instruction: System instruction for the interaction
        generation_config: Generation configuration
        stream: Whether to stream the response
        store: Whether to store the response for later retrieval
        background: Whether to run in background
        response_modalities: Requested response modalities (TEXT, IMAGE, AUDIO)
        response_format: JSON schema for response format
        response_mime_type: MIME type of the response
        previous_interaction_id: ID of previous interaction for continuation
        extra_headers: Additional headers
        extra_body: Additional body parameters
        timeout: Request timeout
        custom_llm_provider: Override the LLM provider
        
    Returns:
        InteractionsAPIResponse or async iterator for streaming
    Tacreate_interactionNapi_base)r   r*   geminir   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r   r'   Zoriginal_exceptionZcompletion_kwargsextra_kwargs)localsasyncioget_event_looplitellmget_llm_providergetr   createcontextvarscopy_contextrunrun_in_executoriscoroutine	Exceptionexception_type)r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   kwargs
local_varsloop_funcctxfunc_with_contextinit_responseresponsee rF   P/home/app/Keep/.python/lib/python3.10/site-packages/litellm/interactions/main.pyacreateI   s   <	


rH   c                 K   s>  t  }z|d}|dd}|dddu }tdi |}| r0tj| ||j|jd\} }}}n|p3d}t|| d	}|	| t
|}|d
ksL|du rgddlm} | }|jd| p[d|||||d|W S |j| t|d|i|d tj| ||||||||||||d}|W S  ty } z
tj| ||||dd}~ww )a  
    Sync: Create a new interaction using Google's Interactions API.
    
    Per OpenAPI spec, provide either `model` or `agent`.
    
    Args:
        model: The model to use (e.g., "gemini-2.5-flash")
        agent: The agent to use (e.g., "deep-research-pro-preview-12-2025")
        input: The input content (string, content object, or list)
        tools: Tools available for the model
        system_instruction: System instruction for the interaction
        generation_config: Generation configuration
        stream: Whether to stream the response
        store: Whether to store the response for later retrieval
        background: Whether to run in background
        response_modalities: Requested response modalities (TEXT, IMAGE, AUDIO)
        response_format: JSON schema for response format
        response_mime_type: MIME type of the response
        previous_interaction_id: ID of previous interaction for continuation
        extra_headers: Additional headers
        extra_body: Additional body parameters
        timeout: Request timeout
        custom_llm_provider: Override the LLM provider
        
    Returns:
        InteractionsAPIResponse or iterator for streaming
    litellm_logging_objlitellm_call_idNr)   FT)r   r'   r*   api_keyr+   )providerr   Zlitellm_responsesr   )#LiteLLMResponsesInteractionsHandler )r   r   optional_paramsr'   	_is_asyncr   r   rO   litellm_paramsr'   )r   r   r   interactions_api_configrO   r'   rR   logging_objr$   r%   r&   rP   r   r,   rF   )r.   r3   popr   r1   r2   r*   rK   r   updater   Z.get_requested_interactions_api_optional_paramsZ=litellm.interactions.litellm_responses_transformation.handlerrM   Zinteractions_api_handlerupdate_environment_variablesdictr   Zcreate_interactionr:   r;   )r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r<   r=   rI   rJ   rP   rR   r?   rS   rO   rM   handlerrD   rE   rF   rF   rG   r4      s   @


r4   interaction_idc              
         t  }z<t }d|d< ttf| |||pdd|}t }t|j|}	|d|	I dH }
t	|
r<|
I dH }|W S |
}|W S  t
yX } ztjd|pNd|||dd}~ww )z$Async: Get an interaction by its ID.Taget_interactionr+   rZ   r$   r&   r'   Nr,   )r.   r/   r0   r   r3   r5   r6   r7   r8   r9   r:   r1   r;   rZ   r$   r&   r'   r<   r=   r>   r@   rA   rB   rC   rD   rE   rF   rF   rG   agetR  B   		

r_   c              
   K      t  }|pd}zE|d}|dd}|dddu }tdi |}	t|d}
|
du r2td	| |jdd
| id|i|d tj| |
||	||||dW S  t	yb } z
t
jd||||dd}~ww )z#Sync: Get an interaction by its ID.r+   rI   rJ   Nr\   FTrL   $Interactions API not supported for: rZ   rQ   rZ   rS   r'   rR   rT   r$   r&   rP   r,   rF   )r.   r3   rU   r   r   
ValueErrorrW   r   Zget_interactionr:   r1   r;   rZ   r$   r&   r'   r<   r=   rI   rJ   rP   rR   rS   rE   rF   rF   rG   r3   }  L   	

r3   c              
      r[   )z'Async: Delete an interaction by its ID.Tadelete_interactionr+   r]   Nr,   )r.   r/   r0   r   deleter5   r6   r7   r8   r9   r:   r1   r;   r^   rF   rF   rG   adelete  r`   rj   c              
   K   ra   )z&Sync: Delete an interaction by its ID.r+   rI   rJ   Nrh   FTrb   rc   rZ   rQ   rd   r,   rF   )r.   r3   rU   r   r   re   rW   r   Zdelete_interactionr:   r1   r;   rf   rF   rF   rG   ri     rg   ri   c              
      r[   )z'Async: Cancel an interaction by its ID.Tacancel_interactionr+   r]   Nr,   )r.   r/   r0   r   cancelr5   r6   r7   r8   r9   r:   r1   r;   r^   rF   rF   rG   acancel  r`   rm   c              
   K   ra   )z&Sync: Cancel an interaction by its ID.r+   rI   rJ   Nrk   FTrb   rc   rZ   rQ   rd   r,   rF   )r.   r3   rU   r   r   re   rW   r   Zcancel_interactionr:   r1   r;   rf   rF   rF   rG   rl   G  rg   rl   )NNNNNNNNNNNNNNNNN)NNN)/__doc__r/   r5   	functoolsr   typingr   r   r   r   r   r   r	   r
   Zhttpxr1   Z!litellm.interactions.http_handlerr   Zlitellm.interactions.utilsr   r   Z*litellm.litellm_core_utils.litellm_loggingr   ZLiteLLMLoggingObjZlitellm.types.interactionsr   r   r   r   r   r   Zlitellm.types.routerr   Zlitellm.utilsr   strboolfloatTimeoutrH   r4   r_   r3   rj   ri   rm   rl   rF   rF   rF   rG   <module>   s   !( 
	
q
	
 *9*9*