AI Copilot Integration
Relevant source files
The following files were used as context for generating this wiki page:
The AI Copilot Integration is a comprehensive system designed to provide interactive, AI-driven assistance to users of the BV-BRC platform. It facilitates conversational queries regarding genomic data, platform services, and general bioinformatics questions. The system is built on a modular architecture that separates API communication, session management, and UI rendering.
The integration supports standard chat interactions as well as advanced features like Retrieval-Augmented Generation (RAG) and page-aware context. By utilizing RAG, the Copilot can provide answers grounded in specific databases, such as the BV-BRC help center or scientific journals. Additionally, it can capture and analyze the current page content or screenshots to provide context-sensitive assistance.
Sources: public/js/p3/widget/copilot/CopilotApi.js, public/js/p3/widget/copilot/ChatSessionContainer.js:1-30
System Architecture
The Copilot system follows a client-server model where a Dojo-based frontend communicates with a PATRIC Copilot backend service.
Core Components
| Component | Description |
|---|---|
| CopilotApi | Handles all HTTP communication with the backend, including authentication and session state. |
| ChatSessionContainer | A BorderContainer that coordinates the layout and lifecycle of a chat session. |
| CopilotInput | Manages the user text area, submission logic, and context gathering (e.g., screenshots). |
| CopilotDisplay | Renders the conversation history, including markdown support and loading indicators. |
| ChatSessionOptionsBar | Provides UI for configuring AI models, RAG databases, and prompt enhancements. |
Sources: public/js/p3/widget/copilot/ChatSessionContainer.js:40-60, public/js/p3/widget/copilot/CopilotApi.js:10-30, public/js/p3/widget/copilot/CopilotInput.js:10-25
Data Flow Overview
The following diagram illustrates the flow of a user query from the UI to the backend and back.
The system uses a centralized ChatMemoryStore to persist messages within a session and dojo/topic for inter-component communication.
Sources: public/js/p3/widget/copilot/ChatSessionContainer.js:80-100, public/js/p3/widget/copilot/CopilotInput.js:150-180
API Implementation
The CopilotApi class is the primary interface for backend communication. It manages base URLs initialized from window.App.copilotApiURL and window.App.copilotDbURL.
Key API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/chat | POST | Submits a regular chat query with session and model data. |
/copilot | POST | Combined endpoint for chat, RAG, and image-based queries. |
/start-chat | GET | Generates a new unique session identifier. |
/get-session-messages | GET | Retrieves the full message history for a specific session. |
/get-model-list | POST | Fetches available LLM models and RAG vector databases. |
/rate-message | POST | Allows users to provide feedback on specific AI responses. |
Sources: public/js/p3/widget/copilot/CopilotApi.js:58-200, public/js/p3/widget/copilot/CopilotApi.js:370-400
Interaction Sequence
The sequence for submitting a query involves state management and asynchronous response handling.
Feature Modules
Retrieval-Augmented Generation (RAG)
The Copilot uses RAG to provide domain-specific answers. Users can select different databases via the ChatSessionOptionsBar. Common databases include bvbrc_helpdesk and cepi_journals. When a RAG query is performed, the system retrieves a specified number of documents (defaulting to 3) to provide context to the LLM.
Sources: public/js/p3/widget/copilot/ChatSessionOptionsBar.js:115-160, public/js/p3/widget/copilot/CopilotInput.js:155-170
Page Context and Screenshots
The CopilotInput and CopilotInputSidePanel widgets support an "Ask about page" feature. This utilizes html2canvas to take a screenshot of the current document body, which is then sent as a base64 encoded image to the /copilot endpoint. If screenshot capture fails, the system falls back to sending the raw HTML content of the page.
Sources: public/js/p3/widget/copilot/CopilotInput.js:365-420, public/js/p3/widget/copilot/CopilotInputSidePanel.js:140-180
Session Management
Chat sessions are persistent and tracked via ChatSessionsMemoryStore.
- Title Generation: The system can automatically generate a title for a session by analyzing the first few messages of a conversation.
- Path Monitoring: The
ChatSessionContainermonitorswindow.locationchanges every 3 seconds to update the "path state," allowing the Copilot to stay aware of the user's current tool or data view.
Sources: public/js/p3/widget/copilot/ChatSessionContainer.js:180-210, public/js/p3/widget/copilot/ChatSessionContainer.js:460-490
Conclusion
The AI Copilot Integration provides a robust framework for AI assistance within the BV-BRC ecosystem. Its design ensures that AI responses are contextually relevant to the user's current activity and grounded in authoritative documentation through RAG. The modular Dojo implementation allows for flexible UI placement, such as floating windows or side panels, while maintaining a consistent interface with the backend services.