MarkChenX's picture
Upload 12 files
d903cfe verified
raw
history blame
2.09 kB
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from database import post_github_access_token, post_github_repo, get_github_access_token
from cura import github_ingestion, vector_store
app = FastAPI(
title="Mindify Chat API",
description="API for Mindify Chat",
version="0.1"
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/github/access_token")
def post_github_access_token_route(token: str, user_email: str):
post_github_access_token(token, user_email)
return {"status": "success"}
@app.post("/github/repo")
def post_github_repo_route(repo_name: str, user_email: str):
post_github_repo(repo_name, user_email)
return {"status": "success"}
@app.post("/github/index")
def index_github_repo_route(repo_name: str, user_email: str):
access_token = get_github_access_token(user_email)
collection_name = repo_name.replace("/", "_")
if access_token is not None:
files = github_ingestion.ingest_github_repo(repo_name, access_token)
results = vector_store.index_vector_store(files=files, collection_name = collection_name)
if results:
return {"status": "success", "message": "GitHub data stored in ChromaDB"}
else:
return {"status": "error", "message": "Failed to set up ChromaDB collection"}
else:
return {"status": "error", "message": "Failed to get GitHub access token"}
@app.post("/github/query")
def query_github_repo_route(repo_name: str, query: str):
collection_name = repo_name.replace("/", "_")
if collection_name is not None:
response = vector_store.query_vector_store(collection_name=collection_name, query=query)
return {"status": "success", "response": response}
else:
return {"status": "error", "message": "Failed to set up ChromaDB collection"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app)