mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-20 13:05:49 +02:00
Tool Call Error Display (#3897)
This commit is contained in:
@@ -20,6 +20,10 @@ from onyx.utils.logger import setup_logger
|
|||||||
logger = setup_logger()
|
logger = setup_logger()
|
||||||
|
|
||||||
|
|
||||||
|
class ToolCallException(Exception):
|
||||||
|
"""Exception raised for errors during tool calls."""
|
||||||
|
|
||||||
|
|
||||||
def emit_packet(packet: AnswerPacket, writer: StreamWriter) -> None:
|
def emit_packet(packet: AnswerPacket, writer: StreamWriter) -> None:
|
||||||
write_custom_event("basic_response", packet, writer)
|
write_custom_event("basic_response", packet, writer)
|
||||||
|
|
||||||
@@ -45,6 +49,7 @@ def tool_call(
|
|||||||
|
|
||||||
emit_packet(tool_kickoff, writer)
|
emit_packet(tool_kickoff, writer)
|
||||||
|
|
||||||
|
try:
|
||||||
tool_responses = []
|
tool_responses = []
|
||||||
for response in tool_runner.tool_responses():
|
for response in tool_runner.tool_responses():
|
||||||
tool_responses.append(response)
|
tool_responses.append(response)
|
||||||
@@ -52,6 +57,10 @@ def tool_call(
|
|||||||
|
|
||||||
tool_final_result = tool_runner.tool_final_result()
|
tool_final_result = tool_runner.tool_final_result()
|
||||||
emit_packet(tool_final_result, writer)
|
emit_packet(tool_final_result, writer)
|
||||||
|
except Exception as e:
|
||||||
|
raise ToolCallException(
|
||||||
|
f"Error during tool call for {tool.display_name}: {e}"
|
||||||
|
) from e
|
||||||
|
|
||||||
tool_call = ToolCall(name=tool.name, args=tool_args, id=tool_id)
|
tool_call = ToolCall(name=tool.name, args=tool_args, id=tool_id)
|
||||||
tool_call_summary = ToolCallSummary(
|
tool_call_summary = ToolCallSummary(
|
||||||
|
@@ -7,6 +7,7 @@ from typing import cast
|
|||||||
|
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from onyx.agents.agent_search.orchestration.nodes.tool_call import ToolCallException
|
||||||
from onyx.chat.answer import Answer
|
from onyx.chat.answer import Answer
|
||||||
from onyx.chat.chat_utils import create_chat_chain
|
from onyx.chat.chat_utils import create_chat_chain
|
||||||
from onyx.chat.chat_utils import create_temporary_persona
|
from onyx.chat.chat_utils import create_temporary_persona
|
||||||
@@ -945,19 +946,25 @@ def stream_chat_message_objects(
|
|||||||
return
|
return
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Failed to process chat message.")
|
logger.exception(f"Failed to process chat message due to {e}")
|
||||||
|
|
||||||
error_msg = str(e)
|
error_msg = str(e)
|
||||||
stack_trace = traceback.format_exc()
|
stack_trace = traceback.format_exc()
|
||||||
|
|
||||||
|
if isinstance(e, ToolCallException):
|
||||||
|
yield StreamingError(error=error_msg, stack_trace=stack_trace)
|
||||||
|
else:
|
||||||
if llm:
|
if llm:
|
||||||
client_error_msg = litellm_exception_to_error_msg(e, llm)
|
client_error_msg = litellm_exception_to_error_msg(e, llm)
|
||||||
if llm.config.api_key and len(llm.config.api_key) > 2:
|
if llm.config.api_key and len(llm.config.api_key) > 2:
|
||||||
error_msg = error_msg.replace(llm.config.api_key, "[REDACTED_API_KEY]")
|
error_msg = error_msg.replace(
|
||||||
|
llm.config.api_key, "[REDACTED_API_KEY]"
|
||||||
|
)
|
||||||
stack_trace = stack_trace.replace(
|
stack_trace = stack_trace.replace(
|
||||||
llm.config.api_key, "[REDACTED_API_KEY]"
|
llm.config.api_key, "[REDACTED_API_KEY]"
|
||||||
)
|
)
|
||||||
|
|
||||||
yield StreamingError(error=client_error_msg, stack_trace=stack_trace)
|
yield StreamingError(error=client_error_msg, stack_trace=stack_trace)
|
||||||
|
|
||||||
db_session.rollback()
|
db_session.rollback()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@@ -218,6 +218,9 @@ class InternetSearchTool(Tool):
|
|||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
params={"q": query, "count": self.num_results},
|
params={"q": query, "count": self.num_results},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
results = response.json()
|
results = response.json()
|
||||||
|
|
||||||
# If no hits, Bing does not include the webPages key
|
# If no hits, Bing does not include the webPages key
|
||||||
|
@@ -2975,8 +2975,7 @@ export function ChatPage({
|
|||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div key={messageReactComponentKey}>
|
<div key={messageReactComponentKey}>
|
||||||
<AgenticMessage
|
<AIMessage
|
||||||
subQuestions={message.sub_questions || []}
|
|
||||||
currentPersona={liveAssistant}
|
currentPersona={liveAssistant}
|
||||||
messageId={message.messageId}
|
messageId={message.messageId}
|
||||||
content={
|
content={
|
||||||
|
Reference in New Issue
Block a user