Enhance H5 QA session interactions
This commit is contained in:
@@ -8,9 +8,19 @@ export type ChatMessage = {
|
||||
content: string;
|
||||
source?: string;
|
||||
boundary?: string;
|
||||
feedback?: "liked" | "disliked";
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export type ChatSession = {
|
||||
id: string;
|
||||
title: string;
|
||||
preview: string;
|
||||
messages: ChatMessage[];
|
||||
updatedAt: string;
|
||||
questionCount: number;
|
||||
};
|
||||
|
||||
export type SuggestedQuestion = {
|
||||
id: string;
|
||||
text: string;
|
||||
@@ -46,6 +56,32 @@ export const initialMessages: ChatMessage[] = [
|
||||
}
|
||||
];
|
||||
|
||||
export function createEmptySession(): ChatSession {
|
||||
return {
|
||||
id: `session-${Date.now()}`,
|
||||
title: "新的问答",
|
||||
preview: "还没有开始提问",
|
||||
messages: initialMessages,
|
||||
updatedAt: new Date().toISOString(),
|
||||
questionCount: 0
|
||||
};
|
||||
}
|
||||
|
||||
export function summarizeSession(sessionId: string, messages: ChatMessage[]): ChatSession {
|
||||
const userMessages = messages.filter((message) => message.role === "user");
|
||||
const lastMessage = [...messages].reverse().find((message) => message.role === "assistant" || message.role === "user");
|
||||
const firstQuestion = userMessages[0]?.content;
|
||||
|
||||
return {
|
||||
id: sessionId,
|
||||
title: firstQuestion ? firstQuestion.slice(0, 24) : "新的问答",
|
||||
preview: lastMessage?.content.slice(0, 42) ?? "还没有开始提问",
|
||||
messages,
|
||||
updatedAt: new Date().toISOString(),
|
||||
questionCount: userMessages.length
|
||||
};
|
||||
}
|
||||
|
||||
export const mockCallableQa: CallableQAItem[] = [
|
||||
{
|
||||
id: 9001,
|
||||
|
||||
Reference in New Issue
Block a user