
具体代码如下:
import networkx as nx
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import requests
from py2neo import Graph, Node, Relationship
from datetime import datetime
# 设置字体路径
font_path = "/System/Library/Fonts/STHeiti Light.ttc" # macOS系统自带的黑体字体路径
font_prop = FontProperties(fname=font_path)
# 打印带时间戳的日志
def print_with_timestamp(message):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{timestamp}] {message}")
# 可视化知识树
def visualize_tree(tree):
pos = nx.spring_layout(tree, k=0.5, iterations=20) # 节点布局
nx.draw(tree, pos, with_labels=True, node_size=500, node_color="skyblue", font_size=8, font_weight='bold', font_family=font_prop.get_name())
plt.title("销售三步法知识树", fontproperties=font_prop)
plt.axis('off') # 关闭坐标轴
plt.show()
# 构建销售三步法知识树
def build_sales_knowledge_tree():
print_with_timestamp("正在构建初始知识树...")
tree = nx.DiGraph()
# 树干(核心理念)
core_idea = "销售三步法"
tree.add_node(core_idea)
# 树枝(方法论)
methods = [
"了解客户需求",
"提供解决方案",
"促成交易"
]
for method in methods:
tree.add_node(method)
tree.add_edge(core_idea, method)
print_with_timestamp(f"已添加方法论节点:{method}")
# 树叶(具体案例、技巧)
details = {
"了解客户需求": [
("如何了解客户的需求?", "通过开放式问题引导客户表达需求。"),
("如何建立信任关系?", "展示专业知识和成功案例。")
],
"提供解决方案": [
("如何根据客户需求提供解决方案?", "定制化方案,突出产品优势。"),
("如何处理客户异议?", "倾听并提供合理解释。")
],
"促成交易": [
("如何促成交易?", "强调产品价值和紧迫性。"),
("如何跟进潜在客户?", "定期沟通,提供支持。")
]
}
for method, qa_pairs in details.items():
for q, a in qa_pairs:
tree.add_node(q)
tree.add_node(a)
tree.add_edge(method, q)
tree.add_edge(q, a)
print_with_timestamp(f"已添加问题及其回答到知识树:\nQ: {q}\nA: {a}")
print_with_timestamp("初始知识树构建完成。")
return tree, details
# 使用大模型生成补充问题并自动生成答案
def generate_supplement_questions_with_llm(details):
print_with_timestamp("正在生成补充问题及其回答...")
prompt = "基于以下销售三步法的知识树内容,生成一些补充问题,并提供完整的回答。\n"
for method, qa_pairs in details.items():
prompt += f"\n{method}:\n"
for q, a in qa_pairs:
prompt += f"Q: {q}\nA: {a}\n"
prompt += """
请按照以下格式生成补充问题及其回答:
Q: [具体问题]
A: [详细回答]
"""
data = {
"model": "qwen2.5:14b",
"prompt": prompt,
"stream": False,
"temperature": 0.7,
"max_tokens": 400
}
try:
response = requests.post("http://127.0.0.1:11434/api/generate", json=data)
if response.status_code == 200:
response_text = response.json().get("response", "").strip()
print_with_timestamp("大模型生成的内容:")
print(response_text)
# 解析生成的问题和答案
qa_pairs = []
lines = response_text.split("\n")
i = 0
while i < len(lines):
if lines[i].startswith("Q: ") and i + 1 < len(lines) and lines[i + 1].startswith("A: "):
question = lines[i].replace("Q: ", "").strip()
answer = lines[i + 1].replace("A: ", "").strip()

最低0.47元/天 解锁文章
2610

被折叠的 条评论
为什么被折叠?



