-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description - Refactor knowledge to a module - This PR breaks the Github Processor function -> need to comment brain and file imports as it creates a circular dependency issue. Should be fixed and reverted in next PR.
- Loading branch information
Showing
27 changed files
with
186 additions
and
162 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
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
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
File renamed without changes.
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 @@ | ||
from .knowledge_routes import knowledge_router |
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,2 @@ | ||
from .inputs import CreateKnowledgeProperties | ||
from .outputs import DeleteKnowledgeResponse |
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,16 @@ | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class CreateKnowledgeProperties(BaseModel): | ||
brain_id: UUID | ||
file_name: Optional[str] = None | ||
url: Optional[str] = None | ||
extension: str = "txt" | ||
|
||
def dict(self, *args, **kwargs): | ||
knowledge_dict = super().dict(*args, **kwargs) | ||
knowledge_dict["brain_id"] = str(knowledge_dict.get("brain_id")) | ||
return knowledge_dict |
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,8 @@ | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class DeleteKnowledgeResponse(BaseModel): | ||
status: str = "delete" | ||
knowledge_id: UUID |
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 @@ | ||
from .knowledge import Knowledge |
File renamed without changes.
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 @@ | ||
from .knowledges import Knowledges |
58 changes: 58 additions & 0 deletions
58
backend/modules/knowledge/repository/knowledge_interface.py
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,58 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List | ||
from uuid import UUID | ||
|
||
from modules.knowledge.dto.inputs import CreateKnowledgeProperties | ||
from modules.knowledge.dto.outputs import DeleteKnowledgeResponse | ||
from modules.knowledge.entity.knowledge import Knowledge | ||
|
||
|
||
class KnowledgeInterface(ABC): | ||
@abstractmethod | ||
def insert_knowledge(self, knowledge: CreateKnowledgeProperties) -> Knowledge: | ||
""" | ||
Add a knowledge | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def remove_knowledge_by_id( | ||
# todo: update remove brain endpoints to first delete the knowledge | ||
self, | ||
knowledge_id: UUID, | ||
) -> DeleteKnowledgeResponse: | ||
""" | ||
Args: | ||
knowledge_id (UUID): The id of the knowledge | ||
Returns: | ||
str: Status message | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def get_knowledge_by_id(self, knowledge_id: UUID) -> Knowledge: | ||
""" | ||
Get a knowledge by its id | ||
Args: | ||
brain_id (UUID): The id of the brain | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def get_all_knowledge_in_brain(self, brain_id: UUID) -> List[Knowledge]: | ||
""" | ||
Get all the knowledge in a brain | ||
Args: | ||
brain_id (UUID): The id of the brain | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def remove_brain_all_knowledge(self, brain_id: UUID) -> None: | ||
""" | ||
Remove all knowledge in a brain | ||
Args: | ||
brain_id (UUID): The id of the brain | ||
""" | ||
pass |
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.
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,46 @@ | ||
from uuid import UUID | ||
|
||
from logger import get_logger | ||
from modules.knowledge.dto.inputs import CreateKnowledgeProperties | ||
from modules.knowledge.entity.knowledge import Knowledge | ||
from modules.knowledge.repository.knowledge_interface import KnowledgeInterface | ||
from modules.knowledge.repository.knowledges import Knowledges | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class KnowledgeService: | ||
repository: KnowledgeInterface | ||
|
||
def __init__(self): | ||
self.repository = Knowledges() | ||
|
||
def add_knowledge(self, knowledge_to_add: CreateKnowledgeProperties): | ||
knowledge = self.repository.insert_knowledge(knowledge_to_add) | ||
|
||
logger.info(f"Knowledge { knowledge.id} added successfully") | ||
return knowledge | ||
|
||
def get_all_knowledge(self, brain_id: UUID): | ||
knowledges = self.repository.get_all_knowledge_in_brain(brain_id) | ||
|
||
return knowledges | ||
|
||
def get_knowledge(self, knowledge_id: UUID) -> Knowledge: | ||
knowledge = self.repository.get_knowledge_by_id(knowledge_id) | ||
|
||
return knowledge | ||
|
||
def remove_brain_all_knowledge(self, brain_id: UUID) -> None: | ||
self.repository.remove_brain_all_knowledge(brain_id) | ||
|
||
logger.info( | ||
f"All knowledge in brain {brain_id} removed successfully from table" | ||
) | ||
|
||
def remove_knowledge(self, knowledge_id: UUID): | ||
message = self.repository.remove_knowledge_by_id(knowledge_id) | ||
|
||
logger.info(f"Knowledge { knowledge_id} removed successfully from table") | ||
|
||
return message |
Oops, something went wrong.