LLM 流程#

本节介绍如何在 Colang 2.0 中创建 LLM 驱动的流程。

使用 Colang,你可以描述复杂的交互模式。但是,作为开发者,你永远无法描述交互可能发生的所有潜在路径。而这正是 LLM 可以提供帮助的地方,它可以在运行时生成 LLM 驱动的延续。

“对话轨道”和“输入轨道”示例展示了如何使用 LLM 动态生成延续。下面的示例与对话轨道示例类似,但它指示 LLM 直接生成 Bot 响应。请注意,响应的质量取决于配置的 LLM 模型,并且可能会有所不同。

examples/v2_x/tutorial/llm_flows/main.co#
 1import core
 2import llm
 3
 4flow main
 5  """You are an assistant that should talk to the user about cars.
 6  Politely decline to talk about anything else.
 7
 8  Last user question is: "{{ question }}"
 9  Generate the output in the following format:
10
11  bot say "<<the response>>"
12  """
13  $question = await user said something
14  ...

上面的 main 流程等待 user said something 来匹配用户话语,将结果存储在 $question 局部变量中,然后通过 ...(生成运算符)调用 LLM,以生成流程的延续。

注意

上下文变量可以使用双花括号(Jinja2 语法)包含在流程的 NLD(自然语言描述)中(也称为 Python 中的文档字符串)。

测试#

$ nemoguardrails chat --config=examples/v2_x/other/llm_flow

> hi

Hello! How can I assist you with cars today?

> what can yo udo?

I am an assistant that can talk to you about cars. Is there anything specific you would like to know?

本节结束 Colang 2.0 入门指南。查看“推荐的后续步骤”以了解继续学习 Colang 2.0 的推荐方法。