BigQuery Chatbot is an intelligent conversational AI that interacts with Google BigQuery to fetch and analyze data. It integrates LangChain, Streamlit, and LangSmith for real-time query execution, schema inspection, and chatbot monitoring.
✅ Conversational AI: Uses Google Generative AI (Gemini) for intelligent responses.
✅ BigQuery Integration: Fetches schemas and executes queries in real-time.
✅ Session-based Memory: Maintains persistent conversation history.
✅ LangSmith Integration: Tracks and evaluates chatbot performance.
✅ Streamlit UI: User-friendly web interface for interacting with BigQuery.
git clone https://github.com/espin086/BigQueryChat
cd bigquery_chatbotpython -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windowspip install -r requirements.txtTo configure the chatbot, create a .env file by copying the provided .env.template:
cp .env.template .envThen, open .env and update the values with your Google Cloud and LangSmith API credentials:
GOOGLE_API_KEY=your_api_key_here
GOOGLE_APPLICATION_CREDENTIALS=/path/to/your_gcp_json_key.json
PROJECT_ID=your_bigquery_project_id
DATASET_ID=your_bigquery_dataset_name
LANGCHAIN_PROJECT=your-langsmith-project
LANGCHAIN_API_KEY=your-langsmith-api-keyNote: Make sure to provide the correct Google Cloud service account JSON key to authenticate BigQuery access.
streamlit run streamlit_app.pyChatbot can retrieve the schema of a BigQuery table. Example prompt:
You can execute SQL queries using natural language prompts:
bigquery_chatbot/
│── src/
│ ├── agent.py # Defines LangChain agent
│ ├── tools.py # Tools for fetching schema and executing queries
│ ├── bigquery_manager.py # Handles BigQuery interactions
│ ├── sql_lite_handler.py # Manages SQLite database for chat history
│ ├── format_message.py # Formats the LLM response for display
│ ├── utils/
│ ├── config.py # Database configurations
│── streamlit_app.py # Streamlit UI
│── requirements.txt # Dependencies
│── README.md # DocumentationLangSmith is used to trace, monitor, and evaluate chatbot performance in real-time.
-
Go to LangSmith ➡️ LangSmith Platform
-
Create a Project and Generate an API Key (If you haven't already).
-
Update Your
.envFile with the LangSmith details:LANGCHAIN_PROJECT=your-langsmith-project-name LANGCHAIN_API_KEY=your-langsmith-api-key
Add the following code snippet to ensure LangSmith is tracking all interactions:
from langchain.callbacks.tracers import LangChainTracer
from dotenv import load_dotenv
import os
# Load API keys from environment variables
load_dotenv()
langsmith_tracer = LangChainTracer()
llm = ChatGoogleGenerativeAI(
model="gemini-1.5-pro",
temperature=0,
max_tokens=None,
callbacks=[langsmith_tracer],
)Now, all chatbot interactions will be logged in LangSmith!
Once the chatbot is running, you can track its performance via the LangSmith Dashboard.







