|
@@ -18,7 +18,7 @@ TOOLS = [
|
|
|
"type": "function",
|
|
"type": "function",
|
|
|
"function": {
|
|
"function": {
|
|
|
"name": "query_database",
|
|
"name": "query_database",
|
|
|
- "description": "Execute a SQL SELECT query to retrieve data. Available tables:\n1. deep_collection (id, url, content, summary, status, error_msg, created_at, updated_at)\n2. spider_result (id, task_id, title, abstract, source, cover, link, created_at)\n3. collection_task (id, keyword, source, status, created_at, finished_at)\nUse SQLite syntax.",
|
|
|
|
|
|
|
+ "description": "Execute a SQL SELECT query to retrieve data from a PostgreSQL database. Available tables:\n1. deep_collection (id, url, content, summary, status, error_msg, created_at, updated_at)\n2. spider_result (id, task_id, title, abstract, source, cover, link, created_at)\n3. collection_task (id, keyword, source, status, created_at, finished_at)\nUse PostgreSQL syntax. Use COUNT/GROUP BY for statistics. Always call this tool when the user asks about data.",
|
|
|
"parameters": {
|
|
"parameters": {
|
|
|
"type": "object",
|
|
"type": "object",
|
|
|
"properties": {
|
|
"properties": {
|
|
@@ -384,11 +384,17 @@ def analysis_chat():
|
|
|
messages = []
|
|
messages = []
|
|
|
system_prompt = model.system_prompt if model.system_prompt else "You are a helpful AI assistant."
|
|
system_prompt = model.system_prompt if model.system_prompt else "You are a helpful AI assistant."
|
|
|
system_prompt += """
|
|
system_prompt += """
|
|
|
- \nIMPORTANT:
|
|
|
|
|
- 1. You MUST use the `render_chart` tool to display charts. NEVER generate Python code (like matplotlib/pyecharts) for charts in the text response.
|
|
|
|
|
- 2. When using `render_chart`, you can generate "combined" charts by setting `type="combined"` and providing data for "bar", "pie", etc.
|
|
|
|
|
- 3. Use Markdown tables for data presentation when not using charts.
|
|
|
|
|
- """
|
|
|
|
|
|
|
+
|
|
|
|
|
+你是一个专业的数据分析助手。你可以访问以下工具:
|
|
|
|
|
+1. query_database - 查询 PostgreSQL 数据库中的采集数据。当用户询问任何关于数据的问题时,你**必须首先调用此工具**查询数据,不要凭空回答。
|
|
|
|
|
+2. render_chart - 生成图表展示数据。查询到数据后,使用此工具生成可视化图表。
|
|
|
|
|
+
|
|
|
|
|
+工作流程:
|
|
|
|
|
+- 收到用户问题 → 调用 query_database 查询相关数据 → 根据查询结果调用 render_chart 生成图表 → 用文字总结分析结果
|
|
|
|
|
+- SQL 使用 PostgreSQL 语法
|
|
|
|
|
+- 统计类问题使用 COUNT + GROUP BY
|
|
|
|
|
+- 回答使用中文
|
|
|
|
|
+"""
|
|
|
messages.append({"role": "system", "content": system_prompt})
|
|
messages.append({"role": "system", "content": system_prompt})
|
|
|
|
|
|
|
|
for m in past_messages:
|
|
for m in past_messages:
|