Putting an AI-Powered Data Analyst to the Test | by John Adeojo | Jul, 2023

Exploring the Automation of Ad Hoc Analytics with Langchain and OpenAI

Image by Author: Generated with Midjourney

In my opinion, analytics has been one of the toughest arenas to operate in due to the immense volumes of ad hoc requests. Typically, it involves writing a SQL query or conducting some analysis on a spreadsheet that ends up taking longer than anticipated. This results in analytics teams spending most of their time firefighting, building tactical solutions, and never having the chance to be proactive.

I have frequently pondered on the idea of an AI assistant that could manage ad hoc analytics requests, much akin to the chatbots that are now ubiquitous in customer service. However, this always felt rather far-fetched due to the perceived complexity surrounding some analytics queries. Now, with advances in generative AI, we are at a stage where automating mundane, ad hoc requests is feasible. In this article, I present a prototype analytics bot. I evaluate the performance of the bot on some “typical” analytics requests and briefly discuss the implications for commercial analytics.

The analytics bot serves as an AI data analyst through a chat-like interface. Anyone requesting ad hoc analytics can pose questions to the bot in the same manner they would to a data analyst. The bot interprets queries in natural language, converts them into SQL, and queries the data behind it to produce a response in natural language. I have linked to the bot at the end of the article; you will need an OpenAI API key and a data source URL to try it.

Building your own prototype analytics bot is readily achieved in seven lines of Python code. The core functionality of the bot centres around Langchain and OpenAI (although you can leverage any large language model for the task). However, if you are using OpenAI, you will need an API key, for which you can register here. The bot utilises the SQLDatabaseChain API, which employs SQLAlchemy to connect to SQL databases. It can be used with any SQL dialect supported by…

Source link

Leave a Comment