response id fix
This commit is contained in:
parent
1a084767da
commit
e3e6432d37
1 changed files with 25 additions and 9 deletions
|
|
@ -248,6 +248,7 @@ function ChatPage() {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
};
|
};
|
||||||
setMessages((prev) => [...prev.slice(0, -1), pollingMessage]);
|
setMessages((prev) => [...prev.slice(0, -1), pollingMessage]);
|
||||||
|
return null;
|
||||||
} else if (response.ok) {
|
} else if (response.ok) {
|
||||||
// Original flow: Direct response
|
// Original flow: Direct response
|
||||||
|
|
||||||
|
|
@ -277,12 +278,15 @@ function ChatPage() {
|
||||||
|
|
||||||
// If this is a new conversation (no currentConversationId), set it now
|
// If this is a new conversation (no currentConversationId), set it now
|
||||||
if (!currentConversationId) {
|
if (!currentConversationId) {
|
||||||
|
console.log("Setting current conversation ID to:", result.response_id);
|
||||||
setCurrentConversationId(result.response_id);
|
setCurrentConversationId(result.response_id);
|
||||||
refreshConversations(true);
|
refreshConversations(true);
|
||||||
} else {
|
} else {
|
||||||
// For existing conversations, do a silent refresh to keep backend in sync
|
// For existing conversations, do a silent refresh to keep backend in sync
|
||||||
refreshConversationsSilent();
|
refreshConversationsSilent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result.response_id;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Upload failed: ${response.status}`);
|
throw new Error(`Upload failed: ${response.status}`);
|
||||||
|
|
@ -721,7 +725,7 @@ function ChatPage() {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSSEStream = async (userMessage: Message) => {
|
const handleSSEStream = async (userMessage: Message, previousResponseId?: string) => {
|
||||||
// Prepare filters
|
// Prepare filters
|
||||||
const processedFilters = parsedFilterData?.filters
|
const processedFilters = parsedFilterData?.filters
|
||||||
? (() => {
|
? (() => {
|
||||||
|
|
@ -747,10 +751,13 @@ function ChatPage() {
|
||||||
})()
|
})()
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
// Use passed previousResponseId if available, otherwise fall back to state
|
||||||
|
const responseIdToUse = previousResponseId || previousResponseIds[endpoint];
|
||||||
|
|
||||||
// Use the hook to send the message
|
// Use the hook to send the message
|
||||||
await sendStreamingMessage({
|
await sendStreamingMessage({
|
||||||
prompt: userMessage.content,
|
prompt: userMessage.content,
|
||||||
previousResponseId: previousResponseIds[endpoint] || undefined,
|
previousResponseId: responseIdToUse || undefined,
|
||||||
filters: processedFilters,
|
filters: processedFilters,
|
||||||
limit: parsedFilterData?.limit ?? 10,
|
limit: parsedFilterData?.limit ?? 10,
|
||||||
scoreThreshold: parsedFilterData?.scoreThreshold ?? 0,
|
scoreThreshold: parsedFilterData?.scoreThreshold ?? 0,
|
||||||
|
|
@ -761,7 +768,7 @@ function ChatPage() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSendMessage = async (inputMessage: string) => {
|
const handleSendMessage = async (inputMessage: string, previousResponseId?: string) => {
|
||||||
if (!inputMessage.trim() || loading) return;
|
if (!inputMessage.trim() || loading) return;
|
||||||
|
|
||||||
const userMessage: Message = {
|
const userMessage: Message = {
|
||||||
|
|
@ -781,7 +788,7 @@ function ChatPage() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (asyncMode) {
|
if (asyncMode) {
|
||||||
await handleSSEStream(userMessage);
|
await handleSSEStream(userMessage, previousResponseId);
|
||||||
} else {
|
} else {
|
||||||
// Original non-streaming logic
|
// Original non-streaming logic
|
||||||
try {
|
try {
|
||||||
|
|
@ -890,16 +897,25 @@ function ChatPage() {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Check if there's an uploaded file and upload it first
|
// Check if there's an uploaded file and upload it first
|
||||||
|
let uploadedResponseId: string | null = null;
|
||||||
if (uploadedFile) {
|
if (uploadedFile) {
|
||||||
// Upload the file first
|
// Upload the file first
|
||||||
await handleFileUpload(uploadedFile);
|
const responseId = await handleFileUpload(uploadedFile);
|
||||||
// Clear the file after upload
|
// Clear the file after upload
|
||||||
setUploadedFile(null);
|
setUploadedFile(null);
|
||||||
chatInputRef.current?.clickFileInput?.(); // Reset file input if needed
|
|
||||||
|
// If the upload resulted in a new conversation, store the response ID
|
||||||
|
if (responseId) {
|
||||||
|
uploadedResponseId = responseId;
|
||||||
|
setPreviousResponseIds((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[endpoint]: responseId,
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then send the message
|
// Pass the responseId from upload (if any) to handleSendMessage
|
||||||
handleSendMessage(input);
|
handleSendMessage(input, uploadedResponseId || undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleFunctionCall = (functionCallId: string) => {
|
const toggleFunctionCall = (functionCallId: string) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue