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
38 changes: 38 additions & 0 deletions SmartNotes-AI/SmartNotes-AI/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const express = require("express");
const app = express();

app.use(express.json());
app.use(express.static(__dirname));

// Notes
const notes = [
{ title: "Meeting", content: "Met German company in 2020" },
{ title: "Tasks", content: "Website redesign tasks list" },
{ title: "Poem", content: "Moon shines in the dark night" }
];

app.post("/ask", (req, res) => {
console.log("API RUNNING 🔥");

const query = req.body.query.toLowerCase();

const results = notes.filter(note =>
query.split(" ").some(word =>
note.content.toLowerCase().includes(word)
)
);

if (results.length === 0) {
return res.json([{ content: "No results found" }]);
}

const answer = results.map(n =>
`Based on your notes: ${n.content}`
).join("\n");

res.json([{ content: answer }]);
});

app.listen(3000, () => {
console.log("Server started on http://localhost:3000");
});
33 changes: 33 additions & 0 deletions SmartNotes-AI/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<body>

<h2>Test Chat</h2>

<input id="query" placeholder="type anything">
<button onclick="send()">Send</button>

<p id="res"></p>

<script>
function send() {
console.log("Clicked");

fetch("http://localhost:3000/ask", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({query: "hi"})
})
.then(r => r.json())
.then(d => {
document.getElementById("res").innerText = d[0].content;
})
.catch(e => {
console.log(e);
document.getElementById("res").innerText = "Error";
});
}
</script>

</body>
</html>