File size: 1,177 Bytes
0ca1506 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
// pages/api/chat.js
import axios from 'axios';
export const config = {
"name": "chatgptweb",
"url": "/api/chatgptweb",
"description": "Get response from Chatgptweb. Chatgptweb is a ChatGPT API. It can be used to get responses from ChatGPT. It can provide you with the latest news, weather, and more.",
"query": "prompt",
"response": "text",
"testURL": "./api/chatgptweb?prompt=hello"
}
const url = "https://niansuhai-llms.hf.space/api/openai/v1/chat/completions";
const main = async (prompt) => {
const response = await axios.post(url, {
messages: [
{ role: "user", content: "hi" },
{ role: "assistant", content: "Hello! How can I assist you today?" },
{ role: "user", content: prompt },
],
stream: false,
model: "gpt-3.5-turbo",
temperature: 0.5,
presence_penalty: 0,
frequency_penalty: 0,
top_p: 1,
});
console.log(response.data.choices[0].message.content);
return response.data.choices[0].message.content
};
export default async function handler(req, res) {
const {prompt} = req.query;
const response = await main(prompt);
res.status(200).json({response: response});
} |