From fb3f44a912aa10158d380cedb84a69c9cb1aa116 Mon Sep 17 00:00:00 2001 From: forrest <398043641@qq.com> Date: Tue, 21 Jan 2025 11:54:25 +0800 Subject: [PATCH 1/3] feat: bots update api support updating knowledge base --- cozepy/__init__.py | 2 + cozepy/bots/__init__.py | 91 ++++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/cozepy/__init__.py b/cozepy/__init__.py index a3784b9..dd30bab 100644 --- a/cozepy/__init__.py +++ b/cozepy/__init__.py @@ -24,6 +24,7 @@ Bot, BotModelInfo, BotOnboardingInfo, + BotKnowledge, BotPluginAPIInfo, BotPluginInfo, BotPromptInfo, @@ -179,6 +180,7 @@ # bots "BotPromptInfo", "BotOnboardingInfo", + "BotKnowledge", "BotModelInfo", "BotPluginAPIInfo", "BotPluginInfo", diff --git a/cozepy/bots/__init__.py b/cozepy/bots/__init__.py index abb77c5..27c3902 100644 --- a/cozepy/bots/__init__.py +++ b/cozepy/bots/__init__.py @@ -20,6 +20,15 @@ class BotOnboardingInfo(CozeModel): suggested_questions: List[str] = [] +class BotKnowledge(CozeModel): + # Configured dataset ids of the bot. + dataset_ids: List[str] = [] + # Whether to call knowledge base automatically. + auto_call: bool = False + # Configured search strategy of the bot, values: 0: semantic search, 1: hybrid search, 20: full-text search. + search_strategy: int = 0 + + class BotModelInfo(CozeModel): # The ID of the model. model_id: str @@ -74,6 +83,8 @@ class Bot(CozeModel): prompt_info: Optional[BotPromptInfo] = None # The onboarding message configuration for the bot. For more information, see Onboarding object. onboarding_info: Optional[BotOnboardingInfo] = None + # The knowledge configuration for the bot. For more information, see Knowledge object. + knowledge: Optional[BotKnowledge] = None # The mode of the Bot, values: 0: Single Agent mode, 1: Multi Agent mode, 3: Single Agent Workflow mode. bot_mode: Optional[BotMode] = None # The plugins configured for the bot. For more information, see Plugin object. @@ -125,14 +136,14 @@ def __init__(self, base_url: str, auth: Auth, requester: Requester): self._requester = requester def create( - self, - *, - space_id: str, - name: str, - description: Optional[str] = None, - icon_file_id: Optional[str] = None, - prompt_info: Optional[BotPromptInfo] = None, - onboarding_info: Optional[BotOnboardingInfo] = None, + self, + *, + space_id: str, + name: str, + description: Optional[str] = None, + icon_file_id: Optional[str] = None, + prompt_info: Optional[BotPromptInfo] = None, + onboarding_info: Optional[BotOnboardingInfo] = None, ) -> Bot: url = f"{self._base_url}/v1/bot/create" body = { @@ -147,14 +158,15 @@ def create( return self._requester.request("post", url, False, Bot, body=body) def update( - self, - *, - bot_id: str, - name: Optional[str] = None, - description: Optional[str] = None, - icon_file_id: Optional[str] = None, - prompt_info: Optional[BotPromptInfo] = None, - onboarding_info: Optional[BotOnboardingInfo] = None, + self, + *, + bot_id: str, + name: Optional[str] = None, + description: Optional[str] = None, + icon_file_id: Optional[str] = None, + prompt_info: Optional[BotPromptInfo] = None, + onboarding_info: Optional[BotOnboardingInfo] = None, + knowledge: Optional[BotKnowledge] = None ) -> UpdateBotResp: """ Update the configuration of a bot. @@ -173,6 +185,7 @@ def update( file interface and obtain the file ID from the interface response. :param prompt_info: The personality and reply logic of the bot. :param onboarding_info: The settings related to the bot's opening remarks. + :param knowledge: The knowledge base that the bot uses to answer user queries. :return: None """ url = f"{self._base_url}/v1/bot/update" @@ -183,6 +196,7 @@ def update( "icon_file_id": icon_file_id, "prompt_info": prompt_info.model_dump() if prompt_info else None, "onboarding_info": onboarding_info.model_dump() if onboarding_info else None, + "knowledge": knowledge.model_dump() if knowledge else None, } return self._requester.request( @@ -277,14 +291,14 @@ def __init__(self, base_url: str, auth: Auth, requester: Requester): self._requester = requester async def create( - self, - *, - space_id: str, - name: str, - description: Optional[str] = None, - icon_file_id: Optional[str] = None, - prompt_info: Optional[BotPromptInfo] = None, - onboarding_info: Optional[BotOnboardingInfo] = None, + self, + *, + space_id: str, + name: str, + description: Optional[str] = None, + icon_file_id: Optional[str] = None, + prompt_info: Optional[BotPromptInfo] = None, + onboarding_info: Optional[BotOnboardingInfo] = None, ) -> Bot: url = f"{self._base_url}/v1/bot/create" body = { @@ -299,14 +313,15 @@ async def create( return await self._requester.arequest("post", url, False, Bot, body=body) async def update( - self, - *, - bot_id: str, - name: Optional[str] = None, - description: Optional[str] = None, - icon_file_id: Optional[str] = None, - prompt_info: Optional[BotPromptInfo] = None, - onboarding_info: Optional[BotOnboardingInfo] = None, + self, + *, + bot_id: str, + name: Optional[str] = None, + description: Optional[str] = None, + icon_file_id: Optional[str] = None, + prompt_info: Optional[BotPromptInfo] = None, + onboarding_info: Optional[BotOnboardingInfo] = None, + knowledge: Optional[BotKnowledge] = None ) -> UpdateBotResp: """ Update the configuration of a bot. @@ -325,6 +340,7 @@ async def update( file interface and obtain the file ID from the interface response. :param prompt_info: The personality and reply logic of the bot. :param onboarding_info: The settings related to the bot's opening remarks. + :param knowledge: The knowledge base that the bot uses to answer user queries. :return: None """ url = f"{self._base_url}/v1/bot/update" @@ -335,16 +351,17 @@ async def update( "icon_file_id": icon_file_id, "prompt_info": prompt_info.model_dump() if prompt_info else None, "onboarding_info": onboarding_info.model_dump() if onboarding_info else None, + "knowledge": knowledge.model_dump() if knowledge else None, } return await self._requester.arequest("post", url, False, cast=UpdateBotResp, body=body) async def publish( - self, - *, - bot_id: str, - connector_ids: Optional[List[str]] = None, - **kwargs, + self, + *, + bot_id: str, + connector_ids: Optional[List[str]] = None, + **kwargs, ) -> Bot: url = f"{self._base_url}/v1/bot/publish" headers: Optional[dict] = kwargs.get("headers") From 9cef61d8be5ef8a293723f6713b16462593b4748 Mon Sep 17 00:00:00 2001 From: forrest <398043641@qq.com> Date: Tue, 21 Jan 2025 12:02:06 +0800 Subject: [PATCH 2/3] feat: bots update api support updating knowledge base --- cozepy/bots/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cozepy/bots/__init__.py b/cozepy/bots/__init__.py index 27c3902..18f96d9 100644 --- a/cozepy/bots/__init__.py +++ b/cozepy/bots/__init__.py @@ -24,7 +24,7 @@ class BotKnowledge(CozeModel): # Configured dataset ids of the bot. dataset_ids: List[str] = [] # Whether to call knowledge base automatically. - auto_call: bool = False + auto_call: bool = True # Configured search strategy of the bot, values: 0: semantic search, 1: hybrid search, 20: full-text search. search_strategy: int = 0 From 289aba7eeee1c7bd16e069081621978ef6a8886d Mon Sep 17 00:00:00 2001 From: forrest <398043641@qq.com> Date: Wed, 22 Jan 2025 19:07:49 +0800 Subject: [PATCH 3/3] fix: resolve CI error caused by unsorted imports --- cozepy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cozepy/__init__.py b/cozepy/__init__.py index dd30bab..dc3c255 100644 --- a/cozepy/__init__.py +++ b/cozepy/__init__.py @@ -22,9 +22,9 @@ ) from .bots import ( Bot, + BotKnowledge, BotModelInfo, BotOnboardingInfo, - BotKnowledge, BotPluginAPIInfo, BotPluginInfo, BotPromptInfo,