From fc848b377458dd74320a0b0755bea08850dc9cd1 Mon Sep 17 00:00:00 2001 From: userpj Date: Tue, 25 Feb 2025 18:46:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A5=E8=AF=86=E5=BA=93=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E7=BD=91=E9=A1=B5=E6=95=B0=E6=8D=AE=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=9B=B4=E6=96=B0=E9=A2=91=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Platform/KnowledgeBase/knowledgebase.md | 8 +++++ go/appbuilder/knowledge_base_data.go | 11 +++++-- go/appbuilder/knowledge_base_test.go | 5 +++ .../knowledgebase/DocumentsCreateRequest.java | 32 +++++++++++++++++++ .../appbuilder/KnowledgebaseTest.java | 3 +- python/__init__.py | 3 +- .../core/console/knowledge_base/__init__.py | 1 + .../core/console/knowledge_base/data_class.py | 8 +++++ python/tests/test_knowledge_base.py | 1 + 9 files changed, 67 insertions(+), 5 deletions(-) diff --git a/docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md b/docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md index fdd439a51..ddbad9a5d 100644 --- a/docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md +++ b/docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md @@ -301,10 +301,17 @@ knowledge.delete_knowledge_base("da51a988-cbe7-4b24-aa5b-768985e8xxxx") `DocumentSource`类定义如下: ```python +class DocumentSourceUrlConfig(BaseModel): + frequency: int = Field( + ..., + description="更新频率,目前支持的更新频率为-1(不自动更新),1(每天),3(每3天),7(每7天),30(每30天)。", + ) + class DocumentSource(BaseModel): type: str = Field(..., description="数据来源类型", enum=["bos", "web"]) urls: list[str] = Field(None, description="文档URL") urlDepth: int = Field(None, description="url下钻深度,1时不下钻") + urlConfigs: Optional[list[DocumentSourceUrlConfig]] = Field(None, description="该字段的长度需要和source、urls字段长度保持一致。") ``` `DocumentProcessOption`类及衍生类定义如下: @@ -364,6 +371,7 @@ knowledge.create_documents( type="web", urls=["https://baijiahao.baidu.com/s?id=1802527379394162441"], urlDepth=1, + urlConfigs=[appbuilder.DocumentSourceUrlConfig(frequency=1)] ), processOption=appbuilder.DocumentProcessOption( template="custom", diff --git a/go/appbuilder/knowledge_base_data.go b/go/appbuilder/knowledge_base_data.go index ecbe1690f..e65e6e54a 100644 --- a/go/appbuilder/knowledge_base_data.go +++ b/go/appbuilder/knowledge_base_data.go @@ -145,10 +145,15 @@ type GetKnowledgeBaseListResponse struct { MaxKeys int `json:"maxKeys"` } +type DocumentsSourceUrlConfig struct { + Frequency int `json:"frequency"` +} + type DocumentsSource struct { - Type string `json:"type"` - Urls []string `json:"urls,omitempty"` - UrlDepth int `json:"url_depth,omitempty"` + Type string `json:"type"` + Urls []string `json:"urls,omitempty"` + UrlDepth int `json:"url_depth,omitempty"` + UrlConfigs *[]DocumentsSourceUrlConfig `json:"url_configs,omitempty"` } type DocumentsProcessOptionParser struct { diff --git a/go/appbuilder/knowledge_base_test.go b/go/appbuilder/knowledge_base_test.go index ada987bc6..ea52fd726 100644 --- a/go/appbuilder/knowledge_base_test.go +++ b/go/appbuilder/knowledge_base_test.go @@ -1245,6 +1245,11 @@ func TestCreateKnowledgeBase(t *testing.T) { Type: "web", Urls: []string{"https://baijiahao.baidu.com/s?id=1802527379394162441"}, UrlDepth: 1, + UrlConfigs: &[]DocumentsSourceUrlConfig{ + { + Frequency: 1, + }, + }, }, ProcessOption: &DocumentsProcessOption{ Template: "custom", diff --git a/java/src/main/java/com/baidubce/appbuilder/model/knowledgebase/DocumentsCreateRequest.java b/java/src/main/java/com/baidubce/appbuilder/model/knowledgebase/DocumentsCreateRequest.java index 893a0e56e..d65f9914b 100644 --- a/java/src/main/java/com/baidubce/appbuilder/model/knowledgebase/DocumentsCreateRequest.java +++ b/java/src/main/java/com/baidubce/appbuilder/model/knowledgebase/DocumentsCreateRequest.java @@ -37,6 +37,7 @@ public static class Source { private String type; private String[] urls; private Integer urlDepth; + private UrlConfig[] urlConfigs; public Source(String type, String[] urls, Integer urlDepth) { this.type = type; @@ -44,6 +45,13 @@ public Source(String type, String[] urls, Integer urlDepth) { this.urlDepth = urlDepth; } + public Source(String type, String[] urls, Integer urlDepth, UrlConfig[] urlConfigs) { + this.type = type; + this.urls = urls; + this.urlDepth = urlDepth; + this.urlConfigs = urlConfigs; + } + public String getType() { return type; } @@ -55,6 +63,30 @@ public String[] getUrls() { public Integer getUrlDepth() { return urlDepth; } + + public UrlConfig[] getUrlConfigs() { + return urlConfigs; + } + + public void setUrlConfigs(UrlConfig[] urlConfigs) { + this.urlConfigs = urlConfigs; + } + + public static class UrlConfig { + private Integer frequency; + + public UrlConfig(Integer frequency) { + this.frequency = frequency; + } + + public Integer getFrequency() { + return frequency; + } + + public void setFrequency(Integer frequency) { + this.frequency = frequency; + } + } } public static class ProcessOption { diff --git a/java/src/test/java/com/baidubce/appbuilder/KnowledgebaseTest.java b/java/src/test/java/com/baidubce/appbuilder/KnowledgebaseTest.java index 06125ba10..b077d8843 100644 --- a/java/src/test/java/com/baidubce/appbuilder/KnowledgebaseTest.java +++ b/java/src/test/java/com/baidubce/appbuilder/KnowledgebaseTest.java @@ -108,8 +108,9 @@ public void testCreateKnowledgebase() throws IOException, AppBuilderServerExcept knowledgebase.modifyKnowledgeBase(modifyRequest); // 导入知识库 + DocumentsCreateRequest.Source.UrlConfig[] urlConfigs = {new DocumentsCreateRequest.Source.UrlConfig(1)}; DocumentsCreateRequest.Source source = new DocumentsCreateRequest.Source("web", - new String[] {"https://baijiahao.baidu.com/s?id=1802527379394162441"}, 1); + new String[] {"https://baijiahao.baidu.com/s?id=1802527379394162441"}, 1, urlConfigs); DocumentsCreateRequest.ProcessOption.Parser parser = new DocumentsCreateRequest.ProcessOption.Parser( new String[] {"layoutAnalysis", "ocr"}); diff --git a/python/__init__.py b/python/__init__.py index f146594c6..412259c95 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -183,7 +183,7 @@ def get_default_header(): from appbuilder.core.console.appbuilder_client.appbuilder_client import get_app_list, get_all_apps, describe_apps from appbuilder.core.console.component_client.component_client import ComponentClient from appbuilder.core.console.knowledge_base.knowledge_base import KnowledgeBase -from appbuilder.core.console.knowledge_base.data_class import CustomProcessRule, DocumentSource, DocumentChoices, DocumentChunker, DocumentSeparator, DocumentPattern, DocumentProcessOption +from appbuilder.core.console.knowledge_base.data_class import CustomProcessRule, DocumentSource, DocumentChoices, DocumentChunker, DocumentSeparator, DocumentPattern, DocumentProcessOption, DocumentSourceUrlConfig from .core._exception import ( BadRequestException, @@ -234,6 +234,7 @@ def get_default_header(): "DocumentSeparator", "DocumentPattern", "DocumentProcessOption", + "DocumentSourceUrlConfig" "assistant", "StreamRunContext", "AssistantEventHandler", diff --git a/python/core/console/knowledge_base/__init__.py b/python/core/console/knowledge_base/__init__.py index 26c368e90..6eb83345e 100644 --- a/python/core/console/knowledge_base/__init__.py +++ b/python/core/console/knowledge_base/__init__.py @@ -16,6 +16,7 @@ from .data_class import ( CustomProcessRule, DocumentSource, + DocumentSourceUrlConfig, DocumentProcessOption, DocumentChoices, DocumentSeparator, diff --git a/python/core/console/knowledge_base/data_class.py b/python/core/console/knowledge_base/data_class.py index de1dc8022..43be0f379 100644 --- a/python/core/console/knowledge_base/data_class.py +++ b/python/core/console/knowledge_base/data_class.py @@ -171,10 +171,18 @@ class KnowledgeBaseGetListResponse(BaseModel): isTruncated: bool = Field(..., description="是否有更多结果") +class DocumentSourceUrlConfig(BaseModel): + frequency: int = Field( + ..., + description="更新频率,目前支持的更新频率为-1(不自动更新),1(每天),3(每3天),7(每7天),30(每30天)。", + ) + + class DocumentSource(BaseModel): type: str = Field(..., description="数据来源类型", enum=["bos", "web"]) urls: list[str] = Field(None, description="文档URL") urlDepth: int = Field(None, description="url下钻深度,1时不下钻") + urlConfigs: Optional[list[DocumentSourceUrlConfig]] = Field(None, description="该字段的长度需要和source、urls字段长度保持一致。") class DocumentChoices(BaseModel): diff --git a/python/tests/test_knowledge_base.py b/python/tests/test_knowledge_base.py index 078b0e8ea..c871de513 100644 --- a/python/tests/test_knowledge_base.py +++ b/python/tests/test_knowledge_base.py @@ -84,6 +84,7 @@ def test_create_knowledge_base(self): type="web", urls=["https://baijiahao.baidu.com/s?id=1802527379394162441"], urlDepth=1, + urlConfigs=[appbuilder.DocumentSourceUrlConfig(frequency=1)] ), processOption=appbuilder.DocumentProcessOption( template="custom",