How saiganesh4995/llm_sql_chatbot works
Project type and purpose
• This is a single‑page, full‑stack‑style data application built with Streamlit.
• Purpose: Let end users ask natural‑language questions in a browser, convert them to SQL via Groq LLM, run queries on a SQL Server database, and display both raw data and human‑friendly answers.
File structure
• All files live at the root level—no separate frontend/backend folders—but functionally you have:
• A Streamlit “frontend” (chatbot.py)
• Data‑processing logic in the same script (pandas, pypyodbc)
• External API integration (Groq LLM)
• SQL helper artifacts (SQLQuery1.sql, SQLQuery2.sql, SQL_Chatbot.ipynb)
• requirements.txt and .gitignore signal standard Python project conventions.
Key insights from the README
• Tech stack: Python 3.9+, Streamlit, pandas, pypyodbc, Groq LLM API
• Database schema: Four tables in SQL Server (product_info, order_status, support_contacts, faq)
• Workflow: User input → metadata extraction → prompt to Groq → execute SQL → fetch DataFrame → prompt to Groq for human answer → display results
Main components
a. User Interface
• Streamlit app (chatbot.py) in the user’s browser/host machine
b. LLM API
• Groq LLM service for:
• Generating SQL from natural language
• Generating human‑readable answers from query results
c. Database
• SQL Server instance with the four tables
d. Data Processing Layer
• Python modules: pypyodbc for ODBC connectivity, pandas for DataFrame handling
e. Retry & Error Handling
• Built‑in retry mechanism in chatbot.py
Relationships and interactions
• User → Streamlit UI: HTTP/WebSocket
• Streamlit UI → Groq API: REST calls carrying prompts
• Streamlit UI → SQL Server: ODBC calls to execute generated SQL
• SQL Server → Streamlit UI: Returns tabular data
• Streamlit UI → Groq API: Sends retrieved data context for answer generation
• Groq API → Streamlit UI → Browser: Final human‑readable answer plus raw data display
Architectural patterns & principles
• Layered architecture:
• Presentation (Streamlit)
• Application logic (prompt building, retry)
• Data access (ODBC)
• External services (LLM, Database)
• Single‑process, event‑driven flow (Streamlit reruns script on each user interaction)
• Clear separation of concerns: prompt generation, query execution, answer rendering
Technologies & frameworks
• Python 3.9+
• Streamlit for UI
• Groq LLM API (LLaMA‑3.1‑8b‑instant)
• pypyodbc (ODBC Driver 17) + pandas
• SQL Server business_data database