Update index.js
Browse files
index.js
CHANGED
@@ -15,30 +15,42 @@ app.get('/api/test', async (req, res) => {
|
|
15 |
}
|
16 |
})
|
17 |
|
18 |
-
const
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
try {
|
25 |
-
const
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
} catch (error) {
|
28 |
-
|
29 |
-
|
30 |
-
} else {
|
31 |
-
console.error("Error Message:", error.message);
|
32 |
-
}
|
33 |
-
return "Error occurred!";
|
34 |
}
|
35 |
};
|
36 |
|
37 |
-
app.get('/api/
|
38 |
try {
|
39 |
const query = req.params.query;
|
40 |
-
const
|
41 |
-
res.json({
|
42 |
} catch (error) {
|
43 |
res.status(401).json({ error: error.message });
|
44 |
}
|
|
|
15 |
}
|
16 |
})
|
17 |
|
18 |
+
const payload = (prompt) => ({
|
19 |
+
model: "gpt-4o",
|
20 |
+
prompt: prompt,
|
21 |
+
top_p: 1,
|
22 |
+
logprobs: null,
|
23 |
+
stop: null
|
24 |
+
});
|
25 |
+
|
26 |
+
const OpenaiRes = async (prompt) => {
|
27 |
try {
|
28 |
+
const url = "https://openai-gpt.remixproject.org/";
|
29 |
+
const headers = {
|
30 |
+
"Accept": "application/json",
|
31 |
+
"Content-Type": "application/json",
|
32 |
+
"Accept-Language": "en",
|
33 |
+
"Connection": "keep-alive",
|
34 |
+
"Origin": "https://remix.ethereum.org",
|
35 |
+
"Referer": "https://remix.ethereum.org/",
|
36 |
+
"Sec-Fetch-Dest": "empty",
|
37 |
+
"Sec-Fetch-Mode": "cors",
|
38 |
+
"Sec-Fetch-Site": "cross-site",
|
39 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134"
|
40 |
+
};
|
41 |
+
const response = await axios.post(url, payload(prompt), { headers, timeout: 50000 });
|
42 |
+
return response.data;
|
43 |
} catch (error) {
|
44 |
+
console.error("Error:", error.message);
|
45 |
+
return null;
|
|
|
|
|
|
|
|
|
46 |
}
|
47 |
};
|
48 |
|
49 |
+
app.get('/api/gpt-old', async (req, res) => {
|
50 |
try {
|
51 |
const query = req.params.query;
|
52 |
+
const results = await OpenaiRes(query);
|
53 |
+
res.json({ results });
|
54 |
} catch (error) {
|
55 |
res.status(401).json({ error: error.message });
|
56 |
}
|