
    Ng	                         d dl mZmZ d dlmZm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 eZdedeee         ef         fd	Z G d
 de          ZdS )    )ListUnion)AgentActionAgentFinish)BaseMessage)ChatGeneration
Generation)MultiActionAgentOutputParser)ToolAgentActionparse_ai_message_to_tool_actionmessagereturnc           
      6   t          |           }t          |t                    r|S g }|D ]m}t          |t                    rA|                    t          |j        |j        |j        |j	        |j
                             X|                    |           n|S )z6Parse an AI message potentially containing tool_calls.)tool
tool_inputlogmessage_logtool_call_id)r   
isinstancer   r   appendOpenAIToolAgentActionr   r   r   r   r   )r   tool_actionsfinal_actionsactions       h/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/agents/output_parsers/openai_tools.py&parse_ai_message_to_openai_tool_actionr      s     37;;L,,, ')M ) )fo.. 	)  %%0
 & 2!'!4        ((((    c            	           e Zd ZdZedefd            Zdddee         de	de
ee         ef         fdZd	ede
ee         ef         fd
ZdS )OpenAIToolsAgentOutputParserat  Parses a message into agent actions/finish.

    Is meant to be used with OpenAI models, as it relies on the specific
    tool_calls parameter from OpenAI to convey what tools to use.

    If a tool_calls parameter is passed, then that is used to get
    the tool names and tool inputs.

    If one is not passed, then the AIMessage is assumed to be the final output.
    r   c                     dS )Nz openai-tools-agent-output-parser )selfs    r   _typez"OpenAIToolsAgentOutputParser._type4   s    11r   F)partialresultr$   c                    t          |d         t                    st          d          |d         j        }t	          |          S )Nr   z6This output parser only works on ChatGeneration output)r   r   
ValueErrorr   r   )r"   r%   r$   r   s       r   parse_resultz)OpenAIToolsAgentOutputParser.parse_result8   sD     &)^44 	WUVVV)#5g>>>r   textc                      t          d          )NzCan only parse messages)r'   )r"   r)   s     r   parsez"OpenAIToolsAgentOutputParser.parse@   s    2333r   N)__name__
__module____qualname____doc__propertystrr#   r   r	   boolr   r   r   r(   r+   r!   r   r   r   r   (   s        	 	 2s 2 2 2 X2 <A? ? ?:&?48?	tK +-	.? ? ? ?4# 4%[(9;(F"G 4 4 4 4 4 4r   r   N)typingr   r   langchain_core.agentsr   r   langchain_core.messagesr   langchain_core.outputsr   r	   langchain.agents.agentr
   %langchain.agents.output_parsers.toolsr   r   r   r   r   r!   r   r   <module>r9      s	           : : : : : : : : / / / / / / = = = = = = = = ? ? ? ? ? ?       
 ( 
4k)*   04 4 4 4 4#? 4 4 4 4 4r   