talk to your database using natural language

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 42270
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

talk to your database using natural language

Post by Antonio Linares »

Recently we found a tool that lets you talk to your database using natural language thanks to AI.

So we are going to implement the same funcionality using FWH and FWH AI Classes.

This is a true AI agent and it is a great example of what AI power can do for you :)

Stay tunned... :wink:
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 6380
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: talk to your database using natural language

Post by Otto »

Dear Antonio,

we use a simple method since we don't have the expertise that you do. However, even with this, we achieve good results.
Yesterday, I looked at your example in the AI section. I then thought that if JSON or CSV databases are suggested for such examples, a modernized DBF could experience a revival here.

According to AI, the following improvements should be made:

Potential Improvements to the DBF Format
To make DBF more competitive in the context of AI, the following enhancements could be introduced:

Support for Larger Datasets:
Raising file size and field number limits to keep up with modern requirements.
Compression:
Integrated support for compression to save storage space.
Advanced Data Types:
Support for complex data types such as JSON, arrays, or BLOBs.
Timestamps and Logging:
Automatic logging of changes or accesses, similar to relational databases.
Encryption:
Support for native encryption to protect sensitive data.
DBF could have advantages over CSV and MySQL in the AI context, especially in scenarios like:

Smaller, local applications.
Simple data structures.
Systems with limited resources.

With some modern adaptations, DBF could be considered a lightweight and robust alternative, particularly for specialized AI applications. The format has potential if it is systematically modernized.


I have built a very convenient converter with PHP2DBF.

DBF2JSON Converter: Interactive DBF Query and JSON Transformation Tool


You simply enter the database path and name, the fields that should go into the JSON, and then let ChatGPT create the query function for you, e.g.:



For example, I could say: Only output bookings from August 25, 2024, and rename the field to "Reservation Date." Add the weekday to it.

You then enter the function created by ChatGPT into the designated text field and say "Convert JSON."

And you will receive the final JSON output.


Image


How does it continue?
I then ask ChatGPT further, for example:

Can you now create a nicely designed arrival list using Bootstrap and Awesomefont, with a table and a field for manual check-off? Please read the data from the JSON file anreisen.json. We have 34 rooms. There are 13 regular guests and those arriving, as listed in the JSON. Also, make me a chart for it.

The unoccupied rooms must be displayed in the chart. The chart should be a maximum of 300 pixels high.

I get the HTML code and already have the report ready. I will then post my previous development in terms of HTML reports.

Image




Best regards,

Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42270
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: talk to your database using natural language

Post by Antonio Linares »

Working example:

Using the simple technique we can talk to any database using natural language! :D

agentdb.prg

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local oChat := TDeepSeek():New()
   local dummy := FW_SetUnicode( .T. )
   local cDatabase := "foros_antiguos"
   local oCn   := maria_Connect( "localhost," + cDatabase + ",fivetec1_antonio,1234", .T. )
   local aTables, cTable
   local hDatabase := { => }, cJson

   if oCn == nil
      MsgAlert( "Error connecting to database" )
      return nil 
   endif   

   aTables = oCn:ListBaseTables()

   for each cTable in aTables
      hDatabase[ cTable ] = oCn:ListColumns( cTable ) 
   next   

   oChat:Send( "tell me the SQL sentence to list the 10 more active users in the forums using this info," + ;
               " give me the SQL sentence, no explanations. Remove the '''SQL from the beginning and the ''' from the end: " + ;
               hb_jsonEncode( hDatabase ) )
   XBrowser( oCn:Execute( oChat:GetValue() ) )

   oChat:End()

return nil   
Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 6380
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: talk to your database using natural language

Post by Otto »

Dear Antonio,
thank you. Can you show this for dbf?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42270
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: talk to your database using natural language

Post by Antonio Linares »

Dear Otto,

You have to provide all the DBFs structures info to an AI API and then provide the right prompt for it.

That simple :)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply