Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
userpj committed Jul 22, 2024
1 parent 8abe0c0 commit 5ad769d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
4 changes: 2 additions & 2 deletions appbuilder/core/console/knowledge_base/data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class KnowledgeBaseGetDocumentsListRequest(BaseModel):


class DocumentMeta(BaseModel):
source: str = Field(None, description="文档来源")
file_id: str = Field(None, description="文档对应的文件ID")
source: Optional[str] = Field(None, description="文档来源")
file_id: Optional[str] = Field(None, description="文档对应的文件ID")


class Document(BaseModel):
Expand Down
86 changes: 46 additions & 40 deletions appbuilder/tests/test_knowledge_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,58 +60,64 @@ def test_create_knowledge_base(self):
knowledge_base_id = resp.id
knowledge.get_knowledge_base_detail(knowledge_base_id)
knowledge.get_knowledge_base_list(knowledge_base_id, maxKeys=10)
knowledge.create_documents(
id=knowledge_base_id,
contentFormat="rawText",
source=appbuilder.DocumentSource(
type="web",
urls=["https://baijiahao.baidu.com/s?id=1802527379394162441"],
urlDepth=1,
),
processOption=appbuilder.DocumentProcessOption(
template="custom",
parser=appbuilder.DocumentChoices(choices=["layoutAnalysis", "ocr"]),
chunker=appbuilder.DocumentChunker(
choices=["separator"],
separator=appbuilder.DocumentSeparator(
separators=["。"],
targetLength=300,
overlapRate=0.25,

try:
knowledge.create_documents(
id=knowledge_base_id,
contentFormat="rawText",
source=appbuilder.DocumentSource(
type="web",
urls=["https://baijiahao.baidu.com/s?id=1802527379394162441"],
urlDepth=1,
),
processOption=appbuilder.DocumentProcessOption(
template="custom",
parser=appbuilder.DocumentChoices(
choices=["layoutAnalysis", "ocr"]
),
prependInfo=["title", "filename"],
chunker=appbuilder.DocumentChunker(
choices=["separator"],
separator=appbuilder.DocumentSeparator(
separators=["。"],
targetLength=300,
overlapRate=0.25,
),
prependInfo=["title", "filename"],
),
knowledgeAugmentation=appbuilder.DocumentChoices(choices=["faq"]),
),
knowledgeAugmentation=appbuilder.DocumentChoices(choices=["faq"]),
),
)
)

knowledge.upload_documents(
id=knowledge_base_id,
content_format="rawText",
file_path="./data/qa_appbuilder_client_demo.pdf",
processOption=appbuilder.DocumentProcessOption(
template="custom",
parser=appbuilder.DocumentChoices(choices=["layoutAnalysis", "ocr"]),
chunker=appbuilder.DocumentChunker(
choices=["separator"],
separator=appbuilder.DocumentSeparator(
separators=["。"],
targetLength=300,
overlapRate=0.25,
knowledge.upload_documents(
id=knowledge_base_id,
content_format="rawText",
file_path="./data/qa_appbuilder_client_demo.pdf",
processOption=appbuilder.DocumentProcessOption(
template="custom",
parser=appbuilder.DocumentChoices(
choices=["layoutAnalysis", "ocr"]
),
chunker=appbuilder.DocumentChunker(
choices=["separator"],
separator=appbuilder.DocumentSeparator(
separators=["。"],
targetLength=300,
overlapRate=0.25,
),
prependInfo=["title", "filename"],
),
prependInfo=["title", "filename"],
knowledgeAugmentation=appbuilder.DocumentChoices(choices=["faq"]),
),
knowledgeAugmentation=appbuilder.DocumentChoices(choices=["faq"]),
),
)
)

try:
list_res = knowledge.get_documents_list()
document_id = list_res.data[-1].id
res = knowledge.describe_chunks(document_id)
knowledge.describe_chunk(res.data[0].id)
resp = knowledge.create_chunk(document_id, content="test")
chunk_id = resp.id
knowledge.modify_chunk(chunk_id, content="new test", enable=True)
time.sleep(1)
knowledge.describe_chunk(chunk_id)
knowledge.delete_chunk(chunk_id)

knowledge.modify_knowledge_base(
Expand Down

0 comments on commit 5ad769d

Please sign in to comment.