-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (29 loc) · 991 Bytes
/
server.js
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
const express = require('express')
const app = express()
const cors = require('cors')
require('dotenv').config()
app.use(express.json())
app.use(cors())
const LANGUAGE_MODEL_API_KEY = process.env.LANGUAGE_MODEL_API_KEY
const LANGUAGE_MODEL_URL = `https://generativelanguage.googleapis.com/v1beta1/models/chat-bison-001:generateMessage?key=${LANGUAGE_MODEL_API_KEY}`
const PORT = 8000
app.get('/prompt/:text', async (req, res) => {
const text = req.params.text
const payload = {
prompt: { "messages": [{ "content": text }]},
temperature: 0.1,
candidate_count: 1,
// max_tokens: 10,
}
const response = await fetch(LANGUAGE_MODEL_URL, {
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload),
method: "POST",
})
const data = await response.json()
console.log(data)
res.send(data)
})
app.listen(PORT, () => console.log(`Listening on port ${PORT}`))