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

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.kler.cn/news/294694.html

相关文章:

  • 云计算实训41——部署project_exam_system项目(续)
  • 关于Qt在子线程中使用通讯时发生无法接收数据的情况
  • Docker配置Redis持久化
  • 如何保护服务器免受恶意软件攻击?
  • C++学习笔记(11)
  • 【网络安全】如何预防xss
  • 基于EPS32C3电脑远程开机模块设计
  • 飞思相机存储卡格式化数据如何恢复?提供全面指南
  • 风格控制水平创新高!南理工InstantX小红书发布CSGO:简单高效的端到端风格迁移框架
  • 【Nacos】负载均衡
  • 应用层简单实现udp / tcp网络通信
  • 「大数据分析」图形可视化,如何选择大数据可视化图形?
  • Qt: 详细理解delete与deleteLater (避免访问悬空指针导致程序异常终止)
  • JAVA并发编程JUC包之CAS原理
  • 概率学 笔记一 - 概率 - 随机变量 - 期望 - 方差 - 标准差(也不知道会不会有二)
  • 【AcWing】853. 有边数限制的最短路(bellman-ford贝尔曼福特算法)
  • 【HTML】script标签asyncdefer
  • 第十五届蓝桥杯青少组省赛成绩查询及国赛考试安排
  • 如何实现加密功能
  • 内置消息支持
  • 【电子通识】洁净度等级划分及等级标准
  • macOS 安装 Homebrew
  • 电子发射与气体导电
  • 用ceres实现lio-sam平面点匹配
  • SVD降维
  • 网络安全威胁与防范
  • Java-数据结构-链表-LinkedList(二)|ू・ω・` )
  • 【牛站 / USACO2007】
  • 图欧科技-IMYAI智能助手24年8月更新日志大汇总(含史诗级更新)
  • 如何在SQL Server中恢复多个数据库?