
    hw                       d dl mZ d dlZd dlZd dlmZ d dlmZ d dl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mZmZ d dlmZ d dlmZ d dlmZm Z m!Z! d dl"m#Z#m$Z$ e
rd dl%Z%d dl&m'Z' d dl(m)Z)  G d de      Z* G d de      Z+ddZ,ddZ-	 	 	 	 ddZ.	 	 	 	 d dZ/ee0e+   e*e0d   e0d   f   Z1 G d dee2e1f         Z3y)!    )annotationsN)Sequence)JSONDecodeError)sleep)TYPE_CHECKINGAnyCallableOptionalUnion)AgentActionAgentFinish)CallbackManager)dumpd)RunnableConfigRunnableSerializableensure_config)BaseTool)convert_to_openai_tool)	BaseModelFieldmodel_validator)Selfoverride)ThreadMessage)RequiredActionFunctionToolCallc                  8    e Zd ZU dZded<   ded<   edd       Zy)OpenAIAssistantFinishzuAgentFinish with run and thread metadata.

    Parameters:
        run_id: Run id.
        thread_id: Thread id.
    strrun_id	thread_idc                     yz]Check if the class is serializable by LangChain.

        Returns:
            False
        F clss    d/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain/agents/openai_assistant/base.pyis_lc_serializablez(OpenAIAssistantFinish.is_lc_serializable,            Nreturnbool__name__
__module____qualname____doc____annotations__classmethodr'   r#   r)   r&   r   r   !   s%     KN r)   r   c                  B    e Zd ZU dZded<   ded<   ded<   edd       Zy)	OpenAIAssistantActionzAgentAction with info needed to submit custom tool output to existing run.

    Parameters:
        tool_call_id: Tool call id.
        run_id: Run id.
        thread_id: Thread id
    r   tool_call_idr   r    c                     yr"   r#   r$   s    r&   r'   z(OpenAIAssistantAction.is_lc_serializableC   r(   r)   Nr*   r-   r#   r)   r&   r5   r5   6   s+     KN r)   r5   c                     	 dd l }  | j                         S # t        $ r}d}t        |      |d }~wt        $ r}d}t        |      |d }~ww xY wNr   zBUnable to import openai, please install with `pip install openai`.zuPlease make sure you are using a v1.1-compatible version of openai. You can install with `pip install "openai>=1.1"`.)openaiOpenAIImportErrorAttributeErrorr:   emsgs      r&   _get_openai_clientrA   M   s\    )v}} &R#A% )< 	 S!q()    	A.AAAc                     	 dd l }  | j                         S # t        $ r}d}t        |      |d }~wt        $ r}d}t        |      |d }~ww xY wr9   )r:   AsyncOpenAIr<   r=   r>   s      r&   _get_openai_async_clientrE   ]   s_    )!v!!## &R#A% )< 	 S!q()rB   c                D    d}t        | t              xr d| v xr | d   |v S )z<Determine if tool corresponds to OpenAI Assistants built-in.)code_interpreterfile_searchtype)
isinstancedict)toolassistants_builtin_toolss     r&   _is_assistants_builtin_toolrN   m   s8      C4 	7t^	7&\55r)   c                2    t        |       r| S t        |       S )zConvert a raw function/class to an OpenAI tool.

    Note that OpenAI assistants supports several built-in tools,
    such as "code_interpreter" and "file_search".
    )rN   r   )rL   s    r&   _get_assistants_toolrP   y   s     #4(!$''r)   r   r   c                     e Zd ZU dZ ee      Zded<   	 dZded<   	 ded<   	 d	Z	d
ed<   	 dZ
ded<   	  ed      d"d       Zedd	 	 	 	 	 	 	 	 	 	 	 	 	 d#d       Ze	 d$	 	 	 	 	 	 	 d%d       Zedd	 	 	 	 	 	 	 	 	 	 	 	 	 d&d       Ze	 d$	 	 	 	 	 	 	 d%d       Z	 	 	 	 d'dZd(dZd)dZd*dZd+dZ	 	 	 	 d'dZd(dZd)dZd*d Zd+d!Zy),OpenAIAssistantRunnablea  Run an OpenAI Assistant.

    Example using OpenAI tools:
        .. code-block:: python

            from langchain_experimental.openai_assistant import OpenAIAssistantRunnable

            interpreter_assistant = OpenAIAssistantRunnable.create_assistant(
                name="langchain assistant",
                instructions="You are a personal math tutor. Write and run code to answer math questions.",
                tools=[{"type": "code_interpreter"}],
                model="gpt-4-1106-preview"
            )
            output = interpreter_assistant.invoke({"content": "What's 10 - 4 raised to the 2.7"})

    Example using custom tools and AgentExecutor:
        .. code-block:: python

            from langchain_experimental.openai_assistant import OpenAIAssistantRunnable
            from langchain.agents import AgentExecutor
            from langchain.tools import E2BDataAnalysisTool


            tools = [E2BDataAnalysisTool(api_key="...")]
            agent = OpenAIAssistantRunnable.create_assistant(
                name="langchain assistant e2b tool",
                instructions="You are a personal math tutor. Write and run code to answer math questions.",
                tools=tools,
                model="gpt-4-1106-preview",
                as_agent=True
            )

            agent_executor = AgentExecutor(agent=agent, tools=tools)
            agent_executor.invoke({"content": "What's 10 - 4 raised to the 2.7"})


    Example using custom tools and custom execution:
        .. code-block:: python

            from langchain_experimental.openai_assistant import OpenAIAssistantRunnable
            from langchain.agents import AgentExecutor
            from langchain_core.agents import AgentFinish
            from langchain.tools import E2BDataAnalysisTool


            tools = [E2BDataAnalysisTool(api_key="...")]
            agent = OpenAIAssistantRunnable.create_assistant(
                name="langchain assistant e2b tool",
                instructions="You are a personal math tutor. Write and run code to answer math questions.",
                tools=tools,
                model="gpt-4-1106-preview",
                as_agent=True
            )

            def execute_agent(agent, tools, input):
                tool_map = {tool.name: tool for tool in tools}
                response = agent.invoke(input)
                while not isinstance(response, AgentFinish):
                    tool_outputs = []
                    for action in response:
                        tool_output = tool_map[action.tool].invoke(action.tool_input)
                        tool_outputs.append({"output": tool_output, "tool_call_id": action.tool_call_id})
                    response = agent.invoke(
                        {
                            "tool_outputs": tool_outputs,
                            "run_id": action.run_id,
                            "thread_id": action.thread_id
                        }
                    )

                return response

            response = execute_agent(agent, tools, {"content": "What's 10 - 4 raised to the 2.7"})
            next_response = execute_agent(agent, tools, {"content": "now add 17.241", "thread_id": response.thread_id})

    )default_factoryr   clientNasync_clientr   assistant_idg     @@floatcheck_every_msFr,   as_agentafter)modec                    | j                   2dd l}| j                  j                  } |j                  |      | _         | S )Nr   )api_key)rU   r:   rT   r]   rD   )selfr:   r]   s      r&   validate_async_clientz-OpenAIAssistantRunnable.validate_async_client   s:    $kk))G 2 2 27 CDr)   )rT   c          
         |xs
 t               }|j                  j                  j                  |||D cg c]  }t	        |       c}|      } | d|j
                  |d|S c c}w )a*  Create an OpenAI Assistant and instantiate the Runnable.

        Args:
            name: Assistant name.
            instructions: Assistant instructions.
            tools: Assistant tools. Can be passed in OpenAI format or as BaseTools.
            model: Assistant model to use.
            client: OpenAI or AzureOpenAI client.
                Will create a default OpenAI client if not specified.
            kwargs: Additional arguments.

        Returns:
            OpenAIAssistantRunnable configured to run using the created assistant.
        nameinstructionstoolsmodel)rV   rT   r#   )rA   beta
assistantscreaterP   id)	r%   rb   rc   rd   re   rT   kwargsrL   	assistants	            r&   create_assistantz(OpenAIAssistantRunnable.create_assistant   so    2 /-/KK**11%:?@$'-@	 2 
	 F	VFvFF As   A$c                "   t        |      }t        j                  |j                  d      |j                  d      |j                  d            }|j	                  t        |       ||j                  d      xs | j                               }	 | j                  r`|j                  d      rO| j                  |d         } | j                  j                  j                  j                  j                  di |}nd|vrNd	|d
   |j                  d      |j                  d      dg|j                  d      d}| j                  ||      }nd|vrd| j                  j                  j                  j                  j!                  |d   |d
   d	|j                  d            }	| j#                  |      }n: | j                  j                  j                  j                  j                  di |}| j%                  |j&                  |j(                        }	 | j/                  |      }|j1                  |       |S # t*        $ r}
|j-                  |
        d}
~
ww xY w# t*        $ r'}
|j-                  |
|j3                                 d}
~
ww xY w)a  Invoke assistant.

        Args:
            input: Runnable input dict that can have:
                content: User message when starting a new run.
                thread_id: Existing thread to use.
                run_id: Existing run to use. Should only be supplied when providing
                    the tool output for a required action after an initial invocation.
                message_metadata: Metadata to associate with new message.
                thread_metadata: Metadata to associate with new thread. Only relevant
                    when new thread being created.
                instructions: Additional run instructions.
                model: Override Assistant model for this run.
                tools: Override Assistant tools for this run.
                parallel_tool_calls: Allow Assistant to set parallel_tool_calls
                    for this run.
                top_p: Override Assistant top_p for this run.
                temperature: Override Assistant temperature for this run.
                max_completion_tokens: Allow setting max_completion_tokens for this run.
                max_prompt_tokens: Allow setting max_prompt_tokens for this run.
                run_metadata: Metadata to associate with new run.
                attachments: A list of files attached to the message, and the
                    tools they should be added to.
            config: Runnable config. Defaults to None.

        Return:
            If self.as_agent, will return
                Union[List[OpenAIAssistantAction], OpenAIAssistantFinish].
                Otherwise, will return OpenAI types
                Union[List[ThreadMessage], List[RequiredActionFunctionToolCall]].
        	callbackstagsmetadatainheritable_callbacksinheritable_tagsinheritable_metadatarun_namerb   intermediate_stepsr    usercontentmessage_metadataattachments)rolery   rp   r{   thread_metadatamessagesrp   r   ry   r|   rp   Nrp   r#   )r   r   	configuregeton_chain_startr   get_namerY   _parse_intermediate_stepsrT   rf   threadsrunssubmit_tool_outputs_create_thread_and_runr   rh   _create_run_wait_for_runri   r    BaseExceptionon_chain_error_get_responseon_chain_endrK   r^   inputconfigrj   callback_managerrun_managertool_outputsrunthread_r?   responses               r&   invokezOpenAIAssistantRunnable.invoke  sd   N v&*44"(**["9#ZZ/!'J!7

 '55$KJ':4==? 6 

%	}}+?!@#==./  Hdkk&&..33GGW,WE) %+',Y'7(-		2D(E+099]+C	! !&		*; <
 11%@&KK$$,,55<<+&!),"YY'9:	 =  &&u- Hdkk&&..33GGP%P$$SVVS]];C	))#.H
 $$X.O  	&&q)	
  	&&q388:&>	s1   FH; I ;	III	J'"J		J)rU   c                  K   |xs
 t               }|D cg c]  }t        |       }}|j                  j                  j	                  ||||       d{   }	 | d|	j
                  |d|S c c}w 7 w)a	  Async create an AsyncOpenAI Assistant and instantiate the Runnable.

        Args:
            name: Assistant name.
            instructions: Assistant instructions.
            tools: Assistant tools. Can be passed in OpenAI format or as BaseTools.
            model: Assistant model to use.
            async_client: AsyncOpenAI client.
                Will create default async_client if not specified.

        Returns:
            AsyncOpenAIAssistantRunnable configured to run using the created assistant.
        ra   N)rV   rU   r#   )rE   rP   rf   rg   rh   ri   )
r%   rb   rc   rd   re   rU   rj   rL   openai_toolsrk   s
             r&   acreate_assistantz)OpenAIAssistantRunnable.acreate_assistants  s     4 $A'?'A?DEt,T2EE&++66==%	 > 
 
	 R	<R6RR F
s   A6A/.A6A4A6c                  K   |xs i }t        j                  |j                  d      |j                  d      |j                  d            }|j                  t	        |       ||j                  d      xs | j                               }	 | j                  rq|j                  d      r`| j                  |d          d{   } | j                  j                  j                  j                  j                  di | d{   }nd	|vrFd
|d   |j                  d      dg|j                  d      d}| j                  ||       d{   }nd|vrt| j                  j                  j                  j                  j                  |d	   |d   d
|j                  d             d{   }	| j!                  |       d{   }nB | j                  j                  j                  j                  j                  di | d{   }| j#                  |j$                  |j&                         d{   }	 | j-                  |      }|j/                  |       |S 7 7 a7 7 7 7 d7 8# t(        $ r}
|j+                  |
        d}
~
ww xY w# t(        $ r'}
|j+                  |
|j1                                 d}
~
ww xY ww)a  Async invoke assistant.

        Args:
            input: Runnable input dict that can have:
                content: User message when starting a new run.
                thread_id: Existing thread to use.
                run_id: Existing run to use. Should only be supplied when providing
                    the tool output for a required action after an initial invocation.
                message_metadata: Metadata to associate with a new message.
                thread_metadata: Metadata to associate with new thread. Only relevant
                    when a new thread is created.
                instructions: Overrides the instructions of the assistant.
                additional_instructions: Appends additional instructions.
                model: Override Assistant model for this run.
                tools: Override Assistant tools for this run.
                parallel_tool_calls: Allow Assistant to set parallel_tool_calls
                    for this run.
                top_p: Override Assistant top_p for this run.
                temperature: Override Assistant temperature for this run.
                max_completion_tokens: Allow setting max_completion_tokens for this run.
                max_prompt_tokens: Allow setting max_prompt_tokens for this run.
                run_metadata: Metadata to associate with new run.
            config: Runnable config. Defaults to None.
            kwargs: Additional arguments.

        Return:
            If self.as_agent, will return
                Union[List[OpenAIAssistantAction], OpenAIAssistantFinish].
                Otherwise, will return OpenAI types
                Union[List[ThreadMessage], List[RequiredActionFunctionToolCall]].
        rn   ro   rp   rq   ru   rv   rw   Nr    rx   ry   rz   )r|   ry   rp   r}   r~   r   r   r   r#   )r   r   r   r   r   r   rY   _aparse_intermediate_stepsrU   rf   r   r   r   _acreate_thread_and_runr   rh   _acreate_run_await_for_runri   r    r   r   r   r   rK   r   s               r&   ainvokezOpenAIAssistantRunnable.ainvoke  s    N 2*44"(**["9#ZZ/!'J!7

 '55$KJ':4==? 6 

(	}}+?!@%)%D%D./&   TD--22::??SS "  E) %+',Y'7(-		2D(E! !&		*; <	 !88GG&++0088AAHH+&!),"YY'9:	 I   !--e44 TD--22::??SS   ++CFFCMMBBC	))#.H
 $$X.O[  H 5 C 	&&q)	
  	&&q388:&>	s   B
K4I2 I!AI2 I$A
I2 I'AI2 -I*.I2 I,AI2 	I.
-I2 7I08I2 =J K!I2 $I2 'I2 *I2 ,I2 .I2 0I2 2	J;JJK	K"K  KKc                   |d   \  }}| j                  |j                  |j                        }t               }|j                  r7|j                  j
                  j                  D ch c]  }|j                   }}|D cg c]+  \  }}|j                  |v rt        |      |j                  d- }	}}|	|j                  |j                  dS c c}w c c}}w N)outputr6   )r   r   r    
r   r   r    setrequired_actionr   
tool_callsri   r6   r   
r^   rw   last_actionlast_outputr   required_tool_call_idstcactionr   r   s
             r&   r   z1OpenAIAssistantRunnable._parse_intermediate_steps  s     $6b#9 [  !3!3[5J5JK!$ # 3 3 G G R R&&" &
 #5
""&<< 6{F4G4GH
 
 )!(($..
 	
&
s   'C0Cc                    |j                         D ci c]  \  }}|dv r|| }}} | j                  j                  j                  j                  j
                  |d   fd| j                  i|S c c}}w N)
rc   re   rd   additional_instructionsparallel_tool_callstop_ptemperaturemax_completion_tokensmax_prompt_tokensrun_metadatar    rV   )itemsrT   rf   r   r   rh   rV   r^   
input_dictkvparamss        r&   r   z#OpenAIAssistantRunnable._create_run  s     #((*
1 qD
 
" 4t{{'',,33{#
**
 
 	
#
s   A2c                    |j                         D ci c]  \  }}|dv r|| }}} | j                  j                  j                  j                  d| j
                  |d|S c c}}w N)	rc   re   rd   r   r   r   r   r   r   )rV   r   r#   )r   rT   rf   r   create_and_runrV   r^   r   r   r   r   r   s         r&   r   z.OpenAIAssistantRunnable._create_thread_and_run)  s     #((*
1
 qD
 
  7t{{''66 
**
 
 	
!
s   A%c                d   |j                   dk(  rdd lt        j                  j                  j                  d      d         }t        j                  j                  j                  d      d         }|dkD  xs |dk(  xr |dk\  | j                  j                  j                  j                  j                  |j                  d      }|D cg c]  }|j                  |j                  k(  s|  }}| j                  s|S |D cg c]  }|j                  D ]  }|  }}}|D 	cg c]  }|j                   D ]  }	|	  }
}}	t#        fd|D              rd	j%                  d
 |D              }t'        ||j                  |j                  |
dd|j                  |j                        S |j                   dk(  r| j                  s |j(                  j*                  j,                  S g }|j(                  j*                  j,                  D ]  }|j.                  }	 t1        j2                  |j4                  d      }t=        |      dk(  r	d|v r|d   }|j?                  tA        |j8                  ||j                  d|j                  |j                                |S t1        jB                  |jE                         d      }d|j                    d| }t;        |      c c}w c c}}w c c}	}w # t6        $ r-}d|j4                   d|j8                   }t;        |      |d }~ww xY w)N	completedr   .      ascorderc              3     K   | ]n  }r4t        |j                  j                  j                  j                        n3t        |j                  j                  j                  j
                         p y wNrJ   typesrf   r   TextContentBlockMessageContentText.0ry   r:   version_gte_1_14s     r&   	<genexpr>z8OpenAIAssistantRunnable._get_response.<locals>.<genexpr>Y  f      
  ( w(9(9(A(A(R(RS#))11DD
   A4A7
c              3  H   K   | ]  }|j                   j                    y wr   textvaluer   ry   s     r&   r   z8OpenAIAssistantRunnable._get_response.<locals>.<genexpr>d       "L'7<<#5#5"L    ")r   r    r   r{    return_valueslogr   r    requires_actionFstrict*Received invalid JSON function arguments:  for function __arg1rL   
tool_inputr6   r   r   r       indentUnexpected run status: . Full run info:

)#statusr:   intversionVERSIONsplitrT   rf   r   r   listr    r   ri   rY   ry   r{   alljoinr   r   r   r   functionjsonloads	argumentsr   rb   
ValueErrorlenappendr5   dumpsrK   )r^   r   major_versionminor_versionr   r@   new_messagesmsg_contentanswer
attachmentr{   actions	tool_callr   argsr?   run_infor:   r   s                    @@r&   r   z%OpenAIAssistantRunnable._get_response@  s    ::$ 6 6 < <S A! DEM 6 6 < <S A! DEM - 1  ":}':  {{''//88== > H ,4LCszzSVV7KCLLL==##'3 #s{{8CF  '3"S__7A
K   
  &
 
 "LV"LL($!$!ff#.	 vv--
 
 ::**==**>>IIIG 00DDOO 	$--1::h&8&8GD t9>h$&6>D)%]]#'%.\\"vv"%--	, N::chhj3'

|3GzRo{ MD ' 1D#--.nX]]OM  %S/q01s0   K(4K(K-/K3"!K99	L/(L**L/c                    d}|rf| j                   j                  j                  j                  j	                  ||      }|j
                  dv }|rt        | j                  dz         |rfS NT)r    )in_progressqueuedi  )rT   rf   r   r   retriever   r   rX   r^   r   r    r  r   s        r&   r   z%OpenAIAssistantRunnable._wait_for_run  sf    ++""**//8898UC**(AAKd))D01	 
 
r)   c                  K   |d   \  }}| j                  |j                  |j                        }t               }|j                  r7|j                  j
                  j                  D ch c]  }|j                   }}|D cg c]+  \  }}|j                  |v rt        |      |j                  d- }	}}|	|j                  |j                  dS c c}w c c}}w wr   r   r   s
             r&   r   z2OpenAIAssistantRunnable._aparse_intermediate_steps  s      $6b#9 [  !3!3[5J5JK!$ # 3 3 G G R R&&" &
 #5
""&<< 6{F4G4GH
 
 )!(($..
 	
&
s   A'C)C<C0C3(Cc                  K   |j                         D ci c]  \  }}|dv r|| }}} | j                  j                  j                  j                  j
                  |d   fd| j                  i| d {   S c c}}w 7 
wr   )r   rU   rf   r   r   rh   rV   r   s        r&   r   z$OpenAIAssistantRunnable._acreate_run  s      #((*
1 qD
 
" @T&&++3388??{#
**
 
 
 	
#
"
s   BA<AB7B8Bc                   K   |j                         D ci c]  \  }}|dv r|| }}} | j                  j                  j                  j                  d| j
                  |d| d {   S c c}}w 7 
wr   )r   rU   rf   r   r   rV   r   s         r&   r   z/OpenAIAssistantRunnable._acreate_thread_and_run  s      #((*
1
 qD
 
  CT&&++33BB 
**
 
 
 	
!
 
s   A7A/AA7*A5+A7c                0  K   |j                   dk(  rdd lt        j                  j                  j                  d      d         }t        j                  j                  j                  d      d         }|dkD  xs |dk(  xr |dk\  | j                  j                  j                  j                  j                  |j                  d       d {   }|D cg c]  }|j                  |j                  k(  s|  }}| j                  s|S |D cg c]  }|j                  D ]  }|  }}}t!        fd|D              rd	j#                  d
 |D              }t%        ||j                  |j                  dd|j                  |j                        S |j                   dk(  r| j                  s |j&                  j(                  j*                  S g }	|j&                  j(                  j*                  D ]  }
|
j,                  }	 t/        j0                  |j2                  d      }t;        |      dk(  r	d|v r|d   }|	j=                  t?        |j6                  ||
j                  d|j                  |j                                |	S t/        j@                  |jC                         d      }d|j                    d| }t9        |      7 c c}w c c}}w # t4        $ r-}d|j2                   d|j6                   }t9        |      |d }~ww xY ww)Nr   r   r   r   r   r   r   c              3     K   | ]n  }r4t        |j                  j                  j                  j                        n3t        |j                  j                  j                  j
                         p y wr   r   r   s     r&   r   z9OpenAIAssistantRunnable._aget_response.<locals>.<genexpr>  r   r   r   c              3  H   K   | ]  }|j                   j                    y wr   r   r   s     r&   r   z9OpenAIAssistantRunnable._aget_response.<locals>.<genexpr>  r   r   )r   r    r   r   r   r   Fr   r   r   r   r   r   r   r   r   )"r   r:   r   r   r   r   rU   rf   r   r   r   r    r   ri   rY   ry   r   r   r   r   r   r   r   r   r   r   r   rb   r   r   r  r5   r  rK   )r^   r   r  r  r   r@   r  r  r  r	  r
  r   r  r?   r  r:   r   s                  @@r&   _aget_responsez&OpenAIAssistantRunnable._aget_response  s     ::$ 6 6 < <S A! DEM 6 6 < <S A! DEM - 1  ":}':  "..33;;DDII J  H ,4LCszzSVV7KCLLL==##'3 #s{{8CF   
  &
 
 "LV"LL($!$!ff
 vv--	 	 ::**==**>>IIIG 00DDOO 	$--1::h&8&8GD t9>h$&6>D)%]]#'%.\\"vv"%--	, N::chhj3'

|3GzRo{ MB ' 1D#--.nX]]OM  %S/q01s\   CLKLK>KLK1CL	!K*B&LL	L&(LLLc                  K   d}|r| j                   j                  j                  j                  j	                  ||       d {   }|j
                  dv }|r*t        j                  | j                  dz         d {    |rS 7 C7 wr  )	rU   rf   r   r   r  r   asyncior   rX   r  s        r&   r   z&OpenAIAssistantRunnable._await_for_run(  s     ))..66;;DD# E  C **(AAKmmD$7$7$$>???  
 @s*   ABB	9B?B BBB)r+   r   )rb   r   rc   r   rd   Sequence[Union[BaseTool, dict]]re   r   rT   z2Optional[Union[openai.OpenAI, openai.AzureOpenAI]]rj   r   r+   rR   r   )r   rK   r   zOptional[RunnableConfig]rj   r   r+   
OutputType)rb   r   rc   r   rd   r  re   r   rU   z<Optional[Union[openai.AsyncOpenAI, openai.AsyncAzureOpenAI]]rj   r   r+   rR   )rw   z'list[tuple[OpenAIAssistantAction, str]]r+   rK   )r   rK   r+   r   )r   rK   r   rK   r+   r   )r   r   r+   r   )r   r   r    r   r+   r   )r.   r/   r0   r1   r   rA   rT   r2   rU   rX   rY   r   r_   r3   rl   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r#   r)   r&   rR   rR      s   KZ (:;FC;'L#-#NE#;HdF'" #  FJGG G /	G
 G CG G 
!G GB  ,0^^ )^ 	^
 
^ ^@  !S!S !S /	!S
 !S
!S !S 
!!S !SF  ,0aa )a 	a
 
a aF
C
 

,
0
.M^
C
 

,
0
.IV
r)   rR   )r+   zopenai.OpenAI)r+   zopenai.AsyncOpenAI)rL   :Union[dict[str, Any], type[BaseModel], Callable, BaseTool]r+   r,   )rL   r  r+   zdict[str, Any])4
__future__r   r  r   collections.abcr   r   timer   typingr   r   r	   r
   r   langchain_core.agentsr   r   langchain_core.callbacksr   langchain_core.loadr   langchain_core.runnablesr   r   r   langchain_core.toolsr   %langchain_core.utils.function_callingr   pydanticr   r   r   typing_extensionsr   r   r:   openai.types.beta.threadsr   <openai.types.beta.threads.required_action_function_tool_callr   r   r5   rA   rE   rN   rP   r   r  rK   rR   r#   r)   r&   <module>r-     s    "   $     ; 4 % X X ) H 6 6 ,7
K *K .) ) 	
D			
(
D
(
( 		)*,
d
243CD d
r)   