refac
This commit is contained in:
1 parent
f7767d6be7
commit
a1579a01ff
6 files changed
+557
-110
No files matched your search
@@ -66,7 +66,7 @@
|
||||
} from '$lib/utils';
|
||||
import { AudioQueue } from '$lib/utils/audio';
|
||||
import { createTemporaryChatId, isTemporaryChatId } from '$lib/utils/chatId';
|
||||
import { getOutputText } from './Messages/structuredOutput';
|
||||
import { applyResponseStreamEvent, getOutputText } from './Messages/structuredOutput';
|
||||
|
||||
import {
|
||||
archiveChatById,
|
||||
@@ -1178,6 +1178,8 @@
|
||||
updateLastReadAt($chatId);
|
||||
}
|
||||
}
|
||||
} else if (type === 'response:completion') {
|
||||
responseCompletionEventHandler(data, message);
|
||||
} else if (type === 'chat:completion') {
|
||||
chatCompletionEventHandler(data, message, event.chat_id);
|
||||
} else if (type === 'chat:tasks:cancel') {
|
||||
@@ -2693,6 +2695,27 @@
|
||||
}
|
||||
};
|
||||
|
||||
const responseCompletionEventHandler = (data, message) => {
|
||||
message.output = applyResponseStreamEvent(message.output ?? [], data);
|
||||
|
||||
if (data?.type === 'response.output_text.delta') {
|
||||
const value = data.delta ?? '';
|
||||
if (!(message.content == '' && value == '\n')) {
|
||||
message.content += value;
|
||||
|
||||
if (navigator.vibrate && ($settings?.hapticFeedback ?? false)) {
|
||||
navigator.vibrate(5);
|
||||
}
|
||||
dispatchCallOverlayAudio(message);
|
||||
}
|
||||
} else if (data?.type === 'response.completed' || data?.type?.endsWith('.done')) {
|
||||
message.content = getOutputText(message.output) || message.content;
|
||||
}
|
||||
|
||||
history.messages[message.id] = message;
|
||||
history = history;
|
||||
};
|
||||
|
||||
const chatCompletionEventHandler = async (data, message, chatId) => {
|
||||
const { id, done, choices, content, output, sources, selected_model_id, error, usage } = data;
|
||||
|
||||
|
||||
Reference in new issue
Block a user