|
2 | 2 | import BlankAnchor from "./BlankAnchor.svelte"; |
3 | 3 | import Wrapper from "./Wrapper.svelte"; |
4 | 4 | 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()); |
5 | 11 |
|
6 | 12 | const parameters = new URLSearchParams( |
7 | 13 | globalThis.location.hash.split("?")[1], |
8 | 14 | ); |
9 | 15 |
|
10 | 16 | let question = $state<string>(parameters.get("q") ?? ""); |
11 | | - let currentQuestion = $state<string>(""); |
| 17 | + // let currentQuestion = $state<string>(""); |
12 | 18 | let response = $state<string>(); |
13 | 19 | 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 | + }); |
14 | 26 | </script> |
15 | 27 |
|
16 | 28 | <Wrapper pageTitle="Ducky Chat"> |
|
21 | 33 | class="form" |
22 | 34 | onsubmit={(event) => { |
23 | 35 | 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 | + })(); |
59 | 41 | loading = false; |
60 | 42 | }, 2000); |
61 | 43 |
|
62 | 44 | loading = true; |
63 | | - currentQuestion = question; |
64 | | - question = ""; |
| 45 | + // question = ""; |
65 | 46 | event.preventDefault(); |
66 | 47 | }} |
67 | 48 | > |
|
72 | 53 | </form> |
73 | 54 |
|
74 | 55 | <div class="open"> |
75 | | - <BlankAnchor class="chat-button" href="https://chatgpt.com"> |
| 56 | + <BlankAnchor class="chat-button" href="https://ducky.psdr3.org/"> |
76 | 57 | Open Chat in Browser |
77 | 58 | </BlankAnchor> |
78 | 59 | </div> |
|
0 commit comments