|
|
|
|
|
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}); |
|
} |