Repository navigation
Expand file tree
/
Copy pathtest_api.cjs
More file actions
63 lines (58 loc) · 2.2 KB
/
Copy pathtest_api.cjs
File metadata and controls
63 lines (58 loc) · 2.2 KB
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
require('dotenv').config({ path: '.env.local' });
const { GoogleGenAI, Type } = require('@google/genai');
const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
async function testIntervenSchema() {
try {
const res = await client.models.generateContent({
model: 'gemini-3.8-flash',
contents: [{ role: 'user', parts: [{ text: 'Rahul wants to pause SIP for 3 months due to market volatility. Shortfall: Rs 264192, units missed: 199.' }] }],
config: {
systemInstruction: 'You are FinLit AI Co-pilot. Provide a short behavioral audit warning.',
responseMimeType: 'application/json',
responseSchema: {
type: Type.OBJECT,
properties: {
auditText: { type: Type.STRING },
recommendedAction: { type: Type.STRING, enum: ['step_down', 'shorten_pause', 'proceed', 'cancel'] }
},
required: ['auditText', 'recommendedAction']
}
}
});
console.log('INTERVENE TEST OK:', res.text);
} catch (e) {
console.log('INTERVENE FAIL:', e.message);
}
}
async function testWithdrawSchema() {
try {
const res = await client.models.generateContent({
model: 'gemini-3.8-flash',
contents: [{ role: 'user', parts: [{ text: 'Fund: UTI Nifty 50. Invested: Rs 700000. Current: Rs 820000. XIRR: 18.2%' }] }],
config: {
systemInstruction: 'You are FinLit AI. Warn against withdrawal during a 10% market crash.',
responseMimeType: 'application/json',
responseSchema: {
type: Type.OBJECT,
properties: { warningText: { type: Type.STRING } },
required: ['warningText']
}
}
});
console.log('WITHDRAW TEST OK:', res.text);
} catch (e) {
console.log('WITHDRAW FAIL:', e.message);
}
}
async function testChat() {
try {
const res = await client.models.generateContent({
model: 'gemini-3.8-flash',
contents: [{ role: 'user', parts: [{ text: 'What is my portfolio health score? User question: Should I pause my SIP?' }] }],
});
console.log('CHAT TEST OK:', res.text.slice(0, 120));
} catch (e) {
console.log('CHAT FAIL:', e.message);
}
}
testIntervenSchema().then(testWithdrawSchema).then(testChat);