File size: 1,306 Bytes
4050a2c
 
 
eff3dbb
1585a60
d903cfe
9a4ed83
d903cfe
 
1585a60
d903cfe
 
 
 
 
 
 
1585a60
d903cfe
 
1a736cb
d903cfe
 
 
 
1585a60
 
d903cfe
1585a60
 
49f53de
eff3dbb
1585a60
d903cfe
1585a60
 
 
 
 
49f53de
d903cfe
 
1585a60
d903cfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
__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=["*"],
)


@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.post("/chat/query")
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)