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>
pull/6605/head
Laurentiu Piciu 1 year ago committed by GitHub
parent fcccde406d
commit d9670a5945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save