Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 210a0b4

Browse files
authored
Merge pull request #20 from PSDTools/gemini-chat
Gemini chat
2 parents 1008c71 + 0197bc7 commit 210a0b4

File tree

5 files changed

+37
-39
lines changed

5 files changed

+37
-39
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ web-ext.config.ts
2424
*.sw?
2525

2626
.turbo
27+
28+
# API keys
29+
.env

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@dvcol/svelte-simple-router": "^1.10.3",
25+
"@google/generative-ai": "^0.22.0",
2526
"lucide-svelte": "^0.474.0"
2627
},
2728
"devDependencies": {

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entrypoints/popup/Chat.svelte

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22
import BlankAnchor from "./BlankAnchor.svelte";
33
import Wrapper from "./Wrapper.svelte";
44
import { Send } from "lucide-svelte";
5+
import { GoogleGenerativeAI } from "@google/generative-ai";
6+
7+
const key = import.meta.env.VITE_GEMINI_API_KEY;
8+
9+
const genAI = new GoogleGenerativeAI(key);
10+
// console.log(result.response.text());
511
612
const parameters = new URLSearchParams(
713
globalThis.location.hash.split("?")[1],
814
);
915
1016
let question = $state<string>(parameters.get("q") ?? "");
11-
let currentQuestion = $state<string>("");
17+
// let currentQuestion = $state<string>("");
1218
let response = $state<string>();
1319
let loading = $state<boolean>(false);
20+
21+
const model = genAI.getGenerativeModel({
22+
model: "gemini-2.0-flash-lite",
23+
systemInstruction:
24+
'you are DUCKY and have to help people with cybersecurity and digital literacy. always say "Quack!" at the end of every response. Have a playful but serious tone; business casual. DUCKY has a phishing detector, chat bot, and website fact checker. DUCKY is a chrome and firefox web extension. The phishing detector will automatically pop up when the user looks at an email and determines if it is phishing. The chatbot is what you are and can help users understand information or can be used to ask questions. The fact checker checks websites data and finds sources and other places to determine if the website is trustworthy. DUCKY is a rubber duck because computer science often uses rubber duckies to talk to. Be friendly, no cursing. Keep response under 75 words exclude the word "Quack!" from the count. Do not leave blank lines inbetween lines.',
25+
});
1426
</script>
1527

1628
<Wrapper pageTitle="Ducky Chat">
@@ -21,47 +33,16 @@
2133
class="form"
2234
onsubmit={(event) => {
2335
setTimeout(() => {
24-
switch (currentQuestion.trim()) {
25-
case "What do you do?": {
26-
response =
27-
"I am an AI assistant that will help with digital literacy and cyber security! Quack!";
28-
29-
break;
30-
}
31-
32-
case "Tell me more about how you can help.": {
33-
response =
34-
"I can help by detecting AI images, I can fact-check websites, and let you know if an email you got is phishing! Quack!";
35-
36-
break;
37-
}
38-
39-
case "How can I spot phishing?": {
40-
response =
41-
"You can spot phishing by checking for unexpected requests for personal information, false sender info, suspicious links, and spelling errors. Quack!";
42-
43-
break;
44-
}
45-
46-
case "": {
47-
response = "Please enter a question. Quack!";
48-
49-
break;
50-
}
51-
52-
default: {
53-
response = "I'm sorry, I didn't understand that. Quack!";
54-
55-
break;
56-
}
57-
}
58-
36+
void (async () => {
37+
const airesponse = await model.generateContent(question);
38+
console.log(airesponse.response.text());
39+
response = airesponse.response.text();
40+
})();
5941
loading = false;
6042
}, 2000);
6143

6244
loading = true;
63-
currentQuestion = question;
64-
question = "";
45+
// question = "";
6546
event.preventDefault();
6647
}}
6748
>
@@ -72,7 +53,7 @@
7253
</form>
7354

7455
<div class="open">
75-
<BlankAnchor class="chat-button" href="https://chatgpt.com">
56+
<BlankAnchor class="chat-button" href="https://ducky.psdr3.org/">
7657
Open Chat in Browser
7758
</BlankAnchor>
7859
</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// eslint-disable-next-line unicorn/prevent-abbreviations
2+
interface ImportMetaEnv {
3+
VITE_GEMINI_API_KEY: string;
4+
}

0 commit comments

Comments
 (0)