chore: Add pylint for DB-GPT rag lib (#1267)

This commit is contained in:
Fangyin Cheng
2024-03-07 23:27:43 +08:00
committed by GitHub
parent aaaf34db17
commit 7446817340
70 changed files with 1135 additions and 587 deletions

View File

@@ -1,3 +1,4 @@
"""String Knowledge."""
from typing import Any, List, Optional
from dbgpt.rag.chunk import Document
@@ -5,22 +6,23 @@ from dbgpt.rag.knowledge.base import ChunkStrategy, Knowledge, KnowledgeType
class StringKnowledge(Knowledge):
"""String Knowledge"""
"""String Knowledge."""
def __init__(
self,
text: str = None,
text: str = "",
knowledge_type: KnowledgeType = KnowledgeType.TEXT,
encoding: Optional[str] = "utf-8",
loader: Optional[Any] = None,
**kwargs: Any,
) -> None:
"""Initialize with Knowledge arguments.
"""Create String knowledge parameters.
Args:
text:(str) text
knowledge_type:(KnowledgeType) knowledge type
encoding:(encoding) csv encoding
loader:(loader) loader
text(str): text
knowledge_type(KnowledgeType): knowledge type
encoding(str): encoding
loader(Any): loader
"""
self._text = text
self._type = knowledge_type
@@ -28,21 +30,25 @@ class StringKnowledge(Knowledge):
self._encoding = encoding
def _load(self) -> List[Document]:
"""load raw text from loader"""
"""Load raw text from loader."""
metadata = {"source": "raw text"}
docs = [Document(content=self._text, metadata=metadata)]
return docs
@classmethod
def support_chunk_strategy(cls) -> List[ChunkStrategy]:
"""Return support chunk strategy."""
return [
ChunkStrategy.CHUNK_BY_SIZE,
ChunkStrategy.CHUNK_BY_SEPARATOR,
]
@classmethod
def default_chunk_strategy(cls) -> ChunkStrategy:
"""Return default chunk strategy."""
return ChunkStrategy.CHUNK_BY_SIZE
@classmethod
def type(cls):
"""Return knowledge type."""
return KnowledgeType.TEXT