mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-08 06:00:41 +00:00
openai_functions_multi_agent: solved the case when the "arguments" is valid JSON but it does not contain actions
key (#10543)
Description: There are cases when the output from the LLM comes fine (i.e. function_call["arguments"] is a valid JSON object), but it does not contain the key "actions". So I split the validation in 2 steps: loading arguments as JSON and then checking for "actions" in it. --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
fcccde406d
commit
d9670a5945
@ -45,12 +45,21 @@ def _parse_ai_message(message: BaseMessage) -> Union[List[AgentAction], AgentFin
|
||||
|
||||
if function_call:
|
||||
try:
|
||||
tools = json.loads(function_call["arguments"])["actions"]
|
||||
arguments = json.loads(function_call["arguments"])
|
||||
except JSONDecodeError:
|
||||
raise OutputParserException(
|
||||
f"Could not parse tool input: {function_call} because "
|
||||
f"the `arguments` is not valid JSON."
|
||||
)
|
||||
|
||||
try:
|
||||
tools = arguments["actions"]
|
||||
except (TypeError, KeyError):
|
||||
raise OutputParserException(
|
||||
f"Could not parse tool input: {function_call} because "
|
||||
f"the `arguments` JSON does not contain `actions` key."
|
||||
)
|
||||
|
||||
final_tools: List[AgentAction] = []
|
||||
for tool_schema in tools:
|
||||
_tool_input = tool_schema["action"]
|
||||
|
Loading…
Reference in New Issue
Block a user