Added option to summarize the chat when an error is triggered (#3598)
This commit is contained in:
@@ -157,6 +157,7 @@ function BaseChatContent({
|
|||||||
updateMessageStreamBody,
|
updateMessageStreamBody,
|
||||||
sessionMetadata,
|
sessionMetadata,
|
||||||
isUserMessage,
|
isUserMessage,
|
||||||
|
clearError,
|
||||||
} = useChatEngine({
|
} = useChatEngine({
|
||||||
chat,
|
chat,
|
||||||
setChat,
|
setChat,
|
||||||
@@ -434,21 +435,51 @@ function BaseChatContent({
|
|||||||
{error.message || 'Honk! Goose experienced an error while responding'}
|
{error.message || 'Honk! Goose experienced an error while responding'}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Regular retry button for non-token-limit errors */}
|
{/* Action buttons for non-token-limit errors */}
|
||||||
<div
|
<div className="flex gap-2 mt-2">
|
||||||
className="px-3 py-2 mt-2 text-center whitespace-nowrap cursor-pointer text-textStandard border border-borderSubtle hover:bg-bgSubtle rounded-full inline-block transition-all duration-150"
|
<div
|
||||||
onClick={async () => {
|
className="px-3 py-2 text-center whitespace-nowrap cursor-pointer text-textStandard border border-borderSubtle hover:bg-bgSubtle rounded-full inline-block transition-all duration-150"
|
||||||
// Find the last user message
|
onClick={async () => {
|
||||||
const lastUserMessage = messages.reduceRight(
|
// Create a contextLengthExceeded message similar to token limit errors
|
||||||
(found, m) => found || (m.role === 'user' ? m : null),
|
const contextMessage: Message = {
|
||||||
null as Message | null
|
id: `context-${Date.now()}`,
|
||||||
);
|
role: 'assistant',
|
||||||
if (lastUserMessage) {
|
created: Math.floor(Date.now() / 1000),
|
||||||
append(lastUserMessage);
|
content: [
|
||||||
}
|
{
|
||||||
}}
|
type: 'contextLengthExceeded',
|
||||||
>
|
msg: 'Summarization requested due to error. Creating summary to help resolve the issue.',
|
||||||
Retry Last Message
|
},
|
||||||
|
],
|
||||||
|
display: true,
|
||||||
|
sendToLLM: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add the context message to trigger ContextHandler
|
||||||
|
const updatedMessages = [...messages, contextMessage];
|
||||||
|
setMessages(updatedMessages);
|
||||||
|
|
||||||
|
// Clear the error state since we're handling it with summarization
|
||||||
|
clearError();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Summarize Conversation
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="px-3 py-2 text-center whitespace-nowrap cursor-pointer text-textStandard border border-borderSubtle hover:bg-bgSubtle rounded-full inline-block transition-all duration-150"
|
||||||
|
onClick={async () => {
|
||||||
|
// Find the last user message
|
||||||
|
const lastUserMessage = messages.reduceRight(
|
||||||
|
(found, m) => found || (m.role === 'user' ? m : null),
|
||||||
|
null as Message | null
|
||||||
|
);
|
||||||
|
if (lastUserMessage) {
|
||||||
|
append(lastUserMessage);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Retry Last Message
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@@ -472,7 +503,7 @@ function BaseChatContent({
|
|||||||
{/* Fixed loading indicator at bottom left of chat container */}
|
{/* Fixed loading indicator at bottom left of chat container */}
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div className="absolute bottom-1 left-4 z-20 pointer-events-none">
|
<div className="absolute bottom-1 left-4 z-20 pointer-events-none">
|
||||||
<LoadingGoose
|
<LoadingGoose
|
||||||
message={isLoadingSummary ? 'summarizing conversation…' : undefined}
|
message={isLoadingSummary ? 'summarizing conversation…' : undefined}
|
||||||
isWaiting={isWaiting}
|
isWaiting={isWaiting}
|
||||||
isStreaming={isStreaming}
|
isStreaming={isStreaming}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ export const useChatEngine = ({
|
|||||||
updateMessageStreamBody,
|
updateMessageStreamBody,
|
||||||
notifications,
|
notifications,
|
||||||
sessionMetadata,
|
sessionMetadata,
|
||||||
|
setError,
|
||||||
} = useMessageStream({
|
} = useMessageStream({
|
||||||
api: getApiUrl('/reply'),
|
api: getApiUrl('/reply'),
|
||||||
id: chat.id,
|
id: chat.id,
|
||||||
@@ -402,5 +403,8 @@ export const useChatEngine = ({
|
|||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
isUserMessage,
|
isUserMessage,
|
||||||
|
|
||||||
|
// Error management
|
||||||
|
clearError: () => setError(undefined),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -173,6 +173,9 @@ export interface UseMessageStreamHelpers {
|
|||||||
|
|
||||||
/** Session metadata including token counts */
|
/** Session metadata including token counts */
|
||||||
sessionMetadata: SessionMetadata | null;
|
sessionMetadata: SessionMetadata | null;
|
||||||
|
|
||||||
|
/** Clear error state */
|
||||||
|
setError: (error: Error | undefined) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -709,5 +712,6 @@ export function useMessageStream({
|
|||||||
notifications,
|
notifications,
|
||||||
currentModelInfo,
|
currentModelInfo,
|
||||||
sessionMetadata,
|
sessionMetadata,
|
||||||
|
setError,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user