feat: Implement knowledge import feature for characters
- Added KnowledgeImport page for importing character knowledge from URLs. - Integrated URL validation and error handling for unsupported websites. - Created API endpoints for importing content from URLs and retrieving character knowledge. - Enhanced VectorStoreService with logging and error handling for vector memory storage. - Updated frontend to display knowledge sources and manage them effectively. - Added support for fetching recent character knowledge as a fallback in similarity searches. - Updated OpenAPI documentation to reflect new import functionality.
This commit is contained in:
@@ -5,6 +5,7 @@ import { useCharacterStore } from '../stores/characterStore';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
import type { Message } from '../types';
|
||||
import { io, Socket } from 'socket.io-client';
|
||||
import { chatControllerSendMessage } from '../api/generated/conversations/conversations';
|
||||
|
||||
const WS_URL = (import.meta.env as unknown as ImportMetaEnv).VITE_WS_URL || 'http://localhost:3000';
|
||||
|
||||
@@ -26,6 +27,7 @@ export function Chat() {
|
||||
|
||||
const [message, setMessage] = useState('');
|
||||
const [streamingContent, setStreamingContent] = useState('');
|
||||
const [socketConnected, setSocketConnected] = useState(false);
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
const socketRef = useRef<Socket | null>(null);
|
||||
|
||||
@@ -42,6 +44,17 @@ export function Chat() {
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Connected to chat server');
|
||||
setSocketConnected(true);
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('Disconnected from chat server');
|
||||
setSocketConnected(false);
|
||||
});
|
||||
|
||||
socket.on('connect_error', (err) => {
|
||||
console.error('Socket connection error:', err.message);
|
||||
setSocketConnected(false);
|
||||
});
|
||||
|
||||
socket.on('message_chunk', (data: { conversationId: string; chunk: { content: string } }) => {
|
||||
@@ -111,11 +124,30 @@ export function Chat() {
|
||||
setStreamingContent('');
|
||||
setStreaming(true);
|
||||
|
||||
// Send via socket for streaming
|
||||
socketRef.current?.emit('send_message', {
|
||||
conversationId,
|
||||
content,
|
||||
});
|
||||
// Check if socket is connected, otherwise fallback to HTTP
|
||||
if (socketRef.current?.connected) {
|
||||
socketRef.current.emit('send_message', {
|
||||
conversationId,
|
||||
content,
|
||||
});
|
||||
} else {
|
||||
// Fallback to HTTP API when socket is not connected
|
||||
try {
|
||||
const result = await chatControllerSendMessage(conversationId, { content });
|
||||
|
||||
// Add messages to the conversation
|
||||
if (result.userMessage) {
|
||||
addMessage(result.userMessage as Message);
|
||||
}
|
||||
if (result.assistantMessage) {
|
||||
addMessage(result.assistantMessage as Message);
|
||||
}
|
||||
setStreaming(false);
|
||||
} catch (error) {
|
||||
console.error('Failed to send message:', error);
|
||||
setStreaming(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
|
||||
Reference in New Issue
Block a user