You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnResponse.json({error: "Report ID is required"},{status: 400});
14
+
}
15
+
16
+
if(!question||typeofquestion!=="string"){
17
+
returnResponse.json(
18
+
{error: "Question is required and must be a string"},
19
+
{status: 400},
20
+
);
21
+
}
22
+
23
+
constcacheDoc=awaitadminDb
24
+
.collection("cache")
25
+
.doc(id.toLowerCase())
26
+
.get();
27
+
28
+
if(!cacheDoc.exists){
29
+
returnResponse.json(
30
+
{error: "Report not found",id: id.toLowerCase()},
31
+
{status: 404},
32
+
);
33
+
}
34
+
35
+
constdocData=cacheDoc.data();
36
+
constcontextPayload={
37
+
id: cacheDoc.id,
38
+
cached_at: docData?.cached_at??null,
39
+
query: docData?.query??id,
40
+
report: docData?.report??null,
41
+
};
42
+
43
+
constresult=awaitai.models.generateContent({
44
+
model: "gemini-2.0-flash-exp",
45
+
contents: [
46
+
{
47
+
role: "user",
48
+
parts: [
49
+
{
50
+
text: `You are an expert security analyst. Rely ONLY on the context provided below when answering the user's question.
51
+
If the context does not contain the requested information, reply exactly with "I don't have information about that in this report."
52
+
Do not speculate, hallucinate, or reference external knowledge. Keep answers to 2-4 concise sentences and reference concrete values from the context when available.
53
+
54
+
Context (JSON):
55
+
${JSON.stringify(contextPayload,null,2)}
56
+
57
+
Question: ${question}`,
58
+
},
59
+
],
60
+
},
61
+
],
62
+
});
63
+
64
+
constanswer=result.text?.trim();
65
+
66
+
if(!answer){
67
+
returnResponse.json(
68
+
{error: "The analyst could not generate an answer."},
0 commit comments