Spaces:
Sleeping
Sleeping
| __import__('pysqlite3') | |
| import sys | |
| sys.modules['sqlite3'] = sys.modules.pop('pysqlite3') | |
| from fastapi import FastAPI, Form | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from .cura import github_ingestion, vector_store, chatbot | |
| 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=["*"], | |
| ) | |
| def read_root(): | |
| return {"Hello": "World"} | |
| def query_chat_route(query: str = Form(...), repo_name: str = Form(...), token: str = Form(...)): | |
| collection_name = repo_name.replace("/", "_") | |
| if repo_name: | |
| files = github_ingestion.ingest_github_repo(repo_name=repo_name, access_token=token) | |
| collection = vector_store.index_vector_store_chroma(collection_name=collection_name, files=files) | |
| if collection != None: | |
| query = vector_store.query_vector_store_chroma(collection=collection, query=query) | |
| else: | |
| print("No repo name provided. Using default collection.") | |
| query = chatbot.ask_question(query=query) | |
| return {"status": "success", "response": query} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app) | |