-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (27 loc) · 1.18 KB
/
Copy pathscript.js
File metadata and controls
38 lines (27 loc) · 1.18 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
// script.js — reference/test file for SafeHire AI's core logic
// (Live version of this logic runs inline inside dashboard.html)
const GEMINI_API_KEY = "ADD_YOUR_API_KEY";
const GEMINI_URL = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${GEMINI_API_KEY}`;
async function askgemini(prompt, resultId) {
const el = document.getElementById(resultId);
try {
const response = await fetch(GEMINI_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contents: [{ parts: [{ text: prompt }] }]
})
});
const data = await response.json();
if (!data.candidates) {
el.innerHTML = `<div class="result-content" style="color:var(--pink)">⚠️ ${data.error?.message || 'No response from AI'}</div>`;
return;
}
const answer = data.candidates[0].content.parts[0].text;
el.innerHTML = `<div class="result-content">${answer.replace(/\n/g, '<br/>')}</div>`;
} catch (err) {
el.innerHTML = `<div class="result-content" style="color:var(--pink)">⚠️ ${err.message}</div>`;
}
}
//Quick test call
askgemini("Explain about AI in a few lines");