-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from ls1intum/integrate-kb-manager
Integrate kb manager
- Loading branch information
Showing
20 changed files
with
739 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
|
||
from fastapi import APIRouter, Depends | ||
|
||
from app.utils.dependencies import auth_handler, model | ||
from app.utils.environment import config | ||
|
||
|
||
admin_router = APIRouter(prefix="/api/admin", tags=["settings", "admin"], | ||
dependencies=[Depends(auth_handler.verify_token)]) | ||
|
||
@admin_router.get("/ping") | ||
async def ping(): | ||
logging.info(config.GPU_URL) | ||
return {"answer": "Server running."} | ||
|
||
|
||
@admin_router.get("/hi") | ||
async def ping(): | ||
logging.info("hi") | ||
return model.complete([{"role": "user", "content": "Hi"}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from typing import List | ||
from fastapi import HTTPException, APIRouter, status, Response, Depends | ||
from app.data.knowledge_base_requests import AddWebsiteRequest, EditDocumentRequest, EditSampleQuestionRequest, EditWebsiteRequest, AddDocumentRequest, AddSampleQuestionRequest, RefreshContentRequest | ||
from app.utils.dependencies import injestion_handler, auth_handler | ||
from app.data.database_requests import DatabaseDocumentMetadata | ||
|
||
knowledge_router = APIRouter(prefix="/api/knowledge", tags=["knowledge"]) | ||
|
||
@knowledge_router.post("/website/add", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def add_website(body: AddWebsiteRequest): | ||
try: | ||
injestion_handler.add_website(body) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/website/addBatch", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def add_websites(body: List[AddWebsiteRequest]): | ||
try: | ||
injestion_handler.add_websites(body) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/website/{id}/refresh", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def refresh_website(id: str, body: RefreshContentRequest): | ||
try: | ||
injestion_handler.refresh_content(id=id, content=body.content) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/website/{id}/update", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def update_website(id: str, body: EditWebsiteRequest): | ||
try: | ||
metadata: DatabaseDocumentMetadata = DatabaseDocumentMetadata( | ||
study_programs=body.studyPrograms | ||
) | ||
injestion_handler.update_database_document(id=id, metadata=metadata) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.delete("/website/{id}/delete", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def delete_website(id: str): | ||
try: | ||
injestion_handler.delete_document(id=id) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
|
||
# === Document Endpoints === | ||
|
||
@knowledge_router.post("/document/add", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def add_document(body: AddDocumentRequest): | ||
try: | ||
injestion_handler.add_document(body) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/sample-question/addBatch", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def add_sample_questions(body: List[AddSampleQuestionRequest]): | ||
try: | ||
injestion_handler.add_sample_questions(body) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/document/{id}/refresh", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def refresh_document(id: str, body: RefreshContentRequest): | ||
try: | ||
injestion_handler.refresh_content(id=id, content=body.content) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/document/{id}/edit", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def edit_document(id: str, body: EditDocumentRequest): | ||
try: | ||
metadata: DatabaseDocumentMetadata = DatabaseDocumentMetadata( | ||
study_programs=body.studyPrograms | ||
) | ||
injestion_handler.update_database_document(id=id, metadata=metadata) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.delete("/document/{id}/delete", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def delete_document(id: str): | ||
try: | ||
injestion_handler.delete_document(id=id) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
|
||
# === Sample Question Endpoints === | ||
|
||
@knowledge_router.post("/sample-question/add", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def add_sample_question(body: AddSampleQuestionRequest): | ||
try: | ||
injestion_handler.add_sample_question(sample_question=body) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.post("/sample-question/{id}/edit", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def edit_sample_question(id: str, body: EditSampleQuestionRequest): | ||
try: | ||
injestion_handler.update_sample_question(kb_id=id, sample_question=body) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) | ||
|
||
@knowledge_router.delete("/sample-question/{id}/delete", dependencies=[Depends(auth_handler.verify_api_key)]) | ||
async def delete_sample_question(id: str): | ||
try: | ||
injestion_handler.delete_sample_question(id=id) | ||
return Response(status_code=200) | ||
except Exception as e: | ||
return Response(status_code=500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pydantic import BaseModel | ||
from typing import List, Optional | ||
|
||
class DatabaseDocument(BaseModel): | ||
id: str | ||
link: Optional[str] = None | ||
study_programs: List[str] | ||
content: str | ||
org_id: int | ||
|
||
class DatabaseDocumentMetadata(BaseModel): | ||
link: Optional[str] = None | ||
study_programs: List[str] | ||
org_id: int | ||
|
||
class DatabaseSampleQuestion(BaseModel): | ||
id: str | ||
topic: str | ||
question: str | ||
answer: str | ||
study_programs: List[str] | ||
org_id: int | ||
|
||
class SampleQuestion(BaseModel): | ||
topic: str | ||
question: str | ||
answer: str | ||
study_programs: List[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pydantic import BaseModel | ||
from typing import List | ||
|
||
|
||
class AddWebsiteRequest(BaseModel): | ||
id: str | ||
orgId: int | ||
title: str | ||
link: str | ||
studyPrograms: List[str] | ||
content: str | ||
type: str | ||
|
||
class RefreshContentRequest(BaseModel): | ||
content: str | ||
|
||
class EditWebsiteRequest(BaseModel): | ||
title: str | ||
studyPrograms: List[str] | ||
|
||
class AddDocumentRequest(BaseModel): | ||
id: str | ||
orgId: int | ||
title: str | ||
studyPrograms: List[str] | ||
content: str | ||
|
||
class EditDocumentRequest(BaseModel): | ||
title: str | ||
studyPrograms: List[str] | ||
|
||
class AddSampleQuestionRequest(BaseModel): | ||
id: str | ||
orgId: int | ||
question: str | ||
answer: str | ||
topic: str | ||
studyPrograms: List[str] | ||
|
||
class EditSampleQuestionRequest(BaseModel): | ||
question: str | ||
answer: str | ||
topic: str | ||
studyPrograms: List[str] | ||
orgId: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.