Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions middlewareNode/chatHistory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"role": "user",
"parts": [
{
"text": "my name is Mario, what are you?"
}
]
},
{
"role": "model",
"parts": [
{
"text": "Hi Mario! I'm a helpful chatbot here to assist you with information about Y STEM and Chess Inc. (YSC). We're a non-profit organization dedicated to introducing kids in K-12 to the exciting world of STEM through chess and the Mastery Learning method. We focus on helping underserved and at-risk children develop STEM skills and pursue STEM careers. How can I help you today?\n"
}
]
},
{
"role": "user",
"parts": [
{
"text": "I have son named Luigi, he wants become an engineer, what advice do you have for him?"
}
]
},
{
"role": "model",
"parts": [
{
"text": "That's wonderful that Luigi wants to become an engineer! It's a challenging but rewarding career path. Here's some advice for him, broken down by age group (assuming he's K-12 since that's our focus):\n\n**For younger Luigi (K-5):**\n\n* **Focus on fundamentals:** Encourage a love of learning and problem-solving. Chess is a great tool for this – it teaches critical thinking, planning, and strategic thinking, all essential for engineering. Make learning fun! Explore age-appropriate STEM kits, books, and activities.\n* **Develop strong math and science skills:** These are the cornerstones of engineering. Make sure he's comfortable with basic arithmetic, geometry, and science concepts.\n* **Curiosity is key:** Encourage Luigi to ask \"why?\" and \"how?\". Foster his natural curiosity about how things work. Take things apart (safely!) and see how they're put together.\n\n**For older Luigi (6-12):**\n\n* **Explore different engineering disciplines:** There are many types of engineering (civil, mechanical, electrical, chemical, software, etc.). Expose him to different fields through books, videos, or even visits to engineering companies or museums.\n* **Get involved in STEM activities:** Look for robotics clubs, coding classes, science fairs, and other opportunities to apply his skills. YSC programs might be a great fit! (Check out our website for more information on programs and locations.)\n* **Develop strong problem-solving skills:** Engineering is all about solving problems. Encourage him to tackle challenges creatively and think critically. Chess is excellent for this!\n* **Start thinking about college and career prep:** He should begin to explore STEM-related courses in school. Consider summer camps or programs focusing on engineering.\n\n**Regardless of age:**\n\n* **Mentorship:** Finding a mentor who's an engineer can be invaluable. They can provide guidance, support, and real-world insights.\n* **Persistence is crucial:** Engineering can be challenging. Encourage him to persevere through difficulties and celebrate his successes along the way.\n* **Embrace teamwork:** Many engineering projects are collaborative efforts. Encourage participation in group projects and activities.\n\n\nLet me know if you have any other questions, Mario. We at YSC are here to support Luigi's journey into the world of engineering!\n"
}
]
},
{
"role": "user",
"parts": [
{
"text": "he wants to become a doctor"
}
]
},
{
"role": "model",
"parts": [
{
"text": "That's fantastic that Luigi is aiming to be a doctor! It's a noble and challenging profession requiring dedication and hard work. Here’s some advice tailored for his age group (assuming he's K-12):\n\n**For younger Luigi (K-5):**\n\n* **Cultivate a love of learning:** A strong foundation in science and math is essential. Make learning fun through games, books, and age-appropriate experiments.\n* **Develop strong communication skills:** Doctors need to communicate effectively with patients and colleagues. Encourage him to read, write, and express himself clearly.\n* **Build empathy and compassion:** A caring demeanor is crucial for a doctor. Encourage him to be kind, understanding, and show concern for others.\n\n\n**For older Luigi (6-12):**\n\n* **Focus on science and math:** Biology, chemistry, and physics are particularly important. Encourage participation in science clubs, fairs, and extracurricular activities related to these subjects.\n* **Shadowing or volunteering:** If possible, arrange for Luigi to shadow a doctor or volunteer at a hospital (with appropriate parental supervision and clearances). This will give him a realistic view of the profession.\n* **Research different medical fields:** Medicine is a broad field, encompassing many specialties. Encourage him to explore various options, such as pediatrics, cardiology, or surgery.\n* **Prepare for higher education:** A strong academic record in high school is essential for medical school. Encourage him to focus on his studies and maintain a good GPA.\n* **Explore relevant extracurricular activities:** Joining clubs related to science, debate, or community service can showcase his commitment and skills.\n\n\n**Regardless of age:**\n\n* **Develop strong problem-solving skills:** Doctors constantly face challenges and need to think critically to diagnose and treat patients. Encourage logical reasoning and creative problem-solving.\n* **Learn about medical ethics:** Understanding ethical principles is vital for responsible medical practice. Discuss scenarios involving ethical dilemmas and different perspectives.\n* **Maintain good health habits:** Doctors need to be healthy role models. Encourage him to prioritize physical activity, healthy eating, and sufficient rest.\n\n\nWhile YSC focuses on STEM through chess, the problem-solving and critical thinking skills developed through chess will still be beneficial for Luigi's aspirations. The key is to build a strong foundation in science and math, cultivate empathy, and work hard to achieve his goals. Good luck to Luigi! Let me know if you have other questions.\n"
}
]
},
{
"role": "user",
"parts": [
{
"text": "what was my name again?"
}
]
},
{
"role": "model",
"parts": [
{
"text": "Your name is Mario.\n"
}
]
}
]
211 changes: 211 additions & 0 deletions middlewareNode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions middlewareNode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "API for Y STEM And Chess Inc",
"main": "server.js",
"dependencies": {
"@google/genai": "^1.5.1",
"aws-sdk": "^2.889.0",
"axios": "^0.21.1",
"config": "^3.3.12",
Expand Down
4 changes: 2 additions & 2 deletions middlewareNode/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ router.post(
function (err, token) {
if (err) throw err;
res.json({ token });
},
}
);

return jwt; //Return the encrypted jwt
} catch (error) {
console.error(error.message);
res.status(500).send("Server error");
}
},
}
);

module.exports = router;
50 changes: 50 additions & 0 deletions middlewareNode/routes/geminiAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const express = require("express");
const router = express.Router();
const config = require("config");

router.post("/", async (req, res) => {
const { GoogleGenAI } = await import("@google/genai");
const GEMINI_API_KEY = config.get("geminiApiKey");
const { prompt, chatHistory } = req.body;

if (!prompt) return res.status(400).json({ error: "Prompt is required" });

try {
const ai = new GoogleGenAI({ apiKey: GEMINI_API_KEY });

const MAX_HISTORY_LENGTH = 12;
if (Array.isArray(chatHistory) && chatHistory.length > MAX_HISTORY_LENGTH) {
chatHistory = chatHistory.slice(-MAX_HISTORY_LENGTH);
}
else if (!Array.isArray(chatHistory)) {
chatHistory = [];
}
const systemInstruction = {
role: "user",
parts: [
{
text: `API (admin) Instructions:
You are a helpfull chatbot on a non-profit org called yStem and chess.
Y STEM and Chess Inc. (YSC) seeks to open the hearts and minds of kids (K-12) to the world of STEM through chess and the Mastery Learning approach to ensure learning and mastery of STEM-related principles. YSC strives to empower underserved and at-risk children through mentoring and STEM skills development to enable them to pursue STEM careers and change their life trajectories. You give advice to users on this site.

user prompt:`,
},
],
};
const contents = [systemInstruction, ...chatHistory];

const result = await ai.models.generateContent({
model: "gemini-1.5-flash",
contents: contents,
});
const modelReply = result.candidates[0].content.parts[0].text;
return res.json({ response: modelReply });
} catch (error) {
console.error("Gemini API Error:", error.response?.data || error.message);
return res
.status(500)
.json({ error: "Failed to get response from Gemini API" });
}
});

module.exports = router;
Loading