yangdx
commited on
Commit
·
1cc51a7
1
Parent(s):
8be533e
Fix browse compatible problem for crypto.randomUUID
Browse files
lightrag/api/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1 |
-
__api_version__ = "
|
|
|
1 |
+
__api_version__ = "0165"
|
lightrag_webui/src/features/RetrievalTesting.tsx
CHANGED
@@ -12,6 +12,16 @@ import { EraserIcon, SendIcon } from 'lucide-react'
|
|
12 |
import { useTranslation } from 'react-i18next'
|
13 |
import type { QueryMode } from '@/api/lightrag'
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
export default function RetrievalTesting() {
|
16 |
const { t } = useTranslation()
|
17 |
const [messages, setMessages] = useState<MessageWithError[]>(() => {
|
@@ -108,13 +118,13 @@ export default function RetrievalTesting() {
|
|
108 |
// Create messages
|
109 |
// Save the original input (with prefix if any) in userMessage.content for display
|
110 |
const userMessage: MessageWithError = {
|
111 |
-
id:
|
112 |
content: inputValue,
|
113 |
role: 'user'
|
114 |
}
|
115 |
|
116 |
const assistantMessage: MessageWithError = {
|
117 |
-
id:
|
118 |
content: '',
|
119 |
role: 'assistant',
|
120 |
mermaidRendered: false
|
|
|
12 |
import { useTranslation } from 'react-i18next'
|
13 |
import type { QueryMode } from '@/api/lightrag'
|
14 |
|
15 |
+
// Helper function to generate unique IDs with browser compatibility
|
16 |
+
const generateUniqueId = () => {
|
17 |
+
// Use crypto.randomUUID() if available
|
18 |
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
19 |
+
return crypto.randomUUID();
|
20 |
+
}
|
21 |
+
// Fallback to timestamp + random string for browsers without crypto.randomUUID
|
22 |
+
return `id-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
23 |
+
};
|
24 |
+
|
25 |
export default function RetrievalTesting() {
|
26 |
const { t } = useTranslation()
|
27 |
const [messages, setMessages] = useState<MessageWithError[]>(() => {
|
|
|
118 |
// Create messages
|
119 |
// Save the original input (with prefix if any) in userMessage.content for display
|
120 |
const userMessage: MessageWithError = {
|
121 |
+
id: generateUniqueId(), // Use browser-compatible ID generation
|
122 |
content: inputValue,
|
123 |
role: 'user'
|
124 |
}
|
125 |
|
126 |
const assistantMessage: MessageWithError = {
|
127 |
+
id: generateUniqueId(), // Use browser-compatible ID generation
|
128 |
content: '',
|
129 |
role: 'assistant',
|
130 |
mermaidRendered: false
|