Fix browse compatible problem for crypto.randomUUID
This commit is contained in:
@@ -1 +1 @@
|
|||||||
__api_version__ = "0164"
|
__api_version__ = "0165"
|
||||||
|
@@ -12,6 +12,16 @@ import { EraserIcon, SendIcon } from 'lucide-react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { QueryMode } from '@/api/lightrag'
|
import type { QueryMode } from '@/api/lightrag'
|
||||||
|
|
||||||
|
// Helper function to generate unique IDs with browser compatibility
|
||||||
|
const generateUniqueId = () => {
|
||||||
|
// Use crypto.randomUUID() if available
|
||||||
|
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
}
|
||||||
|
// Fallback to timestamp + random string for browsers without crypto.randomUUID
|
||||||
|
return `id-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
||||||
|
};
|
||||||
|
|
||||||
export default function RetrievalTesting() {
|
export default function RetrievalTesting() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [messages, setMessages] = useState<MessageWithError[]>(() => {
|
const [messages, setMessages] = useState<MessageWithError[]>(() => {
|
||||||
@@ -108,13 +118,13 @@ export default function RetrievalTesting() {
|
|||||||
// Create messages
|
// Create messages
|
||||||
// Save the original input (with prefix if any) in userMessage.content for display
|
// Save the original input (with prefix if any) in userMessage.content for display
|
||||||
const userMessage: MessageWithError = {
|
const userMessage: MessageWithError = {
|
||||||
id: crypto.randomUUID(), // Add unique ID
|
id: generateUniqueId(), // Use browser-compatible ID generation
|
||||||
content: inputValue,
|
content: inputValue,
|
||||||
role: 'user'
|
role: 'user'
|
||||||
}
|
}
|
||||||
|
|
||||||
const assistantMessage: MessageWithError = {
|
const assistantMessage: MessageWithError = {
|
||||||
id: crypto.randomUUID(), // Add unique ID
|
id: generateUniqueId(), // Use browser-compatible ID generation
|
||||||
content: '',
|
content: '',
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
mermaidRendered: false
|
mermaidRendered: false
|
||||||
|
Reference in New Issue
Block a user