LLM Flows

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

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

对话 Rails输入 Rails 示例展示了如何使用 LLM 动态生成延续。下面的示例与对话 rails 示例类似,但它指示 LLM 直接生成 bot 响应

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 的推荐方法。