
    AHjV              /          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jL                  f      dee#   deeee   f   f$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jL                  f      dee#   deee
e   eeeeeee   f   f   f   f$d       Z(e"	 	 	 d'de#dee	e#ef      deee%ejL                  f      dee#   def
d        Z)e"	 	 	 d'de#dee	e#ef      deee%ejL                  f      dee#   deeeeeef   f   f
d!       Z*e"	 	 	 d'de#dee	e#ef      deee%ejL                  f      dee#   def
d"       Z+e"	 	 	 d'de#dee	e#ef      deee%ejL                  f      dee#   deeeeeef   f   f
d#       Z,e"	 	 	 d'de#dee	e#ef      deee%ejL                  f      dee#   def
d$       Z-e"	 	 	 d'de#dee	e#ef      deee%ejL                  f      dee#   deeeeeef   f   f
d%       Z.y)(a  
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                 r  K   t               }	 t        j                         }d|d<   |/| r-t        j                  | |j                  dd            \  }}}}n|d}t        t        fi d| d|d	|d
|d|d|d|d|d|d|	d|
d|d|d|d|d|d||}t        j                         }t        |j                  |      }|j                  d|       d{   }t        j                  |      r| d{   }|S |}|S 7 )7 # t        $ r}t        j                  | ||||      d}~ww xY 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(   original_exception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es                              Q/root/tools/cai/cai_env/lib/python3.12/site-packages/litellm/interactions/main.pyacreaterK   @   s    x J2
%%'(,$%&5+2+C+CfjjT&B,(A"Aq !("*

 
 	

 
  2
 0
 
 
 "
 !4
 ,
  2
 %<
 (
  "!
" #
$ !4'
, &&(#CGGT2"2249JKK}-**H  %H L +
  
$$ 3 (
 	

sY   D7CD DD =D
>D D7D D7D 
D 	D4D//D44D7c                    t               }	 |j                  d      }|j                  dd      }|j                  dd      du }t        di |}| r3t	        j
                  | ||j                  |j                        \  } }}}n|xs d}t        || 	      }|j                  |       t        j                  |      }|d
k(  s|*ddlm}  |       } |j                  d| xs d|||||d|S |j                  || t!        |      d|i|       t#        j$                  | ||||||||||||      }|S # t&        $ r}t	        j(                  | ||||      d}~ww xY 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   litellm_responsesr   )#LiteLLMResponsesInteractionsHandler )r   r   optional_paramsr(   	_is_asyncr   r@   r   rT   litellm_paramsr(   )r   r   r   interactions_api_configrT   r(   rW   logging_objr%   r&   r'   rU   r   r.    )r2   r7   popr   r5   r6   r,   rO   r   updater   .get_requested_interactions_api_optional_params=litellm.interactions.litellm_responses_transformation.handlerrR   interactions_api_handlerupdate_from_kwargsdictr   create_interactionr>   r?   )r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r@   rA   rM   rN   rU   rW   rC   rX   rT   rR   handlerrH   rI   s                                 rJ   r8   r8      s   H JT
17<Q1R)/4Et)LJJ4e<D	-77/6/G/G$7'00&..	0,E&1 #6"A"F(#
 	&!'VV 	  #66&. :;G3733 kr /$7#   	.. 1-? 3 	/ 	
 -??$;+ 3)+'!
   
$$ 3 (
 	

s   C D2 -AD2 2	E;EEinteraction_idc                   K   t               }	 t        j                         }d|d<   t        t        f| |||xs dd|}t        j                         }t        |j                  |      }	|j                  d|	       d{   }
t        j                  |
      r|
 d{   }|S |
}|S 7 )7 # t        $ r#}t        j                  d|xs d|||      d}~ww xY ww)z$Async: Get an interaction by its ID.Taget_interactionr-   rd   r%   r'   r(   Nr.   )r2   r3   r4   r   r7   r9   r:   r;   r<   r=   r>   r5   r?   rd   r%   r'   r(   r@   rA   rB   rD   rE   rF   rG   rH   rI   s                rJ   agetri   T  s      J
%%'%)!"
)' 3 ?x
 
 &&(#CGGT2"2249JKK}-**H  %H L +
  
$$ 3 ?x (
 	

Y   CA1B- ?B) B- B+B- $C%B- (C)B- +B- -	C6CCCc           
         t               }|xs d}	 |j                  d      }|j                  dd      }|j                  dd      du }t        di |}	t	        |      }
|
t        d	|       |j                  |dd
| id|i|       t        j                  | |
||	||||      S # t        $ r}t        j                  d||||      d}~ww xY w)z#Sync: Get an interaction by its ID.r-   rM   rN   Nrf   FTrP   $Interactions API not supported for: rd   rV   rd   rX   r(   rW   rY   r%   r'   rU   r.   rZ   )r2   r7   r[   r   r   
ValueErrorr`   r   get_interactionr>   r5   r?   rd   r%   r'   r(   r@   rA   rM   rN   rU   rW   rX   rI   s               rJ   r7   r7     s    J-9)
17<Q1R)/4Et)LJJ159TA	-77"F(#
 #*67J6KL  	..-~>-? 3 	/ 	
 )88)$; 3)+'	
 		
  
$$ 3 (
 	

   BB' '	C0C

Cc                   K   t               }	 t        j                         }d|d<   t        t        f| |||xs dd|}t        j                         }t        |j                  |      }	|j                  d|	       d{   }
t        j                  |
      r|
 d{   }|S |
}|S 7 )7 # t        $ r#}t        j                  d|xs d|||      d}~ww xY ww)z'Async: Delete an interaction by its ID.Tadelete_interactionr-   rg   Nr.   )r2   r3   r4   r   deleter9   r:   r;   r<   r=   r>   r5   r?   rh   s                rJ   adeleterv           J
%%'(,$%
)' 3 ?x
 
 &&(#CGGT2"2249JKK}-**H  %H L +
  
$$ 3 ?x (
 	

rj   c           
         t               }|xs d}	 |j                  d      }|j                  dd      }|j                  dd      du }t        di |}	t	        |      }
|
t        d	|       |j                  |dd
| id|i|       t        j                  | |
||	||||      S # t        $ r}t        j                  d||||      d}~ww xY w)z&Sync: Delete an interaction by its ID.r-   rM   rN   Nrt   FTrl   rm   rd   rV   rn   r.   rZ   )r2   r7   r[   r   r   ro   r`   r   delete_interactionr>   r5   r?   rq   s               rJ   ru   ru         J-9)
17<Q1R)/4Et)LJJ4e<D	-77"F(#
 #*67J6KL  	..-~>-? 3 	/ 	
 );;)$; 3)+'	
 		
  
$$ 3 (
 	

rr   c                   K   t               }	 t        j                         }d|d<   t        t        f| |||xs dd|}t        j                         }t        |j                  |      }	|j                  d|	       d{   }
t        j                  |
      r|
 d{   }|S |
}|S 7 )7 # t        $ r#}t        j                  d|xs d|||      d}~ww xY ww)z'Async: Cancel an interaction by its ID.Tacancel_interactionr-   rg   Nr.   )r2   r3   r4   r   cancelr9   r:   r;   r<   r=   r>   r5   r?   rh   s                rJ   acancelr~   $  rw   rj   c           
         t               }|xs d}	 |j                  d      }|j                  dd      }|j                  dd      du }t        di |}	t	        |      }
|
t        d	|       |j                  |dd
| id|i|       t        j                  | |
||	||||      S # t        $ r}t        j                  d||||      d}~ww xY w)z&Sync: Cancel an interaction by its ID.r-   rM   rN   Nr|   FTrl   rm   rd   rV   rn   r.   rZ   )r2   r7   r[   r   r   ro   r`   r   cancel_interactionr>   r5   r?   rq   s               rJ   r}   r}   O  rz   rr   )NNNNNNNNNNNNNNNNN)NNN)/__doc__r3   r9   	functoolsr   typingr   r   r   r   r   r	   r
   r   httpxr5   !litellm.interactions.http_handlerr   litellm.interactions.utilsr   r   *litellm.litellm_core_utils.litellm_loggingr   LiteLLMLoggingObjlitellm.types.interactionsr   r   r   r   r   r   litellm.types.routerr   litellm.utilsr   strboolfloatTimeoutrK   r8   ri   r7   rv   ru   r~   r}   rZ       rJ   <module>r      s  B    W W W   G T  6     (,-1(,26! !%/304(,-1.2+/59)-;n
C=n
 C=n

 $%n
 D)*n
 !n
  S#X/n
 TNn
 D>n
" #n
& "$s),'n
( d38n-)n
* !+n
. &c]/n
2 DcN+3n
4 c3h(5n
6 eE5==0127n
: "#;n
> "M2R$SST?n
 n
b   (,-1(,26! !%/304(,-1.2+/59)-;Y
C=Y
 C=Y

 $%Y
 D)*Y
 !Y
  S#X/Y
 TNY
 D>Y
" #Y
& "$s),'Y
( d38n-)Y
* !+Y
. &c]/Y
2 DcN+3Y
4 c3h(5Y
6 eE5==0127Y
: "#;Y
> -.%}5U'VVW	Y?Y
 Y
B  /359)-	'
'
DcN+'
 eE5==012'
 "#	'
 '
 '
T  /359)-	4
4
DcN+4
 eE5==0124
 "#	4
 "Ic38O.O$PPQ4
 4
x  /359)-	'
'
DcN+'
 eE5==012'
 "#	'
 '
 '
T  /359)-	4
4
DcN+4
 eE5==0124
 "#	4
 "Ic38O.O$PPQ4
 4
x  /359)-	'
'
DcN+'
 eE5==012'
 "#	'
 '
 '
T  /359)-	4
4
DcN+4
 eE5==0124
 "#	4
 "Ic38O.O$PPQ4
 4
r   