Merge remote-tracking branch 'origin/ai-hub' into ai-hub
This commit is contained in:
@@ -138,6 +138,28 @@ function scrollToBottom() {
|
||||
function handleDataChunk(chunk: AnyObject) {
|
||||
try {
|
||||
const parsed = parseStreamChunk(chunk, currentRequestApiType.value || 'Completions');
|
||||
|
||||
// 处理消息ID和创建时间
|
||||
// UserMessage 对应用户消息(倒数第二条),SystemMessage 对应AI消息(最后一条)
|
||||
if (parsed.type === 'UserMessage' && parsed.messageId) {
|
||||
const userMessage = bubbleItems.value[bubbleItems.value.length - 2];
|
||||
if (userMessage) {
|
||||
userMessage.id = parsed.messageId;
|
||||
if (parsed.creationTime) {
|
||||
userMessage.creationTime = parsed.creationTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (parsed.type === 'SystemMessage' && parsed.messageId) {
|
||||
const aiMessage = bubbleItems.value[bubbleItems.value.length - 1];
|
||||
if (aiMessage) {
|
||||
aiMessage.id = parsed.messageId;
|
||||
if (parsed.creationTime) {
|
||||
aiMessage.creationTime = parsed.creationTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const latest = bubbleItems.value[bubbleItems.value.length - 1];
|
||||
|
||||
// 处理 token 使用情况
|
||||
|
||||
@@ -230,6 +230,9 @@ export interface UnifiedStreamChunk {
|
||||
total_tokens?: number;
|
||||
};
|
||||
finish_reason?: string;
|
||||
messageId?: string;
|
||||
creationTime?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,6 +262,17 @@ export function parseCompletionsStreamChunk(chunk: any): UnifiedStreamChunk {
|
||||
result.finish_reason = chunk.choices[0].finish_reason;
|
||||
}
|
||||
|
||||
// 解析消息ID和创建时间(UserMessage 或 SystemMessage 类型)
|
||||
if (chunk.type === 'UserMessage' || chunk.type === 'SystemMessage') {
|
||||
result.type = chunk.type;
|
||||
if (chunk.messageId) {
|
||||
result.messageId = chunk.messageId;
|
||||
}
|
||||
if (chunk.creationTime) {
|
||||
result.creationTime = chunk.creationTime;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user