next.js - OpenAI GPT-3 API 错误 : 'text' does not exist TS(2339) & 'prompt' does not exist on type 'CreateChatCompletion' TS(2345)

标签 next.js openai-api gpt-3

import openai from "./zggpt";

const query = async (prompt:string,  chatId:string, model:string) => {
    const res= await openai
    .createChatCompletion({
        model,
        prompt,
        temperature: 0.9,
        
        top_p:1,
       
        max_tokens:1000,
        frequency_penalty:0,
        presence_penalty:0,
    })
    .then((res) => res.data.choices[0].text)
    .catch((err)=>
    `ZG was unable to find an answer for that!
     (Error: ${err.message})`
     );
     return res;
};

export default query;

类型“CreateChatCompletionResponseChoicesInner”上不存在属性“text”.ts(2339)

'{ model: string; 类型的参数提示:字符串;温度:数字; top_p:数字; max_tokens:数量; frequency_penalty:数字; presence_penalty:数字; }' 不可分配给类型为“CreateChatCompletionRequest”的参数。 对象字面量只能指定已知属性,并且类型“CreateChatCompletionRequest”中不存在“提示”。ts(2345)

即使我按照视频中的方式执行所有操作,我也会遇到这些错误。

我是编码初学者,所以我正在尝试制作基于视频的应用程序来学习。

谢谢

应用程序响应而不返回错误。 enter image description here

https://www.youtube.com/watch?v=V6Hq_EX2LLM&t=6293s

最佳答案

问题

您观看了使用 GPT-3 Completions endpoint 的教程(您需要提供提示和参数才能完成)。在这种情况下,这是生成完成的函数:

openai.createCompletion()

然而,您使用了教程中的代码,但使用了 ChatGPT Completions endpoint (您需要提供聊天消息才能完成)。在这种情况下,这是生成完成的函数:

openai.createChatCompletion()

解决方案

所以,改变这个...

openai.createChatCompletion()

...为此。

openai.createCompletion()

这两个错误都会消失。

我的建议

但是,您想要使用 GPT-3 模型实现类似聊天的机器人。在录制教程时,这是唯一的方法。自 2023 年 3 月 1 日起,gpt-3.5-turbo 模型可用。我强烈建议你使用它。查看documentation .

关于next.js - OpenAI GPT-3 API 错误 : 'text' does not exist TS(2339) & 'prompt' does not exist on type 'CreateChatCompletion' TS(2345),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75624308/

相关文章:

reactjs - 如何使用 PNPM 创建特定版本的下一个或 react 项目?

typescript - Next.js - 导入 TypeScript 模块时找不到模块

javascript - 一种使 GPT-3's "davinci“使用 discord.js 通过不和谐的机器人与用户交谈的方法?

node.js - OpenAI GPT-3 API 错误 : "TypeError: Converting circular structure to JSON" using ExpressJS

python - 属性错误: module transformers has no attribute TFGPTNeoForCausalLM

javascript - 使用草稿js的Nextjs-当我使用convertFromHTML方法使用HTML内容初始化编辑器时未定义文档

openai-api - gpt-3.5-turbo 中的提示标记添加了 7 个标记

python - 寻找 OpenAi 的 Codex,如开源沙盒 Playground

jupyter-lab - 什么是 OpenAI API 警告 : To avoid an invalid_request_error, best_of 设置为等于 n。什么是 "best of"?

javascript - 除非我专门刷新页面,否则脚本无法在 React、NextJS 项目中工作