OpenAI converting API code from GPT-3 to chatGPT-3.5

题意:将OpenAI API代码从GPT-3转换为ChatGPT-3.5

问题背景:

Below is my working code for the GPT-3 API. I am having trouble converting it to work with chatGPT-3.5.

以下是我用于GPT-3 API的工作代码。我在将其转换为适用于ChatGPT-3.5时遇到了困难

<?php include('../config/config.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Chatbot</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="container py-5"><h1 class="mb-5 text-center"><div class="logo"> <img src="/images/Logo-PocketAI.svg" height="80" width="210" aria-label="PocketAI.Online Logo" title="PocketAI.Online Logo" alt="SPocketAI.Online Logo" class="img-fluid"> </div></h1><div class="form-floating mb-3"><select class="form-select" id="tab-select" aria-label="Select your purpose"><option value="exam" selected>Exam</option><option value="feedback">Feedback</option></select><label for="tab-select">Select your purpose:</label></div><div class="input-group mb-3"><div class="form-floating"><textarea class="form-control" placeholder="Enter your question or comment here" id="prompt"></textarea><label for="prompt">Enter your question or comment here</label></div><div class="input-group-append username w-100 mt-3 mb-4"><button class="btn btn-outline-primary w-100" type="button" id="send-button">Send</button></div></div><div id="output" class="mb-3" style="height: 300px; overflow: auto; border: 1px solid lightgray; padding: 10px;"></div><div id="exam-instructions" class="mb-3" style="display: block;"><h3>Exam</h3><p>PocketAI can create multiple choice and true false questions in a format that enables import into Brightspace D2L quizzes using Respondus. Place PocketAI output into a Word document before importing with Respondus. Ask PocketAI questions like the following: <br><br>Create 3 multiple choice questions about carbohydrates for a freshman Nutrition online college course.<br>Create 2 true false questions about business for a sophomore Business face to face college course.</p></div><div id="feedback-instructions" class="mb-3" style="display: none;"><h3>Feedback</h3><p>Enter text to receive writing feedback.</p></div>
</div>
<script>
const previousPrompts = [];
const userName = "<strong>User</strong>";
const chatbotName = "<strong>PocketAI</strong>";const selectDropdown = document.getElementById("tab-select");selectDropdown.addEventListener("change", function() {const activeTabId = this.value;// hide all instruction sectionsdocument.querySelectorAll("[id$='-instructions']").forEach(function(instructionSection) {instructionSection.style.display = "none";});// show the instruction section for the active tabdocument.getElementById(`${activeTabId}-instructions`).style.display = "block";
});document.getElementById("send-button").addEventListener("click", function() {const prompt = document.getElementById("prompt").value;const activeTabId = selectDropdown.value;const endpoint = "https://api.openai.com/v1/completions";const apiKey = "<?=$OPEN_AI_KEY;?>";document.getElementById("send-button").innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Sending...';let promptText = "";switch (activeTabId) {case "exam":promptText = "Create quiz questions in the following format: Begin each question with a number followed by a period, and then include the question wording. For each question, include four answer choices listed as letters (A, B, C, D) followed by a period and at least one space before the answer wording. Designate the correct answer by placing an asterisk (*) directly in front of the answer letter (do not put a space between the asterisk and the answer choice). Place the asterisk in front of the answer letter, only the front. It is important that correct answers are identified. Don't make up answers, only select factual answers. For example formatting (don't use this specific example), \"1. What is the recommended daily intake of dietary fiber? A. 10 grams B. 25 grams *C. 50 grams D. 75 grams\". Format true false questions the same way. If you are unsure of the correct answer, don't create the question. Every quiz question and answer must be 100% correct and factual. Do not make up answers. All answers must be correct.";break;case "feedback":promptText = "Can you provide feedback on the writing, grammar, sentence structure, punctuation, and style of this student's paper? The paper should be analyzed for its strengths and weaknesses in terms of written communication. Please provide suggestions for improvement and examples to help the student understand how to make the writing better. The feedback should be specific and provide actionable steps that the student can take to improve their writing skills. Please include at least three examples of areas that could be improved and specific suggestions for how to improve them, such as correcting grammar errors, restructuring sentences, or improving the use of punctuation.";break;}const requestData = {prompt: previousPrompts.join("\n") + promptText + "\n" + prompt,max_tokens: 400,model: "text-davinci-003",n: 1,stop: "",temperature: 0.5,top_p: 0.0,frequency_penalty: 0.0,presence_penalty: 0};const requestOptions = {method: "POST",headers: {"Content-Type": "application/json","Authorization": `Bearer ${apiKey}`,},body: JSON.stringify(requestData),};fetch(endpoint, requestOptions).then(response => response.json()).then(data => {const reply = data.choices[0].text;// Add the user message to the chat historyconst userMessage = `<div class="message-container"><div class="username">${userName}:&nbsp;</div><div class="user-message">${prompt}</div></div>`;document.getElementById("output").innerHTML += userMessage;const chatbotMessage = `<div class="message-container"><div class="username">${chatbotName}:&nbsp;</div><div class="chatbot-message" style="white-space: pre-wrap">${reply}<i class="bi bi-clipboard-check copy-button" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Copy to clipboard" data-text="${reply}" style="cursor: pointer;"></i></div>
</div>`; 
document.getElementById("output").innerHTML += chatbotMessage;// Add an event listener to each "Copy to Clipboard" button
document.addEventListener("click", function(event) {if (event.target.classList.contains("copy-button")) {const textToCopy = event.target.dataset.text;navigator.clipboard.writeText(textToCopy);}
});// Scroll to the bottom of the chat historydocument.getElementById("output").scrollTop = document.getElementById("output").scrollHeight;// Clear the user input fielddocument.getElementById("prompt").value = "";previousPrompts.push(prompt);// Clear the spinner and show the "Send" button againdocument.getElementById("send-button").innerHTML = 'Send';}).catch(error => {console.error(error);// Hide the spinner and show the "Send" button againdocument.getElementById("send-button").innerHTML = 'Send';});
});document.getElementById("prompt").addEventListener("keydown", function(event) {if (event.keyCode === 13) {event.preventDefault();document.getElementById("send-button").
click();}
});
</script>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

I have read https://openai.com/blog/introducing-chatgpt-and-whisper-apis and referred to this - OpenAI ChatGPT (gpt-3.5-turbo) API: How to access the message content? but still can't make it work.

我已经阅读了https://openai.com/blog/introducing-chatgpt-and-whisper-apis并参考了这个 - OpenAI ChatGPT (gpt-3.5-turbo) API: 如何访问消息内容?但仍然无法使其正常工作

I've tried changing the requestData to this, but no luck:

我尝试将 requestData 更改为如下,但仍然没有成功

const requestData = {model: "gpt-3.5-turbo",messages: [{ role: "user", content: prompt }],max_tokens: 400,temperature: 0.5,top_p: 1,frequency_penalty: 0,presence_penalty: 0};

Any help will be greatly appreciated!

任何帮助将不胜感激

问题解决:

better check your requestData object, the GPT 3.5 turbo doesn't need these props

最好检查一下你的 requestData 对象,GPT-3.5 turbo 不需要这些属性

max_tokens,temperature,top_p: 1,frequency_penalty,presence_penalty

I made the same mistake too, GPT 3.5 turbo is way easier to use than I expected. Here's OpenAI sample:

我也犯了同样的错误,GPT-3.5 turbo 比我预期的要简单得多。这里是 OpenAI 的示例

const { Configuration, OpenAIApi } = require("openai");const configuration = new Configuration({apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);const completion = await openai.createChatCompletion({model: "gpt-3.5-turbo",messages: [{role: "user", content: "Hello world"}],
});
console.log(completion.data.choices[0].message);

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

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

相关文章

前端开发之装饰器模式

介绍 装饰器模式 是在不修改对象内部结构的情况下&#xff0c;动态地给对象添加功能的一种设计模式。在软件开发中&#xff0c;有时候我们需要为已有对象添加一些额外的行为&#xff0c;但不希望修改该对象的代码&#xff0c;装饰器模式可以很好的满足这一需求。 在TypeScrip…

echarts map地图动态下钻,自定义标注,自定义tooltip弹窗【完整demo版本】

在数据可视化中&#xff0c;地图是很重要的一个环节&#xff0c;很多时候需要展现的不仅是国家地图&#xff0c;还需要能从国家进入到省市。这个逐级进入的过程就是我们今天说的地图下钻。 地图下钻看起来很屌、很高大上&#xff0c;但是仔细琢磨一下&#xff0c;技术实现上真的…

Cpp类和对象(下)(6)

文章目录 前言一、初始化列表概念使用注意实际运用explicit关键字初始化列表的总结 二、static成员static成员的概念static成员的特性static的一个实用场景 三、友元友元函数友元类 四、内部类概念特性 五、匿名对象六、再次理解封装和面向对象总结 前言 Hello&#xff0c;本篇…

『玉竹』基于Laravel 开发的博客、微博客系统和Android App

基于 Laravel 和 Filament 开发, 使用 Filament 开发管理后台&#xff0c;前端比较简洁。 博客大家都清楚是什么东西&#xff0c;微博客类似于微博之类的吧&#xff0c;有时候想要写的东西可能只有几句话&#xff0c;想要起个标题都不好起。 为了是微博客功能更好用&#xff0c…

【小程序】微信小程序课程 -3 快速上手之常用方法

目录 1、 对话框 1.1 模态对话框 1.2 消息对话框 2、 存储 2.1 同步 2.1.1 同步保存数据 2.1.2 同步获取数据 2.1.3 同步删除数据 2.1.4 同步清空数据 2.2 异步 2.2.1 异步保存数据 2.2.2 异步获取数据 2.2.3 异步删除数据 2.2.4 异步清空数据 3、 上拉加载更多…

Java类加载揭秘:从加载过程到双亲委派机制

类的加载 目标 能够理解字节码加载过程 【了解】 路径 类的加载过程类的加载时机 类的加载 当程序在运行后&#xff0c;第一次使用某个类的时候&#xff0c;会将此类的class文件读取到内存&#xff0c;并将此类的所有信息存储到一个Class对象中 说明&#xff1a;Class对象…

金仓数据库 KingbaseES参考手册 (8. 函数(九))

8.299. SCALE 用法&#xff1a; scale(numeric)功能&#xff1a; SCALE返回参数的精度&#xff08;小数点后的位数&#xff09;。 例子&#xff1a; SELECT scale(8.41);8.300. SCORE 用法&#xff1a; SCORE(lable number)输入参数&#xff1a; lable&#xff1a;表示第几个co…

js发送邮件至指定邮箱功能实现方式和技巧?

js发送邮件至指定邮箱的教程&#xff1f;怎么使用Node.js发信&#xff1f; 无论是用户反馈、订单确认还是密码重置&#xff0c;js发送邮件至指定邮箱的需求无处不在。AokSend将深入探讨js发送邮件至指定邮箱的实现方式和技巧&#xff0c;帮助开发者更好地理解和应用这一功能。…

windows桌面管理软件推荐:一键整理桌面!美化电脑桌面小助手!

windows桌面管理软件推荐来咯&#xff01;在繁忙的工作和生活中&#xff0c;一个整洁、有序的电脑桌面不仅能提升工作效率&#xff0c;还能带来愉悦的视觉体验。然而&#xff0c;随着文件的增多&#xff0c;桌面往往变得杂乱无章。幸运的是&#xff0c;市面上有许多优秀的Windo…

推荐一款开源的Redis桌面客户端

TinyRDM 是一个现代化的、轻量级的跨平台 Redis 桌面客户端&#xff0c;能在 Mac、Windows 和 Linux 系统上使用。它有着现代化的设计风格&#xff0c;界面既简洁又清晰&#xff0c;操作起来方便又高效。不管是刚开始接触的新手&#xff0c;还是经验丰富的开发者&#xff0c;都…

C++标准库类——string类

引言 在c中&#xff0c;string类的引用极大地简化了字符串的操作和管理&#xff0c;相比 C 风格字符串&#xff08;char*或cahr[]&#xff09;&#xff0c;std::string 提供了更高效和更安全的字符串操作。接下来让我们一起来深入学习string类吧&#xff01; 1.string 的构造…

Spring Cache的使用

一、简介 1. Spring Cache是Spring提供的一个缓存框架&#xff0c;在Spring3.1版本开始支持将缓存添加到现有的spring应用程序中&#xff0c;在4.1开始&#xff0c;缓存已支持JSR-107注释和更多自定义的选项。 1. Spring Cache利用了**AOP**&#xff0c;实现了基于注解的缓存…

【解密 Kotlin 扩展函数】命名参数和默认值(十三)

导读大纲 1.0.1 命名参数1.0.2 默认参数值 上一节讲述如何自定义 joinToString 函数来代替集合的默认字符串表示 文末遗留下几个待优化问题–传送门 1.0.1 命名参数 我们要解决的第一个问题涉及函数调用的可读性 例如,请看下面的joinToString调用: joinToString(collection,&…

【LLM多模态】Animatediff文生视频大模型

note AnimateDiff框架&#xff1a;核心是一个可插拔的运动模块&#xff0c;它可以从真实世界视频中学习通用的运动先验&#xff0c;并与任何基于相同基础T2I的个性化模型集成&#xff0c;以生成动画。训练策略&#xff1a;AnimateDiff的训练包括三个阶段&#xff1a; 领域适配…

spark之不同序列化对比

一&#xff0c;spark的rdd的序列话不同介绍 下面是使用不同序列化后的占用资源和数据大小 2&#xff0c;sparksql中序列化的区别 sparksql中使用序列化和不使用差别不大&#xff0c;英文sparksql中默认使用了encode自己实现的序列化方法&#xff0c;加上与不加序列化差别不大…

基于真实山地场景下的超多目标优化算法求解无人机三维路径规划,MATLAB代码

超多目标优化算法是一类专门用于解决存在三个以上目标函数的最优化问题的算法。这类问题在现实世界中非常常见&#xff0c;例如在工程设计、资源管理、机器学习等领域。由于目标之间的冲突性&#xff0c;很难找到一个单一的解来同时优化所有目标&#xff0c;因此超多目标优化算…

MQ高级(二):死信交换机--延迟消息及DelayExchange插件--超时订单案例实现

目录 1.延迟消息 1.1.死信交换机和延迟消息 1.1.1.死信交换机 1.1.2.延迟消息 1.2.DelayExchange插件 1.2.1.下载 1.2.2.安装 1.2.3.声明延迟交换机 1.2.4.发送延迟消息 1.3.超时订单问题 1.3.1.定义常量 1.3.2.配置MQ 1.3.3.改造下单业务&#xff0c;发送延迟消息…

【Linux篇】TCP/IP协议(笔记)

目录 一、TCP/IP协议族体系结构 1. 数据链路层 &#xff08;1&#xff09;介绍 &#xff08;2&#xff09;常用协议 ① ARP协议&#xff08;Address Resolve Protocol&#xff0c;地址解析协议&#xff09; ② RARP协议&#xff08;Reverse Address Resolve Protocol&…

详解Web测试和APP测试的区别

&#x1f345; 点击文末小卡片&#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 最近听到有些朋友说&#xff0c;移动端要比web端稍微难一些&#xff0c;涉及到的细节笔记要多&#xff0c;有转去做web测试的想法&#xff0c;看看在具体测试的…

秋招面试准备:《小米2024数字芯片岗面试题》

在数字芯片设计的浪潮中&#xff0c;验证工程师的角色愈发重要。他们如同守门人&#xff0c;确保每一块芯片在投入市场前都能稳定、高效地运行。小米&#xff0c;作为全球知名的智能设备制造商&#xff0c;对数字芯片岗位的人才选拔尤为严格。 本文分享《小米2024数字芯片岗面…