Skip to content

Blazor AI ChatBot that translates natural language into PostgreSQL queries then turns the result into natural language again

License

Notifications You must be signed in to change notification settings

meowwan/GeminiPostSQL_ChatBot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

See in spanish/Ver en español

GeminiPostSQL Banner

GeminiPostSQL Logo GeminiPostSQL ChatBot | AI-Assisted Blazor ChatBot for PostgreSQL

image image image Blazor image image image

Note

This is the Blazor ChatBot version meant for web client use. There is a REST API version meant for servers with Swagger and a WinForms version for Windows Desktop client use.

This ChatBot program uses Google's AI 'Gemini 2.0 Flash' to make queries to PostgreSQL databases.
The AI interprets natural language into SQL queries, run them, and transform the results into natural language again.

📋 Prerequisites

To make this program work, you'll need a PostgreSQL Server and a Gemini API Key.

Note

I'll use pgAdmin to build the PostgreSQL Server.

🛠️ Setup

If you don't have it, download pgAdmin 4 from the official website.
Now, create the PostgreSQL Server and set up a database with a few tables and insert values.

Next, obtain your Gemini API Key by visiting Google AI Studio. Ensure you're logged into your Google account, then press the blue button that says 'Create API key' and follow the steps to set up your Google Cloud Project and retrieve your API key. Make sure to save it in a safe place.
Google allows free use of this API without adding billing information, but there are some limitations.

In Google AI Studio, you can monitor the AI's usage by clicking 'View usage data' in the 'Plan' column where your projects are displayed. I recommend monitoring the 'Quota and system limits' tab and sorting by 'actual usage percentage,' as it provides the most detailed information.

You now have everything needed to make the program work.
Simply put that data you just got into the code's parameters strings.

📖 About the Blazor ChatBot

The natural-sql-natural process methods works like this:

This method maps the database structure into a JSON that Gemini analyzes to create an SQL query to fulfill the user's request, which is then run by the PostgreSQL Server, returning the requested data.

Then, this data is processed by Gemini again to summary the results into natural language.

Because the AI needs to process two requests (text to query and result table to text) the token usage is pretty high, thats why the remembering capability of the ChatBot is limited to the 5 prior messages, as is not meant to keep a single chat for too long.

The chats are not stored so the ChatBot consists in a volatile single-session chat. Press F5 to clear the current chat.

💻 Technologies Used

About

Blazor AI ChatBot that translates natural language into PostgreSQL queries then turns the result into natural language again

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 47.7%
  • HTML 30.9%
  • CSS 21.4%