美文网首页
Day 2614:学习

Day 2614:学习

作者: kafkaliu | 来源:发表于2024-03-23 23:36 被阅读0次

构建一个对话管理器。可以和client完成剧本式对练,也可以扩展成和LLM结合的对话管理。

对话流程配置

conversation = {
"start": {
"question": "你是哪位?",
"answer": {
"": "step1",
}
},
"step1": {
"question": "你有什么事?",
"answer": {
"
": "step2",
}
},
"step2": {
"question": "好的。",
"answer": {
"*": "end",
}
},
"end": {
"question": "再见!",
"answer": {}
}
}

当前对话状态

current_state = "start"

对话循环

while current_state != "end":
# 获取当前状态的消息和选项
state_data = conversation[current_state]
question = state_data["question"]
answer = state_data["answer"]

# 显示消息并获取用户输入
user_input = input(question).strip()

# 忽略学员输入,继续脚本
current_state = answer["*"]

对话结束

print(conversation["end"]["question"])

相关文章

网友评论

      本文标题:Day 2614:学习

      本文链接:https://www.haomeiwen.com/subject/oewktjtx.html