Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bot update api supports modifying dataset #174

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cozepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from .bots import (
Bot,
BotKnowledge,
BotModelInfo,
BotOnboardingInfo,
BotPluginAPIInfo,
Expand Down Expand Up @@ -179,6 +180,7 @@
# bots
"BotPromptInfo",
"BotOnboardingInfo",
"BotKnowledge",
"BotModelInfo",
"BotPluginAPIInfo",
"BotPluginInfo",
Expand Down
91 changes: 54 additions & 37 deletions cozepy/bots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = True
# 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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Comment on lines +139 to +146
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add the knowledge parameter to the create method for consistency and functionality.

Currently, the create method does not accept a knowledge parameter, which means the bot's knowledge configuration cannot be set during creation. To allow users to set the bot's knowledge during creation and avoid the need for a subsequent update, consider adding the knowledge parameter to the create method.

Apply this diff to add the knowledge parameter to the create method and include it in the request body:

 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,
+    knowledge: Optional[BotKnowledge] = None,
 ) -> Bot:
     url = f"{self._base_url}/v1/bot/create"
     body = {
         "space_id": space_id,
         "name": name,
         "description": description,
         "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,
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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,
knowledge: Optional[BotKnowledge] = None,

) -> Bot:
url = f"{self._base_url}/v1/bot/create"
body = {
Expand All @@ -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.
Expand All @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Comment on lines +294 to +301
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add the knowledge parameter to the async create method for consistency and functionality.

Similar to the synchronous create method, the asynchronous create method in AsyncBotsClient lacks the knowledge parameter. To enable setting the bot's knowledge configuration during creation, consider adding the knowledge parameter.

Apply this diff to add the knowledge parameter to the create method and include it in the request body:

 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,
+    knowledge: Optional[BotKnowledge] = None,
 ) -> Bot:
     url = f"{self._base_url}/v1/bot/create"
     body = {
         "space_id": space_id,
         "name": name,
         "description": description,
         "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,
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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,
knowledge: Optional[BotKnowledge] = None,

) -> Bot:
url = f"{self._base_url}/v1/bot/create"
body = {
Expand All @@ -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.
Expand All @@ -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"
Expand All @@ -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")
Expand Down
Loading