question = """ What is the population of the capital of the country where the Olympic Games were held in 2016? """
llm_chain.run(question)
复制代码
输出如下:
Step 1: Identify the country where the Olympic Games were held in 2016.
Answer: The 2016 Olympic Games were held in Brazil.
Step 2: Identify the capital of Brazil.
Answer: The capital of Brazil is Brasília.
Step 3: Find the population of Brasília.
Answer: As of 2021, the estimated population of Brasília is around 3.1 million. So, the population of the capital of the country where the Olympic Games were held in 2016 is around 3.1 million. Note that this is an estimate and may vary slightly.'
复制代码
PromptTemplate 负责构建模型的输入,能以可复制的方式天生提示词。它包含一个名为 template 的输入文本字符串,其中的值可以通过 input_variables 举行指定。
提示词和模型由 LLMChain 函数组合在一起,形成包含这两个元素的一条链。末了需要调用 run 函数来请求补全输入问题。当运行 run 函数时,LLMChain 使用提供的输入键值格式化提示词模板,随后将颠末格式化的字符串传递给 LLM,并返回 LLM 输出。模型运用“逐步思考”的技巧自动答复问题,对于复杂的应用程序来说,动态提示词是简单而又颇具代价的功能。
5.1.2 智能体及工具
The capital of the country where the Olympic Games were held in 2016 is Rio de Janeiro, Brazil. The population of Rio de Janeiro is approximately 6.32 million people as of 2021. Taking the square root of this population, we get approximately 2,513.29. Therefore, the square root of the population of the capital of the country where the Olympic Games were held in 2016 is approximately 2,513.29.
当你开始与 GPT-4 举行交互时,OpenAI 会向 GPT-4 发送一条隐藏消息,以检查你的插件是否已安装。这条消息会扼要先容你的插件,包括其形貌信息、端点和示例。
模型就成了智能的 API 调用者。当用户询问关于插件的问题时,模型可以调用你的插件 API。是否调用插件是基于 OpenAPI 规范和关于应该使用 API 的环境的天然语言形貌所做出的决策。一旦模型决定调用你的插件,它就会将 API 的结果归并到上下文中,以向用户提供相应。因此,插件的 API 相应必须返回原始数据而不是天然语言相应。这使得GPT-4 可以根据返回的数据天生本身的天然语言相应。
如果用户问模型“我在北京可以住那里”,那么模型可以使用酒店预订插件,然后将插件的 API 相应与其文本天生本领联合起来,提供既含有丰富信息又对用户友爱的答复。
5.2.2 API
description: A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user s username, ask them first before making queries to the plugin. Otherwise, use the username "global".
version: 'v1'
servers:
- url: http://localhost:5003
paths:
/todos/{username}:
get:
operationId: getTodos
summary: Get the list of todos
parameters:
- in: path
name: username
schema:
type: string
required: true
description: The name of the user.
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/getTodosResponse'
[...]
复制代码
可以将 OpenAPI 规范视为形貌性文档,它足以明确和使用 API。在 GPT-4中举行搜索时,使用 info 部分中的形貌来确定插件与搜索内容的干系性。OpenAPI 规范的其余内容遵循尺度的 OpenAPI 格式。很多工具可以根据现有的 API 代码自动天生 OpenAPI 规范。
5.2.5 形貌
当插件有助于相应用户请求时,模型会扫描 OpenAPI 规范中的端点形貌及插件清单文件中的description_for_model 字段。目标是创建最符合的相应,这通常涉及测试不同的请求和形貌。OpenAPI 文档应该提供关于 API 的各种细节,比如可用的函数及其参数。它还应包含特定于属性的形貌字段,提供有代价的表明,说明每个函数的作用及查询字段期望的信息类型。**关键要素是 description_for_model 字段,强烈建议为该字段创建简明、清晰和形貌性强的说明。**在撰写形貌时,必须遵循以下最佳实践: