A React-based chat interface that converts natural language queries into SQL using IBM watsonx.ai and LangChain's ReAct agent pattern.
- Natural Language to SQL conversion powered by AI
- Interactive chat interface built with React and Tailwind CSS (dark mode)
- IBM watsonx.ai integration utilizing Mistral AI models
- ReAct agent pattern using LangChain for robust reasoning and actions
- Message persistence designed for database integration with StoredMessage serialization
- Scrollable chat UI with distinct, styled AI SQL query outputs
- Sidebar for displaying full database schema with syntax-friendly formatting
- Frontend: React, TypeScript, Tailwind CSS (with dark mode support)
- AI/ML: LangChain, IBM watsonx.ai, Mistral AI
- State Management: React useState, useRef hooks
- Build Tool: Next.js
- Node.js 18+ and npm/yarn
- IBM watsonx.ai account and API credentials
- Basic understanding of SQL, React, and AI agents
-
Clone the repository
git clone <your-repo-url> cd text-to-sql-agent
-
Install dependencies
npm install
-
Set up environment variables in
.env.local
WATSONX_AI_PROJECT_ID=your_project_id_here WATSONX_AI_ENDPOINT=https://us-south.ml.cloud.ibm.com WATSONX_AI_VERSION=2023-05-29
-
Run the development server
npm run dev
-
Open your browser at
http://localhost:3000
- Create an IBM watsonx.ai account
- Set up a new project and obtain the project ID and API endpoint
- Ensure access to Mistral AI models for natural language processing
- The default model used is
mistralai/mistral-large
(configurable inactions.ts
)
- Enter your natural language query in the input textarea.
- Press
Enter
or clickSend
(Shift+Enter inserts newline). - The agent converts your input to a SQL query, which is displayed as a syntax-highlighted code bubble.
- View your full conversation history in a scrollable chat interface.
- Reference the database schema conveniently in the sidebar for guidance.
- "Show me all customers"
- "Find orders from last week"
- "Get total sales by region ordered by create_date"
app/
├── page.tsx # Main chat UI component with dark mode and chat logic
└── actions.ts # LangChain agent and AI interaction logic
components/ # Optional reusable UI components (if applicable)
public/ # Static assets
constant.ts # Database schema SQL constants
[8](https://www.geeksforgeeks.org/git/what-is-readme-md-file/)
[9](https://confluence.atlassian.com/spaces/BitbucketServer/pages/776639995/Markdown+syntax+guide)
[10](https://learn.microsoft.com/en-us/azure/devops/project/wiki/markdown-guidance?view=azure-devops)