mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-09 20:39:29 +02:00
Improve error msg in chat UI (#1557)
This commit is contained in:
parent
61d096533c
commit
e4a08c5546
@ -273,8 +273,8 @@ def stream_chat_message_objects(
|
||||
"Be sure to update the chat pointers before calling this."
|
||||
)
|
||||
|
||||
# Save now to save the latest chat message
|
||||
db_session.commit()
|
||||
# NOTE: do not commit user message - it will be committed when the
|
||||
# assistant message is successfully generated
|
||||
else:
|
||||
# re-create linear history of messages
|
||||
final_msg, history_msgs = create_chat_chain(
|
||||
@ -304,6 +304,7 @@ def stream_chat_message_objects(
|
||||
new_file.to_file_descriptor() for new_file in latest_query_files
|
||||
],
|
||||
db_session=db_session,
|
||||
commit=False,
|
||||
)
|
||||
|
||||
selected_db_search_docs = None
|
||||
@ -362,7 +363,7 @@ def stream_chat_message_objects(
|
||||
# error=,
|
||||
# reference_docs=,
|
||||
db_session=db_session,
|
||||
commit=True,
|
||||
commit=False,
|
||||
)
|
||||
|
||||
if not final_msg.prompt:
|
||||
@ -491,11 +492,19 @@ def stream_chat_message_objects(
|
||||
yield cast(ChatPacket, packet)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
logger.exception("Failed to process chat message")
|
||||
|
||||
# Frontend will erase whatever answer and show this instead
|
||||
# This will be the issue 99% of the time
|
||||
yield StreamingError(error="LLM failed to respond, have you set your API key?")
|
||||
# Don't leak the API key
|
||||
error_msg = str(e)
|
||||
if llm.config.api_key and llm.config.api_key.lower() in error_msg.lower():
|
||||
error_msg = (
|
||||
f"LLM failed to respond. Invalid API "
|
||||
f"key error from '{llm.config.model_provider}'."
|
||||
)
|
||||
|
||||
yield StreamingError(error=error_msg)
|
||||
# Cancel the transaction so that no messages are saved
|
||||
db_session.rollback()
|
||||
return
|
||||
|
||||
# Post-LLM answer processing
|
||||
@ -519,6 +528,7 @@ def stream_chat_message_objects(
|
||||
citations=db_citations,
|
||||
error=None,
|
||||
)
|
||||
db_session.commit() # actually save user / assistant message
|
||||
|
||||
msg_detail_response = translate_db_message_to_chat_message_detail(
|
||||
gen_ai_response_message
|
||||
|
@ -522,6 +522,9 @@ export function ChatPage({
|
||||
messageToResendParent ||
|
||||
(currMessageHistory.length > 0
|
||||
? currMessageHistory[currMessageHistory.length - 1]
|
||||
: null) ||
|
||||
(completeMessageMap.size === 1
|
||||
? Array.from(completeMessageMap.values())[0]
|
||||
: null);
|
||||
|
||||
// if we're resending, set the parent's child to null
|
||||
@ -684,14 +687,14 @@ export function ChatPage({
|
||||
message: currMessage,
|
||||
type: "user",
|
||||
files: currentMessageFiles,
|
||||
parentMessageId: null,
|
||||
parentMessageId: parentMessage?.messageId || SYSTEM_MESSAGE_ID,
|
||||
},
|
||||
{
|
||||
messageId: TEMP_ASSISTANT_MESSAGE_ID,
|
||||
message: errorMsg,
|
||||
type: "error",
|
||||
files: aiMessageImages || [],
|
||||
parentMessageId: null,
|
||||
parentMessageId: TEMP_USER_MESSAGE_ID,
|
||||
},
|
||||
],
|
||||
completeMessageMapOverride: frozenCompleteMessageMap,
|
||||
|
@ -113,7 +113,6 @@ export const AIMessage = ({
|
||||
if (!isReady) {
|
||||
return <div />;
|
||||
}
|
||||
console.log(content);
|
||||
|
||||
if (!isComplete) {
|
||||
const trimIncompleteCodeSection = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user