Connecting ChatGPT to a PostgreSQL Database

Connecting ChatGPT to a PostgreSQL Database

At AINIRO we just delivered a financial assistant AI chatbot. The system is the core product of a SaaS company created by a Swedish partner of us, and allows to use natural language, OpenAI, and ChatGPT to ask questions about Swedish companies. You can see a screenshot of the system below.

Fintell AI chatbot answering questions and showing charts

Requirements

The client had access to an SFTP site that contains a bunch of CSV files. These files would contain information about every single company in Sweden based upon their quarterly reporting to the Swedish government. The client came to us and told us to turn these CSV files into an AI chatbot, specialised in answering questions related to his data, so we set out to help the client and implemented the system from scratch. The system had to be able to do the following:

  • Use the data from the client's CSV files as the foundation to answer questions from users.
  • Allow users to log in using SSO, which we solved by implementing OpenID Connect, and configure it such that users can use their Google accounts to register and authenticate.
  • Display financial charts for specific prompts by default.
  • Allow users to download PDF reports.
  • Allow users to ask some free questions per day, and only once the user's free questions were exhausted the system would ask for payments.
  • Automatically connect to Stripe to allow for creating subscriptions that would automatically deduct money from its users' accounts once per month.

Basically, the system needed to be a complete financial AI assistant type of chatbot, and its intention was to become the product of a SaaS company, selling subscriptions to allow access to the system.

Implementation

The first thing we had to do was to model a database. We chose PostgreSQL due to its scalability and high quality. Connecting PostgreSQL to Magic Cloud is also very easy. Once we connected Magic to the database, creating the Hyperlambda AI workflow files for connecting the AI chatbot to the database was easy. Below you can see an example AI workflow created in Hyperlambda.

Fintell AI workflow

The complexity of the system's backend is not very large. The system contains 747 lines of code in total, which includes the Hyperlambda files required to generate charts, query the database, and interact with the system.

The only challenge we had was related to the CSV files not being conforming to standards, in addition to creating a cron job executing a Python script that would automatically import changes once every 24 hour.

AI Expert System

Since we already had our AI Expert System, we didn't actually have to do much frontend development. The client gave us an IP agreement, allowing us to keep the existing IP, so all we had to do was the following;

  • Implement support for SSO and OIDC in our AI Expert System, both in the frontend and the backend. This took about 20 hours in total.
  • Implement support for payments using Stripe. Another 20 hours in total.

The rest was client specific work, such as modeling the database, creating the Hyperlambda files, etc.

Wrapping up

All in all we spent about 100 hours implementing the system, and we billed the client $10,000 for the custom development. In addition the client is paying us $498 per month to host his system, which includes a handful of support hours per month.

Notice, we have previously written about how to connect ChatGPT to your database. Since then we've implemented a lot of improvements into Magic Cloud. However, to integrate ChatGPT to access your database, almost regardless of how its structure, is very easy for us due to our Magic Cloud platform.

The last point can be easily illustrated by the fact that our client got multiple offers. One from a Ukrainian outsourcing company, which offered to do the job for $12,000, but could only deliver about 25% of the features we implemented. If you want to connect your database to ChatGPT to create something similar, you can contact us below.

As a final not, I want to emphasise that AINIRO is "a different" software development company. If you're interested in seeing exactly how much different we are, I encourage you to watch the following video illustrating the AINIRO difference where I use this software system as an example of how we are different.

Thomas Hansen

Thomas Hansen I am the CEO and Founder of AINIRO.IO, Ltd. I am a software developer with more than 25 years of experience. I write about Machine Learning, AI, and how to help organizations adopt said technologies. You can follow me on LinkedIn if you want to read more of what I write.

Published 28. Oct 2024

Generative AI Opening up New Markets

In one of their latest articles Sequoia argues that AI is opening up completely new markets, similarly to how cloud computing and the mobile market space was born.

Read More

Render Charts in your AI Chatbot

By combining our Magic Cloud platform with OpenAI we've implemented an AI chatbot that dynamically renders charts.

Read More

AI Killed the GUI

The GUI's inevitable future is to be replaced by natural language apps, where we give instructions to our apps, similarly to how we instruct human beings.

Read More