当前位置: 首页 > news >正文

How can I load the openai api configuration through js in html?

题意:怎样在HTML中通过JavaScript加载OpenAI API配置

问题背景:

I am trying to send a request through js in my html so that openai analyzes it and sends a response, but if in the js I put the following:

我正在尝试通过HTML中的JavaScript发送一个请求,以便让OpenAI分析它并发送响应,但如果我在JavaScript中放入以下内容:

const { Configuration, OpenAIApi } = require("openai");const configuration = new Configuration({
apiKey: "sk-0000000000000ZXXXXXXXXXXXXXX",
});
const openai = new OpenAIApi(configuration);async function test() {
console("test")
const response = await openai.createCompletion("text-davinci-002", {
prompt: "hello",
temperature: 0.7,
max_tokens: 64,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
console.log(response)
}
test();

return console these error        在控制台返回错误信息

Uncaught ReferenceError: require is not defined
at buttons.js:94:38

I have tried to install it with node.js and it works fine but I don't know how to make it work in my own html

“我已经尝试使用node.js安装它,并且它工作正常,但我不知道如何在我的HTML中使其工作”

问题解决:

Posting the correct link that currently works:

“发布当前有效的正确链接:”

var url = "https://api.openai.com/v1/completions";

and here is how the data should look like for question answering with davinchi-003 engine:

“以下是使用davinci-003引擎进行问答时数据应有的样子:”

var data = `{"model": "text-davinci-003","prompt": "${prompt_text+question_out}","temperature": 0.9,"max_tokens": 150,"top_p": 1,"frequency_penalty": 0.0,"presence_penalty": 0.6,"stop": [" Human:", " AI:"]}`;

here the prompt_text is the prompt text I sent o the engine and question_out is the question I want the engine to answer based on the prompt.

“在这里,prompt_text 是我发送给引擎的提示文本,而 question_out 是我希望引擎根据提示来回答的问题。”

http://www.lryc.cn/news/433039.html

相关文章:

  • Pipeline流水线通过git拉取Jenkinsfile报错 error: RPC failed; result=22, HTTP code = 404
  • 【与C++的邂逅】--- string容器使用
  • 1-18 平滑处理——高斯滤波 opencv树莓派4B 入门系列笔记
  • 小爱打工,你躺平!让「微信AI小助理」接管你的文件处理,一个字:爽!
  • 管理学习(一)马云《赢在中国》创业演讲整理
  • Opencv中的直方图(2)计算图像的直方图函数calcHist()的使用
  • Buzzer:一款针对eBPF的安全检测与模糊测试工具
  • 若依框架登录鉴权详解(动态路由)
  • 孤儿进程、僵尸进程、守护进程(精灵进程)
  • Centos9 网卡配置文件
  • ios免签H5
  • RedHat9.x-基本操作
  • 华为 HCIP-Datacom H12-821 题库 (5)
  • vue中oninput和@input区别
  • 分布式锁(Redis的setnx、Redisson)
  • 从0开始深度学习(4)——线性回归概念
  • C语言中的预处理指令中的其中一对——#ifdef和#ifndef
  • 交换机自动化备份配置(H3C_无人值守)
  • 缓存预热有哪些方案?
  • 「iOS学习」——Masonry学习
  • 828华为云征文|华为云Flexus云服务器X实例之openEuler系统下部署GitLab服务器
  • 51单片机的无线病床呼叫系统【proteus仿真+程序+报告+原理图+演示视频】
  • 计算机毕业设计 | SpringBoot+vue 游戏商城 steam网站管理系统(附源码)
  • 【CH395的简单示例代码】
  • AI模型:追求全能还是专精?
  • ffmpeg音视频开发从入门到精通——ffmpeg 视频数据抽取
  • Node.js之文件夹的操作
  • 线程的四种操作
  • 自我指导:提升语言模型自我生成指令的能力
  • 使用Node.js实现单文件上传功能—含代码解释