-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1023 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
30
31
32
33
34
35
36
37
38
39
40
41
42
import express from 'express';
import cors from 'cors';
import morgan from 'morgan';
import { gemini15Flash, googleAI } from '@genkit-ai/googleai';
import { genkit } from 'genkit';
const app = express();
const port = 3001;
app.use(cors());
app.use(morgan('dev'));
app.use(express.json());
// configure a Genkit instance
const ai = genkit({
plugins: [googleAI()],
model: gemini15Flash, // set default model
});
const codeFlow = ai.defineFlow('customSolidityAndCairo', async (input) => {
// make a generation request
const { text } = await ai.generate(input);
return text;
});
app.post('/generate', async (req, res) => {
const input = req.body.input;
if (!input) {
return res.status(400).json({ error: 'Prompt is required' });
}
try {
const result = await codeFlow(input);
res.json({ response: result });
} catch (error) {
res.status(500).json({ error: 'Error generating text' });
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});