A Dify Chatflow that accepts user phone numbers + questions, assembles chart context, and generates AI readings.
query: string — user's natural language question (e.g., "我的职业发展如何?")phone: string — 11-digit phone numberchart_data: json — pre-calculated triangle data from mini-program (if provided)user_id: string — WeChat OpenIDcontext_builderNode ID: context_builder
Purpose: Assemble chart data into structured context for LLM
def main(query: str, phone: str, chart_data: dict, user_id: str) -> dict:
import json
# Build position descriptions
positions = {
"A": "命宫/事业", "B": "福德宫", "C": "父母宫",
"D": "迁移宫", "E": "财帛宫/财富",
"F": "夫妻宫/感情", "G": "兄弟宫", "N": "交友宫",
"H": "官禄宫", "I": "田宅宫",
"J": "疾厄宫", "M": "子女宫", "L": "仆役宫",
"K": "财库", "O": "整体/综合"
}
if chart_data:
context = "## 数字能量分析数据\n\n"
context += "### 各宫位数字\n\n"
context += "| 宫位 | 数字 | 含义 |\n"
context += "|------|------|------|\n"
for key, label in positions.items():
num = chart_data.get(key, "—")
context += f"| {key}({label}) | {num} | |\n"
# Add primary positions
primary = ["A", "E", "F", "O"]
context += "\n### 主星能量\n\n"
for p in primary:
if p in chart_data:
context += f"- {p}({positions[p]}): {chart_data[p]}\n"
# Add combinations
pairs = [("A","E"),("A","F"),("E","O"),("F","O"),("A","O")]
context += "\n### 重要数字组合\n\n"
for a, b in pairs:
if a in chart_data and b in chart_data:
context += f"- {a}({chart_data[a]}) + {b}({chart_data[b]}) = {(chart_data[a]+chart_data[b])%10}\n"
context += "\n### 手机号\n"
context += f"- {phone}\n"
else:
context = "未提供图表数据。"
# Identify question intent
intents = {
"职业": "career", "事业": "career", "工作": "career",
"财运": "wealth", "财": "wealth", "赚钱": "wealth",
"感情": "relationship", "爱情": "relationship", "婚姻": "relationship",
"健康": "health", "身体": "health",
"家庭": "family", "家人": "family"
}
intent = "general"
for keyword, it in intents.items():
if keyword in query:
intent = it
break
return {
"context": context,
"intent": intent,
"formatted": f"用户问题:{query}\n\n分析焦点:{intent}\n\n{context}"
}
Retrieves from Digital Energy knowledge base if configured.
reading_generatorSystem Prompt:
你是资深数字能量学专家。你的任务是基于用户手机号的数字能量三角图数据,提供专业、准确、有价值的解读。
## 核心原则
1. 只基于用户提供的数字进行分析,不凭空编造
2. 保持客观,不制造焦虑或过度承诺
3. 分析应该既有专业术语又通俗易懂
4. 给出建设性建议而非宿命论结论
## 解读框架
1. 主星分析:A(事业)、E(财富)、F(感情)、O(综合)
2. 数字组合:关键配对的含义
3. 具体领域分析:根据用户问题聚焦(事业/财富/感情/健康/家庭)
4. 建议和指引
## 重要格式
- 使用自然流畅的中文
- 适当分段,有层次感
- 重点数字用加粗或引号标注
User Prompt Template:
{{formatted}}
answer: string — AI response textintent: string — detected intent categoryPOST /v1/workflows/run
Authorization: Bearer {api_key}
Content-Type: application/json
{
"inputs": {
"query": "我的事业运势如何?",
"phone": "13800138000",
"chart_data": {"A": 3, "B": 5, ...},
"user_id": "wx_user_001"
},
"response_mode": "blocking",
"user": "wx_user_001"
}
{
"workflow_run_id": "run_xxx",
"data": {
"outputs": {
"answer": "根据您的数字能量分析...",
"intent": "career"
},
"status": "succeeded"
}
}
See DifyService.java for Spring Boot client implementation.