General Introduction
TableGPT Agent is an intelligent tool based on the GitHub open source project designed for processing and analyzing tabular data. It relies on the TableGPT2 Big Language Model, which utilizes natural language interactions to make it easy for users to query, manipulate, and understand complex table content. Whether it's extracting data from CSV files, generating visual charts, or answering specific table-based questions, this tool gets the job done efficiently. It was developed by the tablegpt team and is built on the Langgraph It supports a variety of table-related application scenarios, and is ideal for users who need to analyze data but are not good at programming. The project is licensed under the Apache 2.0 license, and developers are encouraged to contribute, with active community support on GitHub.
Function List
- Table data reading and processing: Supports reading and structuring table data from locally uploaded CSV, Excel files or databases.
- natural language query:: Users can ask questions in everyday language, such as "How many males survived?" or "What are the top selling products?" or "What is the highest selling product?". : Users can ask questions in everyday language, such as "How many men survived?
- Automatic code generation: Generate Python code based on user needs, such as filtering data, calculating statistics, or drawing charts.
- Data Visualization Support: Work with the tool to generate line graphs, bar charts and other visualization results, intuitively show the conclusions of data analysis.
- Complex Forms Task Support:: Handle multi-layered tabular structures or irregular data to provide accurate analytical results.
- session memory function: Support for multiple consecutive rounds of conversations by preserving the analysis context through checkpointer and session_id.
- Open Source Scalability: Provides a rich API and documentation that allows developers to customize features or integrate them into other projects.
Using Help
Installation process
TableGPT Agent is a Python based tool that requires certain environment configuration to run. The following are the detailed installation steps:
1. Environmental preparation
- Installing Python: Make sure you have Python 3.8 or later installed on your computer, which you can download from the official Python website.
- Installing Git: For cloning GitHub repositories, Windows/Mac users can download it from the Git website.
- Installing vLLM: TableGPT Agent Recommended vLLM Deploy the TableGPT2 model to ensure efficient inference. Run the following command:
pip install vllm==0.5.5 --extra-index-url https://download.pytorch.org/whl/cu124
(Adjusted to your CUDA version) cu124
(You can skip this step if you don't have a GPU, but you will need to deploy the model manually).
2. Cloning of warehouses
Open a terminal (CMD or PowerShell for Windows, Terminal for Mac/Linux) and run it:
git clone https://github.com/tablegpt/tablegpt-agent.git
cd tablegpt-agent
3. Installation of dependencies
In the project directory, install the required Python libraries:
pip install -r requirements.txt
Install additional dependencies if you need to run full functionality locally:
pip install ".[local]"
4. Deployment of the TableGPT2 model
TableGPT Agent requires TableGPT2 model support. First download the model from Hugging Face (e.g. TableGPT2-7B) and then start the service using vLLM:
python -m vllm.entrypoints.openai.api_server --served-model-name TableGPT2-7B --model path/to/weights
When the service starts, it listens by default to the http://localhost:8000
If you do not want to use this URL, write down the URL.
5. Configuring agents
Edit the code or configuration file to point the LLM's API address to the vLLM service you deployed, for example:
llm = ChatOpenAI(openai_api_base="http://localhost:8000/v1", openai_api_key="whatever", model_name="TableGPT2-7B")
Usage
After the installation is complete, TableGPT Agent is ready to run. Below is the detailed operation procedure of the main functions:
Function 1: Read Table Data
- Preparing data files: Place the CSV or Excel file in a local directory (e.g.
gpt_workspace
(folder). - Enabling Agents: Initialize the agent by running the following code in a Python environment:
from langchain_openai import ChatOpenAI from langgraph.checkpoint.memory import MemorySaver from pybox import LocalPyBoxManager from tablegpt.agent import create_tablegpt_graph llm = ChatOpenAI(openai_api_base="http://localhost:8000/v1", openai_api_key="whatever", model_name="TableGPT2-7B") pybox_manager = LocalPyBoxManager() checkpointer = MemorySaver() agent = create_tablegpt_graph(llm=llm, pybox_manager=pybox_manager, checkpointer=checkpointer, session_id="my-session")
- Uploading files: Use the following code to upload a file and let the agent read it:
from datetime import date from tablegpt.agent.file_reading import Stage from langchain_core.messages import HumanMessage attachment_msg = HumanMessage(content="请读取文件 data.csv", additional_kwargs={"file_path": "path/to/data.csv"}) response = await agent.ainvoke( input={"entry_message": attachment_msg, "processing_stage": Stage.UPLOADED, "messages": [attachment_msg], "date": date.today()}, config={"configurable": {"thread_id": "my-thread"}} ) print(response["messages"])
The agent returns an acknowledgement that the file has been read.
Function 2: Natural Language Query
- ask questions: In the same session, continue typing questions:
human_message = HumanMessage(content="有多少行数据?") response = await agent.ainvoke( input={"messages": [human_message], "date": date.today()}, config={"configurable": {"thread_id": "my-thread"}} ) print(response["messages"])
- in the end: The agent will return an answer such as "There are 100 rows of data".
Function 3: Generate visualization charts
- Request Chart:: Enter something like "Plot a bar graph of sales":
human_message = HumanMessage(content="绘制销售额的柱状图") async for event in agent.astream_events( input={"messages": [human_message], "date": date.today()}, config={"configurable": {"thread_id": "my-thread"}}, version="v2" ): if event["event"] == "on_chat_model_end": print(event["data"]["output"])
- exports: The agent generates Python code and returns the chart results (with a library such as matplotlib running locally).
Function 4: Complex Task Processing
For multi-layer tables or irregular data, ask a direct question such as "Count the average age of each department" and the agent will automatically parse and generate the results.
caveat
- environmental dependency: Ensure that the network is unobstructed and the vLLM service is functioning properly.
- file path: Provide the correct path when uploading files.
- Session Management: Use the same
session_id
cap (a poem)thread_id
Maintain contextual continuity.
With the above steps, you can easily get started with TableGPT Agent and complete the whole process from data reading to analysis!