Spaces:
Sleeping
Sleeping
File size: 1,439 Bytes
32177e2 ebd361e 32177e2 288c05b e6b7e49 288c05b e6b7e49 288c05b e6b7e49 32177e2 ebd361e 69f44ef | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | export type CourseResponse = {
id: number | string;
title: string;
description?: string;
};
export type DocumentSource = {
document_id: string;
filename: string;
excerpt: string;
};
export type ChatMessageResponse = {
uuid_id: string;
role: string;
content: string;
sources?: DocumentSource[];
created_at: string;
};
export type ChatSessionResponse = {
uuid_id: string;
user_id: string;
user_name?: string;
course_id: string;
course_name?: string;
title: string;
message_count: number;
last_message_at?: string;
created_at: string;
updated_at: string;
};
function createLocalMessageId(prefix: string): string {
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
return `${prefix}-${crypto.randomUUID()}`;
}
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
}
export function createLocalUserMessage(content: string): ChatMessageResponse {
return {
content,
created_at: new Date().toISOString(),
role: 'user',
sources: [],
uuid_id: createLocalMessageId('local'),
};
}
export function createLocalAssistantMessage(
content = '',
): ChatMessageResponse {
return {
content,
created_at: new Date().toISOString(),
role: 'assistant',
sources: [],
uuid_id: createLocalMessageId('local-assistant'),
};
}
|