In this example we ask a a question that requires joining tables in a relational database (Chinook) to give a response.
Video:
Coming soon…
User question: Give me the top 10 selling artists.
VerbaGPT response:
Cost of query: $0.00
Answer:
('Iron Maiden', 140) ('U2', 107) ('Metallica', 91) ('Led Zeppelin', 87) ('Os Paralamas Do Sucesso', 45) ('Deep Purple', 44) ('Faith No More', 42) ('Lost', 41) ('Eric Clapton', 40) ('R.E.M.', 39)
VerbaGPT answered the question correctly. Since VerbaGPT comes with an embedding framework, it did not have to be told where to look, only pointed to a SQL server instance that contains many different databases including one that has the Chinook database. Chinook is a standard SQL database used for testing. Further, VerbaGPT provided a complete response, along with a helpful option to save the datable to a csv file.
VerbaGPT Message Window
The code below results in a complete answer, and user can edit and run it if they choose. This query is not straightforward, and required multiple joins to answer.
query = '''
SELECT TOP 10 Artist.Name, SUM(InvoiceLine.Quantity) AS TotalSold
FROM Artist
JOIN Album ON Artist.ArtistId = Album.ArtistId
JOIN Track ON Album.AlbumId = Track.AlbumId
JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId
GROUP BY Artist.Name
ORDER BY TotalSold DESC
'''
cursor.execute(query)
results = cursor.fetchall()
for row in results:
print(row)
LangChain + OpenAI response:
Cost of query: $0.16
While the langchain query errored out, it did in fact compute the correct response – it just didn’t output it. We can see that it came up with the correct query, and also the SQLResult matches what VerbaGPT output.
The error looks like something to do with token-length.
The langchain agent did need an explicit and direct connection to the relevant database (i.e., Chinook) in order to try to answer this question.
Leave a Reply