Shuddho commited on
Commit
0ca1506
1 Parent(s): cc9763d

Upload chatgptweb.js

Browse files
Files changed (1) hide show
  1. pages/api/chatgptweb.js +40 -0
pages/api/chatgptweb.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // pages/api/chat.js
2
+
3
+ import axios from 'axios';
4
+
5
+ export const config = {
6
+ "name": "chatgptweb",
7
+ "url": "/api/chatgptweb",
8
+ "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.",
9
+ "query": "prompt",
10
+ "response": "text",
11
+ "testURL": "./api/chatgptweb?prompt=hello"
12
+ }
13
+
14
+ const url = "https://niansuhai-llms.hf.space/api/openai/v1/chat/completions";
15
+
16
+ const main = async (prompt) => {
17
+ const response = await axios.post(url, {
18
+ messages: [
19
+ { role: "user", content: "hi" },
20
+ { role: "assistant", content: "Hello! How can I assist you today?" },
21
+ { role: "user", content: prompt },
22
+ ],
23
+ stream: false,
24
+ model: "gpt-3.5-turbo",
25
+ temperature: 0.5,
26
+ presence_penalty: 0,
27
+ frequency_penalty: 0,
28
+ top_p: 1,
29
+ });
30
+
31
+ console.log(response.data.choices[0].message.content);
32
+ return response.data.choices[0].message.content
33
+ };
34
+
35
+ export default async function handler(req, res) {
36
+ const {prompt} = req.query;
37
+
38
+ const response = await main(prompt);
39
+ res.status(200).json({response: response});
40
+ }