How trinity-syt-security/testlinetogemini works
Project Type and Purpose
• This is a backend‐focused, serverless “smart study assistant” service, implemented as a Flask webhook that integrates with the LINE Messaging API and Google Gemini LLM.
• Users send text or images via LINE; the service retrieves fallback knowledge, filters for security, calls Gemini, and returns study guidance. It also logs interactions and can export reports to Excel.
High-Level Components
a. LINE Users & LINE Messaging API
• The entry point for user requests (text or image).
b. Serverless Flask Webhook (api/webhook.py)
• Deployed on Vercel (serverless function) or any Python host.
• Receives HTTP POSTs from LINE, parses events.
c. GeminiResponder (src/gemini_responder.py)
• Applies safety filters, constructs prompts, calls Google Gemini LLM via google-generativeai SDK.
d. KnowledgeRetriever (src/knowledge_retriever.py)
• Supplies fallback knowledge (e.g., local JSON, YAML, or embedded dataset) when Gemini alone isn’t enough.
e. ReportManager (src/report_manager.py)
• Logs every interaction (user message, AI response) to a local or ephemeral store.
• Optionally exports logs as Excel via pandas/openpyxl.
f. External Services & Storage
• Google Gemini LLM API (for AI reasoning)
• LINE Messaging API (user interface)
• Local “reports” directory or object store (for Excel exports)
• Vercel for deployment configuration (vercel.json)
Relationships & Data Flows
• User → LINE Messaging API → Webhook
• Webhook → (KnowledgeRetriever + GeminiResponder) → Google Gemini API
• GeminiResponder → Webhook → LINE Messaging API → User
• Webhook → ReportManager → Reports Dir/Excel
• Environment Variables (LINE_TOKEN, GEMINI_API_KEY) injected into serverless runtime
Architectural Patterns & Principles
• Modular Monolith: Each core function is a module (responder, retriever, reporter) called by a single HTTP entry point.
• Single Responsibility: Webhook handles HTTP; GeminiResponder handles AI calls & filtering; KnowledgeRetriever handles fallback data; ReportManager handles logging.
• Serverless Friendly: Designed to meet Vercel size/time constraints (no heavy dependencies, no persistent DB).
• Security Layers: Input filtering before prompt construction; length checks; sensitive content filtering.