状态"/>
如何通过 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 并保持对话状态
发布评论