> ## Content Index
> Fetch the complete content index at: https://www.hubwiz.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# ComfyUI-PandasAI数据分析包
- URL: https://www.hubwiz.com/blog/comfyui-pandasai/
- Published: 2024-12-06T14:46:49.000Z
- Updated: 2024-12-06T15:45:14.000Z
- Description: ComfyUI-PandasAI是ComfyUI平台上的数据分析自定义节点包，可以采用自然语言分析本地csv/xlsx文件，或Sqlite、MySQL、PostgreSQL等数据库。
- Author: admin
- Tags: TOOL, COMFYUI, COMFYUI-PANDASAI, #Import 2026-10-14 14:41

[ComfyUI-PandasAI](http://sc.hubwiz.com/codebag/comfyui-pandasai/?ref=hubwiz.com)是ComfyUI平台上的数据分析自定义节点包，可以采用自然语言分析本地csv/xlsx文件，或Sqlite、MySQL、PostgreSQL等数据库。

## 1、代码组织

ComfyUI-PandasAI节点包的目录组织说明如下：

| 文件路径                               | 文件说明                               |
| ---------------------------------- | ---------------------------------- |
| requirements.txt                   | 依赖包清单文件                            |
| \_\_init\_\_.py                    | 包入口文件                              |
| py/                                | 自定义节点目录                            |
| py/smart\_dataframe.py             | SmartDataframe节点                   |
| py/chat\_with\_smart\_dataframe.py | ChatWithSmartDataframe节点           |
| py/agent.py                        | Agent节点                            |
| py/chat\_with\_agent.py            | ChatWithAgent节点                    |
| py/bamboom\_llm.py                 | BambooLLM节点                        |
| py/openai\_llm.py                  | OpenAI节点                           |
| py/google\_palm\_llm.py            | Google Palm节点                      |
| py/google\_vertexai\_llm.py        | Google VertexAI节点                  |
| py/azure\_openai\_llm.py           | Azure OpenAI节点                     |
| py/huggingface\_textgen\_llm.py    | HuggingFace TextGen节点              |
| py/custom\_llm.py                  | CustomLLM节点                        |
| py/file\_connector.py              | FileConnector节点                    |
| py/sql\_connector.py               | SQLConnector节点                     |
| py/sqlite\_connector.py            | SqliteConnector节点                  |
| py/mysql\_connector.py             | MySQLConnector节点                   |
| py/postgresql\_connector.py        | PostgreSQLConnector节点              |
| web/                               | 前端扩展目录                             |
| web/pandasai.js                    | 前端扩展                               |
| examples/                          | 示例工作流目录                            |
| examples/smart\_dataframe.json     | 使用SmartDataframe分析本地csv或xlsx文件的工作流 |
| examples/supported-connectors.json | 数据源节点一览                            |
| examples/supported-llms.json       | 大模型支持节点一览                          |
| datasets/                          | 示例数据集目录                            |
| coffee.csv                         | 咖啡店订单数据，csv格式                      |
| loan\_payments.csv                 | 贷款支付数据，csv格式                       |
| Loan payments data.xlxs            | 贷款支付数据，xlxs格式                      |
| employees\_db.zip                  | 员工数据，sqlite格式，zip压缩                |

## 2、安装

将节点包解压到 `ComfyUI/custom_nodes` 目录下，结果如下所示：

```
ComfyUI
  |- custom_nodes
        |- ComfyUI-PandasAI
              |- __init__.py
              |- ...

```

然后进入 `ComfyUI-PandasAI` 目录，执行如下命令安装依赖包：

```
pip install -r requirements.txt

```

## 3、使用示例数据集快速上手

在ComfyUI界面中，点击【Load】按钮载入 `examples/smart_dataflow.json`工作流，如下图所示：

![smart dataframe example workflow](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/example-smart-dataframe.png)

`SmartDataframe`节点类似于使用LLM大模型增强的表格数据集，可以使用自然语言分析数据集。 它的输入有两个：

- llm：用于分析自然语言的大模型
- connector：数据源连接器，可以连接本地文件或sql数据库等。

在这个工作流中，使用了 `Custom LLM` 节点来访问Groq的API，主要参数如下：

- api\_base: OpenAI兼容API访问基址，对于Groq来说，这个值是 `https://api.groq.com/openai/v1`
- api\_key: 大模型服务商的API KEY，Groq可以在[这里](https://console.groq.com/keys?ref=hubwiz.com)创建API Key
- model：使用的大模型，这里使用 `llama3-8b-8192` 模型

示例工作流使用的数据源连接器是 `File Conector`，用来访问本地的数据文件，目前支持csv格式和xlxs 格式，点击 【upload】按钮即可上传本地其他目录的数据文件。

`Chat With Smart Dataframe`节点是我们输入的地方，例如查询贷款支付数据中男女各有多少人，可以输入：

> 贷款的男女各有多少人？

工作流的输出使用了ComfyUI-Custom-Scripts节点包中的 `show text`节点，用于显示结果文字，如上图所示：

```
    Gender Count
0    male   423
1   female   77

```

## 4、数据源自定义节点

### 4.1 FileConnector

![file connector node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/file-connector.png)

FileConnector可以上传本地的数据文件作为数据分析的数据源，目前支持csv和xlxs。

输入：

- file：已上传的数据文件

输出：

- connector：数据源连接对象

### 4.2 SqliteConnector

![sqlite connector](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/sqlite-connector.png)

SqliteConnector以本地的sqlite数据库文件作为数据分析的数据源。

输入：

- file：sqlite数据库文件本地路径

输出：

- connector：数据源连接对象

### 4.3 MySQLConnector

![MySQL Connector](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/mysql-connector.png)

MySQLConnector以MySQL数据库表作为数据源。

输入：

- host：MySQL主机地址
- port：MySQL服务端口
- database：数据库名称
- username：用户名称
- password：用户密码
- table：数据表名称

### 4.4 PostgreSQLConnector

![PostgreSQL Connector](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/postgresql-connector.png)

PostgreSQLConnector以PostgreSQL数据库表作为数据源。

输入：

- host：PostgreSQL主机地址
- port：PostgreSQL服务端口
- database：数据库名称
- username：用户名称
- password：用户密码
- table：数据表名称

## 5、LLM大模型自定义节点

### 5.1 BambooLLM

![bamboo llm node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/bamboo-llm.png)

BambooLLM 主要针对数据分析。它旨在理解和执行与数据分析、数据处理和数据可视化相关的自然语言查询。 可以在[这里](https://pandabi.ai/?ref=hubwiz.com)注册以获取免费 API 密钥。

输入：

- api\_key：API密钥

输出：

- llm：LLM对象。

### 5.2 OpenAI

![openai llm node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/openai-llm.png)

为了使用 OpenAI 模型，你需要一个 OpenAI API 密钥。可以在 [此处](https://platform.openai.com/account/api-keys?ref=hubwiz.com)获取一个。

输入：

- api\_key：API KEY
- model：使用的大模型，默认：gpt-4

输出：

- llm：LLM对象

### 5.3 GooglePalm

![google palm node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/google-palm-llm.png)

为了使用 Google PaLM 模型，你需要拥有 Google Cloud API 密钥。可以在[此处](https://developers.generativeai.google/tutorials/setup?ref=hubwiz.com)获取一个。

输入：

- api\_key: API密钥

输出：

- llm：LLM对象

### 5.4 GoogleVertexAI

![google vertexai node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/google-vertexai-llm.png)

为了通过 Vertexai api 使用 Google PaLM 模型，需要先创建Google Cloud 项目、设置项目区域并完成gcloud身份验证。

输入：

- project\_id：项目编号
- location：区域
- model：使用的模型名称

输出：

- llm：LLM对象

### 5.5 AzureOpenAI

![azure openai llm node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/azure-openai-llm.png)

为了使用 Azure OpenAI 模型，需要拥有 Azure OpenAI API 密钥以及 Azure OpenAI 端点。可以在 [此处](https://azure.microsoft.com/products/cognitive-services/openai-service?ref=hubwiz.com)获取。

要实例化 Azure OpenAI 对象，您还需要指定在 Azure 上部署的模型的名称和 API 版本：

输入：

- api\_token: API密钥
- azure\_endpoint：访问端点
- api\_version：api版本
- deployment\_name：部署的名称

输出：

- llm：LLM对象

### 5.6 HuggingFaceTextGen

![huggingface textgen llm node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/huggingface-textgen-llm.png)

为了通过文本生成使用 HuggingFace 模型，需要首先提供一个受支持的大型语言模型 (LLM)。 阅读[文本生成文档](https://huggingface.co/docs/text-generation-inference/index?ref=hubwiz.com)以了解有关如何设置推理服务器的更多信息。

例如，这可用于使用 LLaMa2、CodeLLaMa 等模型。可以在[此处](https://huggingface.co/docs/text-generation-inference/index?ref=hubwiz.com)找到有关文本生成的更多信息。

输入：

- inference\_server\_url：推理服务器url

输出：

- llm：LLM对象

### 5.7 CustomLLM

![Custom llm node](http://sc.hubwiz.com/codebag/comfyui-pandasai/img/custom-llm.png)

CustomLLM节点用来加载自定义模型，可以是本地模型，如Ollama或LM Studio托管的模型，也可以是云端模型，例如Groq托管的模型， 只要提供OpenAI兼容的API即可。

输入：

- api\_base：API基地址，需要与OpenAI兼容
- api\_key：API密钥，云平台托管的模型服务，通常需要设置这个密钥
- model：模型名称

输出：

- llm：LLM对象

---

原文链接：[ComfyUI-PandasAI节点包](http://sc.hubwiz.com/codebag/comfyui-pandasai/?ref=hubwiz.com)

汇智网编辑整理，转载请标明出处