ChatGPT 最佳实践指南之:使用外部工具

Use external tools

使用外部工具

Compensate for the weaknesses of GPTs by feeding them the outputs of other tools. For example, a text retrieval system can tell GPTs about relevant documents. A code execution engine can help GPTs do math and run code. If a task can be done more reliably or efficiently by a tool rather than by a GPT, offload it to get the best of both.

通过向 GPT 提供其他工具的输出来弥补 GPT 的弱点。例如,文本检索系统可以告诉 GPT 相关文档的信息,代码执行引擎可以帮助 GPT 进行数学计算和运行代码。如果一个任务可以通过工具而不是GPT更可靠或更高效地完成,那么可以将其转移,以充分发挥两者的优势。

Tactic: Use embeddings-based search to implement efficient knowledge retrieval

技巧:使用基于嵌入的搜索实现高效的知识检索

A model can leverage external sources of information if provided as part of its input. This can help the model to generate more informed and up-to-date responses. For example, if a user asks a question about a specific movie, it may be useful to add high quality information about the movie (e.g. actors, director, etc…) to the model’s input. Embeddings can be used to implement efficient knowledge retrieval, so that relevant information can be added to the model input dynamically at run-time.

如果模型的输入中包含外部信息,模型可以利用外部信息源,这可以帮助模型生成更具见解和最新的回答。例如,如果用户询问有关特定电影的问题,将关于电影的高质量信息(例如演员、导演等)添加到模型的输入中可能会很有用。可以使用嵌入来实现高效的知识检索,以便在运行时动态地将相关信息添加到模型输入中。

A text embedding is a vector that can measure the relatedness between text strings. Similar or relevant strings will be closer together than unrelated strings. This fact, along with the existence of fast vector search algorithms means that embeddings can be used to implement efficient knowledge retrieval. In particular, a text corpus can be split up into chunks, and each chunk can be embedded and stored. Then a given query can be embedded and vector search can be performed to find the embedded chunks of text from the corpus that are most related to the query (i.e. closest together in the embedding space).

文本嵌入是一种可以衡量文本字符串相关性的向量,相似或相关的字符串比不相关的字符串更接近。这个事实以及快速向量搜索算法的存在意味着嵌入可以用来实现高效的知识检索。特别是,可以将文本语料库分成多个块,对每个块进行嵌入和存储。然后可以对给定的查询进行嵌入,并进行向量搜索,以找到与查询最相关的文本块(即,在嵌入空间中最接近的文本块)。

Example implementations can be found in the OpenAI Cookbook. See the tactic “Instruct the model to use retrieved knowledge to answer queries” for an example of how to use knowledge retrieval to minimize the likelihood that a model will make up incorrect facts.

在 OpenAI Cookbook 中可以找到示例实现。有关如何使用知识检索来减少模型编造错误事实的示例,请参阅技巧文章“指导模型使用检索到的知识来回答查询”。

Tactic: Use code execution to perform more accurate calculations or call external APIs

技巧:使用代码执行进行更准确的计算或调用外部API

GPTs cannot be relied upon to perform arithmetic or long calculations accurately on their own. In cases where this is needed, a model can be instructed to write and run code instead of making its own calculations. In particular, a model can be instructed to put code that is meant to be run into a designated format such as triple backtics. After an output is produced, the code can be extracted and run. Finally, if necessary, the output from the code execution engine (i.e. Python interpreter) can be provided as an input to the model for the next query.

GPT 模型本身无法可靠地进行算术或长时间的计算。在需要这样做的情况下,可以指示模型编写并运行代码,而不是进行自己的计算。特别是,可以指示模型将需要运行的代码放入指定的格式中,例如三个反引号。生成输出后,可以提取和运行代码。最后,如果需要,可以将代码执行引擎(比如 Python 解释器)的输出作为下一个查询的模型输入。

SYSTEM

系统

You can write and execute Python code by enclosing it in triple backticks, e.g. ```code goes here```. Use this to perform calculations.

您可以通过将其放在三个反引号中来编写和执行Python代码,例如code goes here。使用它来执行计算。

USER

用户

Find all real-valued roots of the following polynomial: 3*x**5 - 5*x**4 - 3*x**3 - 7*x - 10.

找出以下多项式的所有实根:3x**5 - 5x4 - 3*x3 - 7*x - 10。

Another good use case for code execution is calling external APIs. If a model is instructed in the proper use of an API, it can write code that makes use of it. A model can be instructed in how to use an API by providing it with documentation and/or code samples showing how to use the API.

另一个使用代码执行的好用例是调用外部 API。如果正确指导模型使用 API,它可以编写使用 API 的代码。可以通过为模型提供文档和代码示例来指导模型如何使用 API。

SYSTEM

系统

You can write and execute Python code by enclosing it in triple backticks. Also note that you have access to the following module to help users send messages to their friends:

您可以通过将其放在三个反引号中来编写和执行Python代码。还要注意,您可以使用以下模块来帮助用户向他们的朋友发送消息:

```python

import message

message.write(to="John", message="Hey, want to meetup after work?")```

WARNING: Executing code produced by a model is not inherently safe and precautions should be taken in any application that seeks to do this. In particular, a sandboxed code execution environment is needed to limit the harm that untrusted code could cause.

警告:执行模型生成的代码本质上是不安全的,因此在试图执行此操作的任何应用程序中应采取预防措施。特别是,需要使用沙盒式代码执行环境来限制不受信任的代码可能造成的伤害。

Tactic: Give the model access to specific functions

技巧:为模型提供特定函数的访问权限

The Chat Completions API allows passing a list of function descriptions in requests. This enables models to generate function arguments according to the provided schemas. Generated function arguments are returned by the API in JSON format and can be used to execute function calls. Output provided by function calls can then be fed back into a model in the following request to close the loop. This is the recommended way of using GPT models to call external functions. To learn more see the function calling section in our introductory GPT guide and more function calling examples in the OpenAI Cookbook.

Chat Completions API 允许在请求中传递函数描述列表,这使得模型可以根据提供的模式生成函数参数。API 以 JSON 格式返回生成的函数参数,并可用于执行函数调用。然后,函数调用提供的输出可以作为下一个请求的模型输入,以完成循环。这是使用 GPT 模型调用外部函数的推荐方法。要了解更多信息,请参阅我们的入门指南中的函数调用部分以及 OpenAI Cookbook 中的更多函数调用示例。

a607490a808071c7b48433964b2f8aea.jpeg

“点赞有美意,赞赏是鼓励”

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/23426.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

graylog源码搭建

这里主要讲如何源码安装graylog 下载地址: https://www.graylog.org/downloads/ 下载带有JVM的源码文件源码安装 下载graylog-5.1.3-linux-x64.tgz,并上传到Centos中,执行以下操作 tar -zxvf graylog-5.1.3-linux-x64.tgzcd /etcmkdir -p …

ARPACK特征值求解分析

线性方程组求解、特征值求解是(数值)线性代数的主要研究内容。力学、电磁等许多问题,最终都可以归结为特征值、特征向量的求解。 ARPACK使用IRAM(Implicit Restarted Arnoldi Method)求解大规模系数矩阵的部分特征值与特征向量。了解或者熟悉IRAM算法,必…

Spring Boot中如何解决Redis的缓存穿透、缓存击穿、缓存雪崩?

Redis的缓存穿透、缓存击穿、缓存雪崩 一、概述 ① 缓存穿透:大量请求根本不存在的key ② 缓存雪崩:Redis中大量key集体过期 ③ 缓存击穿:Redis中一个热点key过期 三者出现的根本原因:Redis命中率下降,请求直接打…

机器学习 day27(反向传播)

导数 函数在某点的导数为该点处的斜率,用height / width表示,可以看作若当w增加ε,J(w,b)增加k倍的ε,则k为该点的导数 反向传播 tensorflow中的计算图,由有向边和节点组成。从左向右为正向传播,神经网…

常用的缓存工具有ehcache、memcache和redis,这里介绍spring中ehcache的配置。

常用的缓存工具有ehcache、memcache和redis&#xff0c;这里介绍spring中ehcache的配置。 1.在pom添加依赖&#xff1a; <!-- ehcache 相关依赖 --><dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache</artifactId><ve…

ylb-接口13实名认证

总览&#xff1a; 在api模块下的service包&#xff0c;创建一个充值接口RechargeService&#xff0c;并创建一个&#xff08;根据userID查询它的充值记录&#xff09;方法&#xff1a; package com.bjpowernode.api.service;import com.bjpowernode.api.model.RechargeRecord…

【漂移-扩散通量重建 FV 方案】用于半导体和气体放电模拟的电子传输的更准确的 Sharfetter-Gummel 算法(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

ELK中grok插件、mutate插件、multiline插件、date插件的相关配置

目录 grok 正则捕获插件 自定义表达式调用 mutate 数据修改插件 示例&#xff1a; ●将字段old_field重命名为new_field ●添加字段 ●将字段删除 ●将filedName1字段数据类型转换成string类型&#xff0c;filedName2字段数据类型转换成float类型 ●将filedName字段中…

大华相机接入web页面实现人脸识别

先看下效果&#xff0c;中间主视频流就是大华相机&#xff08;视频编码H.264&#xff09;&#xff0c;海康相机&#xff08;视屏编码H.265&#xff09; 前端接入视屏流代码 <!--视频流--><div id"col2"><div class"cell" style"flex: …

SpringCloud——分布式请求链路跟踪Sleuth

安装运行zipkin SpringCloud从F版已不需要自己构建Zipkin Server&#xff0c;只需要调用jar包即可 https://dl.bintray.com/oenzipkin/maven/io/zipkin/java/zipkin-server/ 下载&#xff1a;zipkin-server-2.12.9-exec.jar 运行&#xff1a;java -jar zipkin-server-2.12.9-e…

Word 插件实现读取excel自动填写

日常工作中碰到需要将EXCEL的对应数据记录填写到word文档对应的位置&#xff0c;人工操作的方式是&#xff1a; 打开exel表—>查找对应报告号的行—>逐列复制excel表列单元格内容到WORD对应的位置&#xff08;如下图标注所示&#xff09; 这种方法耗时且容易出错。实际上…

三菱PLC上位机测试

利用三菱的MX Component与三菱PLC进行以太网通信&#xff0c;我们可以用官方的dll编写C#代码&#xff0c;特别简单&#xff0c;最后附上整个源码下载。 1. 安装MX Component&#xff08;必须&#xff09;和GX WORKS3&#xff08;主要是仿真用&#xff0c;实际可以不装&#xf…