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.xdnf.cn/news/1544074.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Android Studio 真机USB调试运行频繁掉线问题

一、遇到问题 Android Studio使用手机运行项目时&#xff0c;总是频繁掉线&#xff0c;连接很不稳定&#xff0c;动不动就消失&#xff0c;基本上无法使用 二、问题出现原因 1、硬件问题&#xff1a;数据线 换条数据线试试&#xff0c;如果可以&#xff0c;那就是数据线的…

15年408-数据结构

第一题 解析&#xff1a; 栈第一次应该存main的信息。 然后进入到main里面&#xff0c;要输出S(1)&#xff0c;将S(1)存入栈内&#xff0c; 进入到S(1)中&#xff0c;1>0,所以还要调用S(0) S(0)进入栈中&#xff0c;此时栈内从下至上依次是main(),S(1),S(0) 答案选A 第二题&…

昇腾AI异构计算架构CANN——高效使能AI原生创新

异构计算与人工智能的关系是什么&#xff1f;昇腾AI异构计算架构CANN是什么&#xff1f;有哪些主要特点&#xff1f;开发者如何利用CANN的原生能力进行大模型创新&#xff0c;构筑差异化竞争力&#xff1f;带着这些问题&#xff0c;我们来认识昇腾AI异构计算架构——CANN。 1 …

随机验证码验证【JavaScript】

这段 JavaScript 代码实现了随机验证码的生成和验证功能。 实现效果&#xff1a; 代码&#xff1a; <!DOCTYPE html> <html lang"zh"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-…

Vue3教程 - 2 开发环境搭建

更好的阅读体验&#xff1a;点这里 &#xff08; www.foooor.com &#xff09; 2 开发环境搭建 要进行 Vue 开发&#xff0c;需要安装 Node.js&#xff0c;因为构建 Vue 项目的工具&#xff0c;例如 Webpack、Vite等&#xff0c;这些工具依赖于Node.js环境来运行。 Node.js…

OpenAI GPT-3 API: What is the difference between davinci and text-davinci-003?

题意&#xff1a;OpenAI GPT-3 API&#xff1a;davinci 和 text-davinci-003 有什么区别 问题背景&#xff1a; Im testing the different models for OpenAI, and I noticed that not all of them are developed or trained enough to give a reliable response. 我正在测试…

玩手机数据集 8201张玩手机的照片,有对应的xml和txt文件,可以用于yolo训练

玩手机数据集 8201张玩手机的照片&#xff0c;有对应的xml和txt文件&#xff0c;可以用于yolo训练 玩手机数据集&#xff08;Phone Usage Detection Dataset&#xff09; 数据集概述 该数据集专为检测人们使用手机的行为设计&#xff0c;旨在帮助研究人员和工程师开发高效的…

Sentinel-1 数据处理时如何手动下载高程数据

在Sentinel-1 数据数据预处理时&#xff0c;会使用高程数据进行地形校正。但选择自动下载高程时&#xff0c;由于网络原因经常会卡死&#xff0c;造成预处理过程不能正常进行&#xff01; 这个问题经过我的反复实践&#xff0c;可以通过手动下载高程数据来解决。下面是具体方法…

MySQL之基本查询(一)(insert || select)

目录 一、表的增删查改 二、表的增加insert 三、表的读取select where 条件子句 结果排序 筛选分页结果 一、表的增删查改 我们平时在使用数据库的时候&#xff0c;最重要的就是需要对数据库进行各种操作。而我们对数据库的操作一般来说也就是四个操作&#xff0c;CRUD :…

【学术会议征稿】第七届电力电子与控制工程国际学术会议(ICPECE 2024)

高录用|快检索|JPCS独立出版ISSN:1742-6596 连续6年EI检索&#xff0c;稳定且快速 见刊后均1个月检索 第七届电力电子与控制工程国际学术会议&#xff08;ICPECE 2024&#xff09; 2024 7th International Conference on Power Electronics and Control Engineering 2024年…

认知作战壳吉桔:未来认知战战略全案发展趋势

认知作战壳吉桔&#xff1a;未来认知战战略全案发展趋势 认知作战壳吉桔&#xff1a;未来认知战战略全案发展趋势 关键词&#xff1a;认知战战术融合, 数据驱动决策, 生成式人工智能AIGC, 影响力认知, 个性化定制, 沉浸式体验, 视频直播认知, 受众体验优化, 社交媒体互动, 可…

[PICO VR]Unity如何往PICO VR眼镜里写持久化数据txt/json文本

前言 最近在用PICO VR做用户实验&#xff0c;需要将用户实验的数据记录到PICO头盔的存储空间里&#xff0c;记录一下整个过程 流程 1.开启写入权限 首先开启写入权限&#xff1a;Unity->Edit->Player->安卓小机器人->Other Settings->Configuration->Wri…

如何用LightningChart Python实现地震强度数据可视化应用程序?

LightningChart Python是知名图表控件公司LightningChart Ltd正在研发的 Python 图表&#xff0c;目前还未正式推出&#xff0c;感兴趣的朋友可以戳文末链接申请试用&#xff01; 什么是地面震动强度 Python 应用程序&#xff1f; 地面震动是地震的基本特征&#xff0c;会对建…

【Linux】fork入门级使用

目录 一、前置准备 1、进程的基本概念 2、进程标识符PID、PPID 1&#xff09;pid介绍 2&#xff09;获取pid和ppid 二、fork函数 1、fork的基本介绍 1&#xff09;fork&#xff08;&#xff09;&#xff1a; 创建子进程 2&#xff09;对于函数具体的描述 3&#xff09…

yuque-dl-语雀知识库下载为本地markdown

之前有下载语雀的需求&#xff0c;发现了一个开源项目&#xff0c;用起来还是很顺手的 需要环境 需要前端的node环境 https://nodejs.cn/ Node.js 18.4 or later 插入 npm i -g yuque-dl 使用 $ yuque-dl --helpUsage:$ yuque-dl <url>Commands:<url> …

Python 如何读取和写入文件

Python 如何读取和写入文件 文件操作是编程中常见的任务&#xff0c;几乎所有编程语言都支持文件的读写功能。在 Python 中&#xff0c;文件操作简单直观&#xff0c;适用于从初学者到经验丰富的开发者。无论是处理小型文本文件&#xff0c;还是需要处理大型数据文件&#xff…

fo-dicom是如何实现DICOM 的网络通信功能

一、前言 前面的文章&#xff0c;我们介绍了fo-dicom是一个怎样的开源库等一些内容&#xff1a; fo-dicom&#xff0c;第一个基于.NET Standard 2.0 开发的DICOM开源库fo-dicom开源库是如何满足 DICOM标准的基本要求fo-dicom开发之DICOM数据解析&#xff1a;常见数据类型及处…

【Transformers基础入门篇2】基础组件之Pipeline

文章目录 一、什么是Pipeline二、查看PipeLine支持的任务类型三、Pipeline的创建和使用3.1 根据任务类型&#xff0c;直接创建Pipeline&#xff0c;默认是英文模型3.2 指定任务类型&#xff0c;再指定模型&#xff0c;创建基于指定模型的Pipeline3.3 预先加载模型&#xff0c;再…

pycharm恢复两边侧边栏常驻显示

问题&#xff1a; pycharm两边的侧边栏菜单默认不显示&#xff08;打开project还得用alt1快捷键&#xff09;&#xff0c;非常不方便&#xff0c;如下图&#xff1a; pycharm版本&#xff1a;2022.3 professional 勾选&#xff1a;setttngs -> Appearance -> tool Wind…

云原生虚拟化kubevirt安装

kubevirt 介绍 Kubevirt 是 Redhat 开源的一套以容器方式运行虚拟机的项目&#xff0c;通过 kubernetes 云原生方式来管理虚拟机生命周期。它通过使用自定义资源&#xff08;CRD&#xff09;和其它 Kubernetes 功能来无缝扩展现有的集群&#xff0c;以提供一组可用于管理虚拟机…