跳至内容

响应预置

可以在脚本中提供LLM响应的开头部分(assistant消息)。 这允许将LLM的答案引导至特定的语法或格式。

使用assistant函数来提供助手文本。

$`List 5 colors. Answer with a JSON array. Do not emit the enclosing markdown.`
// help the LLM by starting the JSON array syntax
// in the assistant response
assistant(`[`)
👤 user
List 5 colors. Answer with a JSON array. Do not emit the enclosing markdown.
🤖 assistant
[
🤖 assistant
"red",
"blue",
"green",
"yellow",
"purple"
]

它是如何工作的?

在内部调用LLM时,会向查询添加一条额外消息,就好像LLM生成了这个内容一样。

{
"messages": [
...,
{
"role": "assistant",
"content": "[\n"
}
]
}