mirror of
https://github.com/PlatypusPus/MushroomEmpire.git
synced 2026-02-07 22:18:59 +00:00
Merge branch 'PlatypusPus:main' into main
This commit is contained in:
47
api/routers/chatbot.py
Normal file
47
api/routers/chatbot.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import ollama
|
||||||
|
import chromadb
|
||||||
|
from pypdf import PdfReader
|
||||||
|
from fastapi import FastAPI
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
client = chromadb.Client()
|
||||||
|
collection = client.create_collection(name="docs")
|
||||||
|
|
||||||
|
reader = PdfReader('../../GDPRArticles.pdf')
|
||||||
|
chunks = [page.extract_text().strip() for page in reader.pages if page.extract_text().strip()]
|
||||||
|
print("Done reading pages!")
|
||||||
|
for i, chunk in enumerate(chunks):
|
||||||
|
response = ollama.embed(model="nomic-embed-text", input=chunk)
|
||||||
|
embedding = response["embeddings"][0]
|
||||||
|
collection.add(
|
||||||
|
ids=[str(i)],
|
||||||
|
embeddings=[embedding],
|
||||||
|
documents=[chunk]
|
||||||
|
)
|
||||||
|
print("Embeddings done!")
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
@app.post("/chat")
|
||||||
|
async def chat_bot(prompt: str):
|
||||||
|
if not prompt:
|
||||||
|
return
|
||||||
|
query = prompt
|
||||||
|
response = ollama.embed(model="nomic-embed-text", input=query)
|
||||||
|
query_embedding = response["embeddings"][0]
|
||||||
|
|
||||||
|
results = collection.query(
|
||||||
|
query_embeddings=[query_embedding],
|
||||||
|
n_results=1
|
||||||
|
)
|
||||||
|
data = results['documents'][0][0]
|
||||||
|
|
||||||
|
output = ollama.generate(
|
||||||
|
model="llama3.2",
|
||||||
|
prompt=f"Context: {data}\n\nQuestion: {query}\n\nAnswer:"
|
||||||
|
)
|
||||||
|
return {"response": output["response"]}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
uvicorn.run(app, port=8080, host='0.0.0.0')
|
||||||
@@ -1,23 +1,15 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { useEffect, useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export function Navbar() {
|
export function Navbar() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const onTry = pathname?.startsWith('/try');
|
const onTry = pathname?.startsWith('/try');
|
||||||
const [scrolled, setScrolled] = useState(false);
|
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const onScroll = () => setScrolled(window.scrollY > 4);
|
|
||||||
onScroll();
|
|
||||||
window.addEventListener('scroll', onScroll, { passive: true });
|
|
||||||
return () => window.removeEventListener('scroll', onScroll);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className={`w-full sticky top-0 z-50 transition-colors ${scrolled ? 'bg-white/90 border-b border-slate-200/70 shadow-sm' : 'bg-white/70 border-b border-transparent'}`}>
|
<nav className={`w-full sticky top-0 z-50 bg-white border-b border-slate-200 shadow-md`}>
|
||||||
<div className="container-max flex items-center justify-between h-16">
|
<div className="container-max flex items-center justify-between h-16">
|
||||||
<Link href="/" className="font-semibold text-brand-700 text-lg tracking-tight">Nordic Privacy AI</Link>
|
<Link href="/" className="font-semibold text-brand-700 text-lg tracking-tight">Nordic Privacy AI</Link>
|
||||||
{/* Desktop nav */}
|
{/* Desktop nav */}
|
||||||
|
|||||||
Reference in New Issue
Block a user