3.8 KiB
3.8 KiB
Chat Assistant - Backend Integration
Overview
The ChatAssistant component has been successfully integrated with the backend Ollama service to enable real-time policy question answering and content verification.
What Was Done
1. Created Chat Feature Module
Following the new frontend architecture, a complete chat feature module was created:
- Types (
features/chat/types/chat.types.ts): TypeScript types for messages and API requests - Service (
features/chat/services/chatService.ts): API service for chat operations - Hooks (
features/chat/hooks/useChat.ts): React hooks for chat functionality
2. Updated ChatAssistant Component
The ChatAssistant component now:
- ✅ Connects to backend Ollama API (
/test_ollama_1endpoint) - ✅ Sends real questions to the AI model
- ✅ Displays AI responses in real-time
- ✅ Handles verification requests from forms
- ✅ Shows loading states during API calls
- ✅ Displays error messages if API calls fail
- ✅ Maintains conversation history
API Endpoint
The chat uses the backend endpoint:
- URL:
POST /test_ollama_1 - Request Body:
{ "prompt": "user question" } - Response:
{ "oss_json": "AI response text" }
Features
1. Policy Question Answering
Users can ask questions about:
- IT governance policies
- Compliance requirements
- Regulatory standards
- Workflow processes
Example questions:
- "What are the requirements for ISO 27001 compliance?"
- "How do I submit a workflow approval?"
- "What documents are needed for compliance verification?"
2. Content Verification
When users click "Verify" on form fields, the assistant:
- Analyzes the content against compliance requirements
- Provides feedback on whether it meets requirements
- Suggests improvements
- Identifies potential issues
3. Real-time Responses
- Loading indicators while waiting for AI response
- Error handling with user-friendly messages
- Conversation history maintained in the chat
Usage
The ChatAssistant is already integrated in the Dashboard. Users can:
- Ask Questions: Type questions in the chat input and press Enter
- Verify Content: Click "Verify" buttons on form fields to get AI feedback
- View History: Scroll through previous messages
Configuration
The API URL is configured in:
- File:
src/shared/config/env.ts - Environment Variable:
VITE_API_URL - Default:
http://localhost:4402
To change the API URL, update the .env file:
VITE_API_URL=http://your-backend-url:4402
Backend Requirements
Ensure the backend is running and accessible:
- Backend service should be running on port 4402
- Ollama service should be running and accessible
- The
/test_ollama_1endpoint should be available
Testing
To test the integration:
-
Start the backend:
cd be0 docker-compose up be0 -
Start the frontend:
cd fe0 npm run dev -
Open the Dashboard and try:
- Asking a question about policies
- Verifying form content
Troubleshooting
Issue: "Failed to get response from assistant"
Solutions:
- Check if backend is running:
curl http://localhost:4402/health - Check browser console for detailed error messages
- Verify
VITE_API_URLin.envfile
Issue: "Network error"
Solutions:
- Ensure backend is accessible at the configured URL
- Check CORS settings in backend
- Verify network connectivity
Issue: Slow responses
Solutions:
- Ollama model might be loading (first request)
- Check backend logs for errors
- Verify Ollama service is running
Next Steps
Potential improvements:
- Add streaming responses for real-time text generation
- Add conversation context/memory
- Add support for document uploads
- Add voice input/output
- Add response rating/feedback