- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
import openai from "@/openai";
import { NextResponse } from "next/server";
export async function POST(request: Request){
const {todos} = await request.json();
//communicate with openai api
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
temperature: 0.8,
n: 1,
stream: false,
messages: [
{
role: "system",
content: `When responding, welcome the user always as Hello User and say Welcome to the Todo List App!
Limit text to 200 characters.`
},
{
role: "user",
content: `Hi there, provide a summary of the following todos. Count how many todos are in each category such as To do, in progress and done,
then tell the user to have a productive day! Here's the data: ${JSON.stringify(
todos
)}`
}
]
});
const {data} = response;
}
最后一行显示错误“ChatCompletion”类型上不存在属性“data”
我想解构该对象以从收到的响应对象中获取数据。
最佳答案
您正在使用 OpenAI NodeJS SDK v4
。
按如下方式提取消息:
console.log(response.choices[0].message);
提取消息内容如下:
console.log(response.choices[0].message.content);
关于openai-api - OpenAI API错误: "Property ' data' does not exist on type 'ChatCompletion' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77025306/
我正在尝试使用 chatgpt api 运行一些命令,但它并没有运行所有内容,因此我创建了另一个 ChatCompletion 实例。如何让 chatgpt 记住我在先前实例中发送的提示?这是我的代码
当我运行使用 openai.ChatCompletion 的代码时: import openai openai.api_key = "removed for obvious reasons" comp
当我运行使用 openai.ChatCompletion 的代码时: import openai openai.api_key = "removed for obvious reasons" comp
我正在尝试使用 chatgpt api 运行一些命令,但它并没有运行所有内容,因此我创建了另一个 ChatCompletion 实例。如何让 chatgpt 记住我在先前实例中发送的提示?这是我的代码
对于下面的nodejs代码,我在响应中得到prompt_tokens = 24。我希望能够在发出请求之前确定预期的提示 token 应该是什么。 import { Configuration,
对于下面的nodejs代码,我在响应中得到prompt_tokens = 24。我希望能够在发出请求之前确定预期的提示 token 应该是什么。 import { Configuration,
我正在探索 gpt3.5-turbo 上不同提示的用法。 调查“ChatCompletion”和“Completion”之间的差异,一些引用文献说它们应该或多或少相同,例如:https://platf
我正在探索 gpt3.5-turbo 上不同提示的用法。 调查“ChatCompletion”和“Completion”之间的差异,一些引用文献说它们应该或多或少相同,例如:https://platf
import openai from "@/openai"; import { NextResponse } from "next/server"; export async function POS
import openai from "@/openai"; import { NextResponse } from "next/server"; export async function POS
我一直在尝试创建一个带有 Gradio 界面的 GPT-3.5-turbo 聊天机器人,该聊天机器人在命令行中工作得很好,但当我用 Gradio 实现它时却不行。我能够发送我的输入并接收响应。然而,响
我一直在尝试创建一个带有 Gradio 界面的 GPT-3.5-turbo 聊天机器人,该聊天机器人在命令行中工作得很好,但当我用 Gradio 实现它时却不行。我能够发送我的输入并接收响应。然而,响
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我是一名优秀的程序员,十分优秀!