- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 gpt-4-0613
模型,具有单个函数,并在系统提示符中包含一些自定义数据。
如果该函数在聊天中很早就被触发,在前两个请求内,它的功能就很好,并且 API 会要求用户提供调用该函数所需的信息。
但是,如果稍后在对话中调用该函数,例如问题 5,则 API 将仅给出答案并发回函数调用。
如何阻止人工智能编造答案? API 无法从对话上下文中获取这些值。它们都是 100% 化妆的。
completion = openai.ChatCompletion.create(
model='gpt-4-0613',
messages=prompts,
functions=[
{
"name": "fill_form",
"description": "Helps the user create an XYZ Report",
"parameters": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "the full name of the person issuing this report"
},
"zip": {
"type": "string",
"description": "the 5 digit zip code of the address"
},
"address": {
"type": "string",
"description": "the street address, only the street and not the city, state or zip"
},
"year_end": {
"type": "string",
"description": "the full four digit year of the fiscal year"
},
},
"required": ["name", "address", "year_end", "zip"]
}
}],
)
我尝试过使用和不使用
function_call='auto'
没有影响的选项。
感谢您的帮助。
API 应始终询问用户函数的值,而不是虚构它们。
最佳答案
OpenAI 承认模型可能会幻觉(即弥补)函数参数,如官方 OpenAI documentation 中所述。 :
The basic sequence of steps for function calling is as follows:
- Call the model with the user query and a set of functions defined in the functions parameter.
- The model can choose to call a function; if so, the content will be a stringified JSON object adhering to your custom schema (note: themodel may generate invalid JSON or hallucinate parameters).
- Parse the string into JSON in your code, and call your function with the provided arguments if they exist.
- Call the model again by appending the function response as a new message, and let the model summarize the results back to the user.
这可以通过系统消息来缓解,如官方 OpenAI documentation 中所述。 :
Hallucinated outputs in function calls can often be mitigated with asystem message. For example, if you find that a model is generatingfunction calls with functions that weren't provided to it, try using asystem message that says: "Only use the functions you have beenprovided with."
通常,对话首先使用系统消息进行格式化,然后是交替的用户和助理消息,如官方 OpenAI documentation 中所述。 。您可以添加系统消息,如下所示:
Python
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
chatCompletion = openai.ChatCompletion.create(
model = "gpt-3.5-turbo-0613",
messages = [
{"role": "system", "content": "Only use the functions you have been provided with."}
]
)
print(chatCompletion.choices[0].message.content)
NodeJS
注意:OpenAI NodeJS SDK v4
是released于2023年8月16日发布,并且是对SDK的完全重写。下面的代码根据您当前拥有的版本而有所不同。请参阅v3
至v4
migration guide .
• 如果您有 OpenAI NodeJS SDK v3
:
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const chatCompletion = await openai.createChatCompletion({
model: "gpt-3.5-turbo-0613",
messages: [{"role": "system", "content": "Only use the functions you have been provided with."}],
});
console.log(chatCompletion.data.choices[0].message.content);
• 如果您有 OpenAI NodeJS SDK v4
:
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const chatCompletion = await openai.chat.completions.create({
model: "gpt-3.5-turbo-0613",
messages: [{"role": "user", "content": "Only use the functions you have been provided with."}],
});
console.log(chatCompletion.choices[0].message.content);
此外,尝试通过设置 function_call: {"name": "<insert-function-name>"}
强制模型调用特定函数。正如官方所说OpenAI documentation :
就您而言,它看起来像这样:
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
completion = openai.ChatCompletion.create(
model = "gpt-3.5-turbo-0613",
messages = messages,
functions = functions,
function_call = "fill_form", # Add this
)
print(completion.choices[0].message.content)
关于openai-api - OpenAI GPT-4 API : Why does gpt-4-0613 hallucinate (make up) function parameters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76608259/
我已经为此奋斗了几个小时。显然,我不是专家,但我已经做到了这一点 - api 设置,在前端运行,当我输入聊天提示时,它会出现错误,并且gunicorn 返回大长错误。 这是我的 ai_chat.py
我已经为此奋斗了几个小时。显然,我不是专家,但我已经做到了这一点 - api 设置,在前端运行,当我输入聊天提示时,它会出现错误,并且gunicorn 返回大长错误。 这是我的 ai_chat.py
尝试调用刚刚为 ChatGPT 发布的 got-3.5-turbo API,但收到错误请求错误? var body = new {
尝试调用刚刚为 ChatGPT 发布的 got-3.5-turbo API,但收到错误请求错误? var body = new {
最近我必须找到一种方法来区分虚拟机使用的分区类型,从虚拟磁盘读取原始数据我能够通过检查偏移量 1C2(GPT 的 EE)找到它,以防万一MBR 磁盘如果磁盘是动态的,1C2 的偏移量有 42,如果是基
我有一个 Android 应用程序,目前正在使用 chat gpt 3.0 进行补全,并且工作正常。现在,在他们发布 chat gpt 3.5 Turbo 后,我根据他们的请求示例做了一些更改,但抛出
我有一个 Android 应用程序,目前正在使用 chat gpt 3.0 进行补全,并且工作正常。现在,在他们发布 chat gpt 3.5 Turbo 后,我根据他们的请求示例做了一些更改,但抛出
创建微调模型后,如何在/v1/chat/completions 中使用它?我们尝试了这个,但出现了错误 curl --location 'https://api.openai.com/v1/chat/
我收到以下错误: [3067] NetworkUtility.shouldRetryException: Unexpected response code400 for https://api.ope
我收到以下错误: [3067] NetworkUtility.shouldRetryException: Unexpected response code400 for https://api.ope
创建微调模型后,如何在/v1/chat/completions 中使用它?我们尝试了这个,但出现了错误 curl --location 'https://api.openai.com/v1/chat/
我正在围绕 GPT-3 构建一个应用程序,我想知道我发出的每个请求使用了多少 token 。这可能吗?如何实现? 最佳答案 OPEN-AI 通过代币对 GPT-3 的使用进行收费,这包括提示和答案。对
kapt 和有什么区别和 implementation在 Gradle 中声明依赖项时以及何时应该在另一个上使用一个? 例子: //Room Components implementation "an
所以我在我的 React 应用程序中实现了 chat gpt 3.5 Turbo API。所以我的应用程序基本上就像招聘人员的助手。因此,招聘人员向应用程序提供了一个示例职位帖子,并将该帖子发送到聊天
所以我在我的 React 应用程序中实现了 chat gpt 3.5 Turbo API。所以我的应用程序基本上就像招聘人员的助手。因此,招聘人员向应用程序提供了一个示例职位帖子,并将该帖子发送到聊天
我有最新版本的 OpenAi,但缺少某些属性。我试过重新安装它,没有解决它。 GPT 和 Chat 是我发现还不能用的。 切记,我是 python 的新手并且具有该语言的基本知识。代码取自GitHub
我有最新版本的 OpenAi,但缺少某些属性。我试过重新安装它,没有解决它。 GPT 和 Chat 是我发现还不能用的。 切记,我是 python 的新手并且具有该语言的基本知识。代码取自GitHub
我使用的是 gpt-4-0613 模型,具有单个函数,并在系统提示符中包含一些自定义数据。 如果该函数在聊天中很早就被触发,在前两个请求内,它的功能就很好,并且 API 会要求用户提供调用该函数所需的
我使用的是 gpt-4-0613 模型,具有单个函数,并在系统提示符中包含一些自定义数据。 如果该函数在聊天中很早就被触发,在前两个请求内,它的功能就很好,并且 API 会要求用户提供调用该函数所需的
OpenAI 现在允许我们微调 GPT-3.5 模型。我已经使用自己的数据集测试和微调了模型,但问题是微调模型随机生成答案,而不是根据我的自定义数据集正确生成答案。 有什么方法可以让模型仅根据我自己的
我是一名优秀的程序员,十分优秀!