-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (61 loc) · 1.88 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as Rivet from '@ironclad/rivet-node';
import RivetPluginFs from "rivet-plugin-fs";
import express from 'express';
import bodyParser from 'body-parser';
import 'dotenv/config';
import { plugins as rivetPlugins } from '@ironclad/rivet-core';
//import cors from 'cors';
Rivet.globalRivetNodeRegistry.registerPlugin(RivetPluginFs(Rivet));
Rivet.globalRivetNodeRegistry.registerPlugin(rivetPlugins.anthropic);
const app = express();
const port = 3000;
//app.use(cors());
//console.log(process.env.OPENAPIKEY);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post('/generate', async (req, res) => {
const post = req.body;
/* example:
const inputs = {
task: { type: 'string', value: 'Crea un API che prenda dalla tabella Products il nome, categoria e prezzo' },
filament: { type: 'string', value: 'true' },
test: { type: 'string', value: 'true' },
};*/
const inputs = {
task: { type: 'string', value: post.task },
filament: { type: 'string', value: post.filament.toString() },
test: { type: 'string', value: post.test.toString() },
};
//console.log(inputs);
await rivet(res, inputs);
//res.send('Code Generated Successfully');
});
app.listen(port, () => console.log(`Listening on port ${port}!`));
async function rivet(res, data) {
await Rivet.runGraphInFile('./Api.rivet-project', {
graph: 'Flex Code Generator',
externalFunctions: {
async getTask() {
return data.task
},
async getTest() {
return data.test
},
async getFilament() {
return data.filament
}
},
onUserEvent: {
myEvent(data) {
console.log(data);
},
setFile(data) {
res.send(data);
},
},
openAiKey: process.env.OPEN_API_KEY,
getPluginConfig: {
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
},
});
}