mirror of
https://github.com/PlatypusPus/MushroomEmpire.git
synced 2026-02-07 22:18:59 +00:00
Merge branch 'main' of https://github.com/PlatypusPus/MushroomEmpire
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import ollama
|
||||
import chromadb
|
||||
from pypdf import PdfReader
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
import uvicorn
|
||||
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -34,11 +36,24 @@ for i, chunk in enumerate(chunks):
|
||||
print("Embeddings done!")
|
||||
|
||||
|
||||
# Allow browser calls from the frontend
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
class ChatRequest(BaseModel):
|
||||
prompt: str
|
||||
|
||||
@app.post("/chat")
|
||||
async def chat_bot(prompt: str):
|
||||
if not prompt:
|
||||
return
|
||||
query = prompt
|
||||
async def chat_bot(prompt: str | None = None, body: ChatRequest | None = None):
|
||||
# Accept prompt from either query (?prompt=) or JSON body {"prompt": "..."}
|
||||
query = prompt or (body.prompt if body else None)
|
||||
if not query:
|
||||
raise HTTPException(status_code=400, detail="Missing prompt")
|
||||
response = ollama.embed(model="nomic-embed-text", input=query)
|
||||
query_embedding = response["embeddings"][0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user