公司让做网站违法,浏览器网站在线进入,住房和城乡建设部网站首页,软件开发外包公司企云云文章目录 大语言模型LangChain ChatGLM3-6B的组合集成#xff1a;工具调用提示词解读官方给出的提示词模板解读注解#xff1a;1. 模板描述2. 工具调用规范3. 问题处理流程4. 最终响应5. 历史记录6. 实际应用举例 大语言模型LangChain ChatGLM3-6B的组合集成#xff1a;工… 文章目录 大语言模型LangChain ChatGLM3-6B的组合集成工具调用提示词解读官方给出的提示词模板解读注解1. 模板描述2. 工具调用规范3. 问题处理流程4. 最终响应5. 历史记录6. 实际应用举例 大语言模型LangChain ChatGLM3-6B的组合集成工具调用提示词解读
官方给出的提示词模板
PROMPT_TEMPLATES[“agent_chat”] { “ChatGLM3”: “” You can answer using the tools, or answer directly using your knowledge without using the tools.Respond to the human as helpfully and accurately as possible. You have access to the following tools: {tools} Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input). Valid “action” values: “Final Answer” or [{tool_names}] Provide only ONE action per $JSON_BLOB, as shown:
{{{{action: $TOOL_NAME,action_input: $INPUT
}}}}Follow this format:
Question: input question to answer Thought: consider previous and subsequent steps Action:
$JSON_BLOBObservation: action result … (repeat Thought/Action/Observation N times) Thought: I know what to respond Action: {{{{action: Final Answer,action_input: Final response to human
}}}}
Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:$JSON_BLOBthen Observation:.history: {history}Question: {input}Thought: {agent_scratchpad}“”, }
解读
这段代码片段定义了一个名为PROMPT_TEMPLATES[agent_chat]的大语言模型如ChatGLM3的提示词模板用于指导模型在与人类交互时如何使用工具以及基于自身知识进行回答。该模板用于确保模型遵循预设的格式和逻辑流程来处理问题并在需要时调用指定的外部工具。
注解
1. 模板描述
模型被告知可以利用工具来获取信息并整合到答案中也可以直接利用自身的知识库提供答案。提供了访问一系列工具的权限这些工具的具体名称由变量 {tools} 代替在实际使用时会填充具体的工具列表。
2. 工具调用规范 要调用工具模型需要生成一个JSON blob对象其中包含两个键值对 action: 工具名称可选值为Final Answer或预先定义好的具体工具名。action_input: 传递给工具的输入参数。 JSON blob结构示例 {{{action: $TOOL_NAME,action_input: $INPUT
}}} 3. 问题处理流程
对于每个问题模型应该按照以下步骤执行 Question: 显示待解答的问题文本。Thought: 模型记录其思考过程和之前的推理步骤。Action: 发布一个包含工具调用指令或最终回答的JSON blob。Observation: 如果执行了工具调用则显示工具返回的结果。这个流程可以重复多次直至模型得出最终答案。
4. 最终响应
当模型准备好给出最终答案时它将输出一个JSON blob其中动作类型是Final Answer并将最终回复作为action_input的值。
5. 历史记录
history: {history} 表示对话的历史上下文将在实际应用中填充已发生的对话内容以帮助模型理解当前情境。
6. 实际应用举例
在实际运行时{input}、{agent_scratchpad} 和 {history} 都会被替换为真实值。Question: {input} 会插入当前用户提出的问题。Thought: {agent_scratchpad} 会显示模型内部关于当前问题的思考过程或临时结论。
通过这种结构化的提示方式ChatGLM3模型能够根据问题内容选择是否及如何调用外部工具并最终组织出合适且准确的回答。