-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
71 lines (63 loc) · 2.57 KB
/
index.tsx
File metadata and controls
71 lines (63 loc) · 2.57 KB
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
64
65
66
67
68
69
70
71
import ChatActions from '@node-core/ui-components/Common/Search/Chat/Actions';
import type { Interaction } from '@orama/core';
import { ChatInteractions } from '@orama/ui/components';
import type { FC } from 'react';
import ChatSources from '../ChatSources';
import styles from './index.module.css';
type ChatMessageProps = {
interaction: Interaction;
};
const TypingIndicator: FC = () => (
<div className={styles.typingIndicator}>
<span className={styles.typingDot}></span>
<span className={styles.typingDot}></span>
<span className={styles.typingDot}></span>
</div>
);
export const ChatMessage: FC<ChatMessageProps> = ({ interaction }) => {
if (!interaction) {
return null;
}
return (
<>
<ChatInteractions.UserPrompt className={styles.chatUserPrompt}>
<p>{interaction?.query}</p>
</ChatInteractions.UserPrompt>
<ChatSources interaction={interaction} />
<ChatInteractions.Loading interaction={interaction}>
<div className={styles.chatLoadingWrapper}>
<TypingIndicator />
</div>
</ChatInteractions.Loading>
{interaction.response && (
<div className={styles.chatAssistantMessageWrapper}>
<ChatInteractions.AssistantMessage
className={styles.chatAssistantMessage}
markdownClassnames={{
p: 'my-2 leading-relaxed',
pre: 'my-6 text-md overflow-x-auto hljs [&_pre]:bg-neutral-900! [&_pre]:text-sm [&_pre]:rounded-md [&_pre]:p-4 [&_pre]:whitespace-break-spaces wrap-break-word',
code: 'px-2 py-1 rounded text-sm whitespace-pre-wrap hljs bg-neutral-300 dark:bg-neutral-900',
table: 'w-full border-collapse my-6',
thead: 'dark:bg-neutral-900',
th: 'border border-neutral-300 dark:border-neutral-900 px-3 py-2 text-left font-semibold',
td: 'border border-neutral-300 dark:border-neutral-900 px-3 py-2',
tr: 'border-b border-white/10',
h1: 'text-2xl font-bold mb-4 mt-6',
h2: 'text-xl font-bold mb-3 mt-5',
h3: 'text-lg font-extrabold my-3',
ul: 'list-disc pl-10 my-4',
ol: 'list-decimal pl-4 my-4',
li: 'mb-0 [&_p]:mb-0',
hr: 'border-t border-neutral-300 dark:border-neutral-900 my-6',
blockquote: 'border-l-4 pl-4 my-4 italic',
a: 'underline',
}}
>
{interaction.response || ''}
</ChatInteractions.AssistantMessage>
<ChatActions interaction={interaction} />
</div>
)}
</>
);
};