data-analysis-llm-agent
https://github.com/fanqingsong/data-analysis-llm-agent
Conversational AI with Function Calling for Data Analysis
Overview
The chatbot is designed to provide data analysis insights from database 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.
Available Tools
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.
Code
app.py: The main application file, which sets up the Chainlit framework and defines the chatbot's logic.
bot.py: The chatbot class which handles conversation history, talking to llm and parallel function calling.
utils.py: Utility functions for db introspection and format conversion.
tools.py: Tool functions for executing database queries and plotting charts.
.env: openai api keyData
It uses simple sqlite3 database of movie and actors from https://github.com/slackhq/sqlite-python-connect/. The schema is very simple with only two tables but should work with more complex schema.
How it Works
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.
demo
标签:database,chatbot,agent,analysis,llm,data,tool From: https://www.cnblogs.com/lightsong/p/18403320