mirror of
https://github.com/open-webui/open-webui
synced 2025-06-16 19:31:52 +00:00
Isolated fix to single section
This commit is contained in:
parent
ba0088f39b
commit
88c8ea883c
@ -1980,28 +1980,38 @@ async def process_chat_response(
|
|||||||
tools = metadata.get("tools", {})
|
tools = metadata.get("tools", {})
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for tool_call in response_tool_calls:
|
for tool_call in response_tool_calls:
|
||||||
tool_call_id = tool_call.get("id", "")
|
tool_call_id = tool_call.get("id", "")
|
||||||
tool_name = tool_call.get("function", {}).get("name", "")
|
tool_name = tool_call.get("function", {}).get("name", "")
|
||||||
|
tool_call_args = tool_call.get("function", {}).get("arguments", "{}")
|
||||||
|
|
||||||
tool_function_params = {}
|
tool_function_params = {}
|
||||||
try:
|
try:
|
||||||
# json.loads cannot be used because some models do not produce valid JSON
|
# json.loads cannot be used because some models do not produce valid JSON
|
||||||
tool_function_params = ast.literal_eval(
|
tool_function_params = ast.literal_eval(
|
||||||
tool_call.get("function", {}).get("arguments", "{}")
|
tool_call_args
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(e)
|
log.debug(e)
|
||||||
# Fallback to JSON parsing
|
# Fallback to JSON parsing
|
||||||
try:
|
try:
|
||||||
tool_function_params = json.loads(
|
tool_function_params = json.loads(
|
||||||
tool_call.get("function", {}).get("arguments", "{}")
|
tool_call_args
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(
|
log.error(
|
||||||
f"Error parsing tool call arguments: {tool_call.get('function', {}).get('arguments', '{}')}"
|
f"Error parsing tool call arguments: {tool_call_args}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Mutate the original tool call response params as they are passed back to the passed
|
||||||
|
# back to the LLM via the content blocks. If they are in a json block and are invalid json,
|
||||||
|
# this can cause downstream LLM integrations to fail (e.g. bedrock gateway) where response
|
||||||
|
# params are not valid json.
|
||||||
|
# Main case so far is no args = "" = invalid json.
|
||||||
|
log.debug(f"Parsed args from {tool_call_args} to {tool_function_params}")
|
||||||
|
tool_call.setdefault("function", {})["arguments"] = json.dumps(tool_function_params)
|
||||||
|
|
||||||
tool_result = None
|
tool_result = None
|
||||||
|
|
||||||
if tool_name in tools:
|
if tool_name in tools:
|
||||||
|
Loading…
Reference in New Issue
Block a user