如何通过 curl ping ChatGPT 并保持对话状态

编程入门 行业动态 更新时间:2024-10-06 08:37:38

如何通过 curl ping ChatGPT 并保持对话<a href=https://www.elefans.com/category/jswz/34/1771386.html style=状态"/>

如何通过 curl ping ChatGPT 并保持对话状态

下面的代码正在运行。 我可以向 ChatGPT 提出问题,它会一次性回复。 但是,如果我尝试参与需要引用先前提交状态的对话,则聊天无法进行。

我想知道我需要做什么(以及需要的代码)来保留对话的上下文

const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: "sk-my-key",
});
const openai = new OpenAIApi(configuration);

// Set up the server
const app = express();
app.use(bodyParser.json());
app.use(cors())

// Set up the ChatGPT endpoint
app.post("/chat", async (req, res) => {
  // Get the prompt from the request
  const { prompt } = req.body;

  // Generate a response with ChatGPT
  const completion = await openai.createCompletion({
    model: "text-davinci-002",
    prompt: prompt,
  });
  res.send(completion.data.choices[0].text);
});

// Start the server
const port = 8080;
app.listen(port, () => {
  console.log(`Server listening on port ${port}`);
});

CURL 在新终端中运行:

curl -X POST -H "Content-Type: application/json" -d '{"prompt":"Hello, how are you doing today?"}' http://localhost:8080/chat
回答如下:

根据this,你可以在你的提示中保存你的聊天记录,设置系统、用户、助手等角色来总结之前的消息。每次请求前都保持

prompt
才能达到预期的效果

更多推荐

如何通过 curl ping ChatGPT 并保持对话状态

本文发布于:2024-05-30 06:15:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   curl   ping   ChatGPT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!