The chatbot is designed to provide data analysis insights based on a predefined schema. It is built using Chainlit and OpenAI's GPT-3.5-turbo-1106 model. The chatbot utilizes OpenAI function calling to decide when to use tools and in case of db error it retries.
The chatbot has access to a range of tools, including: Database Query: Execute database queries to retrieve data. Plot Chart: Generate visualizations to help users understand data insights.
The application consists of the following components:
app.py: The main application file, which sets up the Chainlit framework and defines the chatbot's logic. bot.py: The chatbot's logic, which handles incoming user messages and generates responses using the OpenAI API. utils.py: Utility functions for db introspection and format conversion tools.py: Tool functions for executing database queries and plotting charts. .env: openai api key
Here's a high-level overview of how the application works:
- The user sends a message to the chatbot.
- The response may include tool calls. Tool calls include fetching results from database or generating plots.
- The tool results are added back to the list of conversation messages. Everything including tool results, error messages are added to the conversation and sent back to llm to get a second response.
- The Execution loop is run for MAX_ITER times if each new response has a tool call.
- The chatbot sends the response back to the user, including any plots or tables generated by the tool calls.
This repository contains a chatbot application built using Chainlit and OpenAI's GPT-3.5-turbo-1106 model. The chatbot provides data analysis insights based on a predefined schema and tools, utilizing Agent AI and reflection capabilities to improve its accuracy.