How eduardr02/faster-chatgpt works
Project Type and Purpose
• The project is a Chrome extension that wraps various language model APIs (OpenAI, Anthropic, Gemini, etc.) to provide “1 click answers” across web pages.
• It offers multiple modes (chat, side panel, arena, and thinking modes) and includes support for both text and images along with chat history management.
File Structure
• Top-Level Files:
– manifest.json: The extension manifest defining permissions, scripts, and UI pages (popup, sidepanel).
– README.md, LICENSE, .gitignore, privacy_policy.md: Project documentation and legal info.
• src Directory:
– css, html: Styling and markup for various user interfaces like history, popup, settings, and sidepanel.
– js: Contains multiple JavaScript modules; examples include:
• background.js – the background script coordinating between different parts of the extension.
• content.js – a content script that interacts with web pages (e.g., reacting to text selections).
• popup.js, sidepanel.js, sidepanel_controller.js – handle popup and side panel interfaces.
• chat_core.js, chat_storage.js, chat_ui.js – manage chat logic, history, and UI rendering.
• state_manager.js, utils.js – common utility functions and state management.
• api_manager.js – handles API requests to external LLM services.
• Additional scripts for settings and renaming suggest modular features and extensibility.
– prompts: Text files containing default prompts for chat and other operations.
README for Additional Insights
• The README details key features such as fast responses via custom prompts, model switching, arena mode with voting, thinking mode, and chat history management.
• It explains how users interact with the extension (popup, side panel, text selection) along with a rough idea of the intended user flows.
• The instructions mention the need for API keys and the visibility of these keys in the browser, a potential security consideration.
Main Components
a. Browser UI Components (Frontend Elements):
• Popup UI: Represented by popup.html and popup.js; serves as the main interaction point for direct chat inputs and settings.
• Side Panel: Represented by sidepanel.html, sidepanel.js, and sidepanel_controller.js; appears when text is selected with CTRL and provides interactive responses.
• Additional UI Pages: History (history.html) and Settings (settings.html) for managing chat history and API keys.
• Content Injection: content.js interacts with web page elements to trigger the side panel.
b. Background Process:
• Background Script: background.js acts as a central hub, managing communication between UI components (popup, side panel, content script) and linking them to backend logic.
c. Core Business Logic:
• Chat Core & UI: chat_core.js and chat_ui.js handle the chat conversation logic and UI updates.
• Chat Storage: chat_storage.js maintains user conversation history.
• State & Utility Management: state_manager.js and utils.js manage dynamic states and shared utility functions.
d. API Communication:
• API Manager: api_manager.js encapsulates the calls to external language models, handling API communication and error management.
e. Prompts and Customization:
• Prompts Folder: Contains default prompt text files (chat_prompt.txt, prompt.txt) used in constructing and customizing API requests.
f. Additional Functionalities:
• Rename Manager and Settings: rename_manager.js and settings.js manage extension-specific configurations and dynamic model switching.
Relationships and Data Flow
– The Content Script (content.js) detects text selections and sends a message to the Background Script.
– The Background Script routes requests to the Popup UI or Side Panel UI based on the context.
– The API Manager (via api_manager.js) is invoked by these UI components (or via the background) to fetch responses from external API services.
– Chat Core (chat_core.js) manages conversation state and routing between the UI, storage (chat_storage.js), and API responses.
– Settings (settings.js) and rename_manager.js allow users to customize chat behavior and model selection.
• Use of Chrome message passing between content scripts, background scripts, and UI pages.
Architectural Patterns and Design Principles
• Separation of Concerns: Different UI components (popup, side panel) are decoupled while still coordinated via the background script.
• Extensibility: Inclusion of separate prompt files and settings modules illustrate that the system is built for easy customization and future expansion.