Improve error msg in chat UI (#1557)

This commit is contained in:
Chris Weaver 2024-06-02 19:53:04 -07:00 committed by GitHub
parent 61d096533c
commit e4a08c5546
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 10 deletions

View File

@ -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

View File

@ -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,

View File

@ -113,7 +113,6 @@ export const AIMessage = ({
if (!isReady) {
return <div />;
}
console.log(content);
if (!isComplete) {
const trimIncompleteCodeSection = (