-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (23 loc) · 802 Bytes
/
index.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
const express = require('express');
const path = require('path');
const { generateSqlQuery } = require('./src/sql-llm.js');
const app = express();
const port = 3000;
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.post('/query', async (req, res) => {
const { question } = req.body;
try {
const {query, databaseResult} = await generateSqlQuery(question);
console.log({ query, databaseResult });
res.json({ query, databaseResult });
} catch (error) {
res.status(500).json({ error: 'Error generating SQL query' });
}
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});