File size: 1,386 Bytes
dc7aadc
 
 
8bf27ec
dc7aadc
0d6a55d
57676b8
 
 
 
 
 
 
 
 
 
 
 
dc7aadc
 
 
 
66a7c30
d312f25
 
 
 
 
66a7c30
d312f25
57676b8
 
 
 
 
 
cc7a029
0d6a55d
413cf0d
0d6a55d
57676b8
 
 
 
 
dc7aadc
 
 
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
41
42
43
44
45
46
47
48
const express = require('express')
const app = express()
const port = 7860
const axios = require('axios')

const headers = {
  "Accept": "application/json",
  "Content-Type": "application/json",
  "Accept-Language": "en",
  "Connection": "keep-alive",
  "Origin": "https://remix.ethereum.org/",
  "Referer": "https://remix.ethereum.org/",
  "Sec-Fetch-Dest": "empty",
  "Sec-Fetch-Mode": "cors",
  "Sec-Fetch-Site": "cross-site",
  "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"
}

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.get('/api/test', async (req, res) => {
  try {
    res.json({message: "Hello world"})
  } catch (error) {
    res.status(401).json({error: error.message})
  }
})

app.post('/api/chatgpt-old', async (req, res) => {
  try {
    query = req.params.query
    const payload = {"prompt": query}
    const type_urls = "openai-gpt"
    const url = "https://${type_urls}.remixproject.org"
    const response = await axios.post(url, payload, { headers })
    console.log('Response:', response.data)
    const output = response.data.choices[0].message.content;
    res.json({message: output})
  } catch (error) {
    res.status(401).json({error: error.message})
  }
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})