mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-15 05:59:59 +00:00
chore: Add pylint for DB-GPT rag lib (#1267)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
"""TXT Knowledge."""
|
||||
from typing import Any, List, Optional
|
||||
|
||||
import chardet
|
||||
@@ -12,7 +13,7 @@ from dbgpt.rag.knowledge.base import (
|
||||
|
||||
|
||||
class TXTKnowledge(Knowledge):
|
||||
"""TXT Knowledge"""
|
||||
"""TXT Knowledge."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -21,21 +22,24 @@ class TXTKnowledge(Knowledge):
|
||||
loader: Optional[Any] = None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Initialize with Knowledge arguments.
|
||||
"""Create TXT Knowledge with Knowledge arguments.
|
||||
|
||||
Args:
|
||||
file_path:(Optional[str]) file path
|
||||
knowledge_type:(KnowledgeType) knowledge type
|
||||
loader:(Optional[Any]) loader
|
||||
file_path(str, optional): file path
|
||||
knowledge_type(KnowledgeType, optional): knowledge type
|
||||
loader(Any, optional): loader
|
||||
"""
|
||||
self._path = file_path
|
||||
self._type = knowledge_type
|
||||
self._loader = loader
|
||||
|
||||
def _load(self) -> List[Document]:
|
||||
"""Load txt document from loader"""
|
||||
"""Load txt document from loader."""
|
||||
if self._loader:
|
||||
documents = self._loader.load()
|
||||
else:
|
||||
if not self._path:
|
||||
raise ValueError("file path is required")
|
||||
with open(self._path, "rb") as f:
|
||||
raw_text = f.read()
|
||||
result = chardet.detect(raw_text)
|
||||
@@ -50,6 +54,7 @@ class TXTKnowledge(Knowledge):
|
||||
|
||||
@classmethod
|
||||
def support_chunk_strategy(cls):
|
||||
"""Return support chunk strategy."""
|
||||
return [
|
||||
ChunkStrategy.CHUNK_BY_SIZE,
|
||||
ChunkStrategy.CHUNK_BY_SEPARATOR,
|
||||
@@ -57,12 +62,15 @@ class TXTKnowledge(Knowledge):
|
||||
|
||||
@classmethod
|
||||
def default_chunk_strategy(cls) -> ChunkStrategy:
|
||||
"""Return default chunk strategy."""
|
||||
return ChunkStrategy.CHUNK_BY_SIZE
|
||||
|
||||
@classmethod
|
||||
def type(cls) -> KnowledgeType:
|
||||
"""Return knowledge type."""
|
||||
return KnowledgeType.DOCUMENT
|
||||
|
||||
@classmethod
|
||||
def document_type(cls) -> DocumentType:
|
||||
"""Return document type."""
|
||||
return DocumentType.TXT
|
||||
|
Reference in New Issue
Block a user