Rostaing的模型内容协议(Rostaing-mcp)
通用模型内容协议(MCP) 熊猫 和 波拉斯 DataFrames,旨在被GPT-4、Claude和Mistral等大型语言模型(LLM)用作强大的工具。
此软件包允许LLM安全地与数据交互,执行从简单过滤到 统计假设检验 和 数据可视化 (返回可查看的图像)。
主要特点
- 图书馆不可知论者: 无缝手柄
pandas和polars数据框架。 - 视觉智能: 生成返回的Plotly图表 Base64 PNG图像,允许LLM“查看”和生成图表。
- 统计套件: 内置支持T检验、方差分析、卡方检验、正态性检验(Shapiro)和生存分析(Logrank)。
- 智能NLU(模糊匹配): 自动纠正列名中的拼写错误(例如,理解“salary”指的是“salary_USD”)。
- 状态分析: 过滤器和修改在代理的会话上下文中持续存在。
安装
pip install rostaing-mcp*注意:这也将安装必要的依赖项,如 plotly, kaleido (用于图像生成), pingouin,以及 scipy.*
快速开始
import pandas as pd
from rostaing_mcp import DataFrameAgent, DataFrameToolHandler
# 1. Create a sample DataFrame
data = {
'employee_name': ['Rostaing', 'Lucrèce', 'Isnard', 'Charline', 'Dacier', 'Nora'],
'salary': [100000, 70000, 85000, 60000, 95000, 62000],
'experience_level': ['Expert', 'Senior', 'Manager', 'Junior', 'Principal', 'Mid-Level'],
'department': ['AI', 'Sales', 'AI', 'Sales', 'AI', 'Sales']
}
df = pd.DataFrame(data)
# 2. Initialize the core agent (Works with Polars too!)
data_agent = DataFrameAgent(df, source_description="Employee salary data")
# 3. Wrap it in the tool handler
df_tool = DataFrameToolHandler(data_agent)
# --- EXAMPLES OF DIRECT USAGE ---
# A. Inspect Data
print(df_tool.get_schema())
# B. Statistical Test (e.g., T-test between groups)
# Note: Handles fuzzy matching if you type 'Department' instead of 'department'
print(df_tool.perform_t_test(a='salary', group='department'))
# C. Visualization (Returns Base64 Image string)
# The LLM can call this to generate a chart
image_data = df_tool.plot_bar_chart(x='employee_name', y='salary', color='department')
print("Chart generated successfully (Base64 data ready).")与LLM代理(如Upsonic、LangChain)集成
为了让LLM使用所有可用的工具,您可以动态传递方法或将它们包装在代理类中。
from upsonic import Agent, Task
# Get the list of all callable tools for the LLM
tools_list = df_tool.get_all_tools()
task = Task(
description="Analyze the salary distribution and plot a bar chart by department.",
tools=tools_list
)
agent = Agent(model="openai/gpt-4o", name="Data Analyst")
result = agent.do(task)
print(result)可用工具
📊 可视化
plot_histogram,plot_bar_chart,plot_line_chartplot_scatter_plot,plot_box_plot,plot_violin_plotplot_heatmap,plot_pie_chart,plot_3d_scatter以及更多。
🧮 统计
get_summary_statistics,get_correlation_matrixperform_normality_test(夏皮罗·威尔克)perform_t_test(学生t检验)perform_anova(单因素方差分析)perform_chi2_test(独立)perform_logrank_test(生存分析)
🛠 操纵
filter_rows(支持复杂条件)sort_valuesselect_columns
