Skip to content

Commit

Permalink
feat: add create/update/publish bot api (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc authored Sep 25, 2024
1 parent 43690ef commit 11e5581
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
82 changes: 71 additions & 11 deletions cozepy/bot/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ class Bot(CozeModel):
# The ID for the bot.
bot_id: str
# The name of the bot.
name: str
name: str = None
# The description of the bot.
description: str
description: str = None
# The URL address for the bot's avatar.
icon_url: str
icon_url: str = None
# The creation time, in the format of a 10-digit Unix timestamp in seconds (s).
create_time: int
create_time: int = None
# The update time, in the format of a 10-digit Unix timestamp in seconds (s).
update_time: int
update_time: int = None
# The latest version of the bot.
version: str
version: str = None
# The prompt configuration for the bot. For more information, see Prompt object.
prompt_info: BotPromptInfo
prompt_info: BotPromptInfo = None
# The onboarding message configuration for the bot. For more information, see Onboarding object.
onboarding_info: BotOnboardingInfo
onboarding_info: BotOnboardingInfo = None
# The mode of the Bot, values: 0: Single Agent mode, 1: Multi Agent mode, 3: Single Agent Workflow mode.
bot_mode: BotMode
bot_mode: BotMode = None
# The plugins configured for the bot. For more information, see Plugin object.
plugin_info_list: List[BotPluginInfo]
plugin_info_list: List[BotPluginInfo] = None
# The model configured for the bot. For more information, see Model object.
model_info: BotModelInfo
model_info: BotModelInfo = None


class SimpleBot(CozeModel):
Expand All @@ -105,6 +105,66 @@ def __init__(self, base_url: str, auth: Auth, requester: Requester):
self._auth = auth
self._requester = requester

def create(
self,
*,
space_id: str,
name: str,
description: str = None,
icon_file_id: str = None,
prompt_info: BotPromptInfo = None,
onboarding_info: BotOnboardingInfo = 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,
}

return self._requester.request("post", url, Bot, body=body)

def update(
self,
*,
bot_id: str,
name: str = None,
description: str = None,
icon_file_id: str = None,
prompt_info: BotPromptInfo = None,
onboarding_info: BotOnboardingInfo = None,
) -> Bot:
url = f"{self._base_url}/v1/bot/update"
body = {
"bot_id": bot_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,
}

return self._requester.request("post", url, None, body=body)

def publish(
self,
*,
bot_id: str,
connector_ids: List[str] = None,
) -> Bot:
url = f"{self._base_url}/v1/bot/publish"
if not connector_ids:
connector_ids = ["API"]
body = {
"bot_id": bot_id,
"connector_ids": connector_ids,
}

return self._requester.request("post", url, Bot, body=body)

def retrieve(self, *, bot_id: str) -> Bot:
"""
Get the configuration information of the bot, which must have been published
Expand Down
2 changes: 2 additions & 0 deletions cozepy/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def request(
item_model = get_args(model)[0]
return [item_model.model_validate(item) for item in data]
else:
if model is None:
return None
return model.model_validate(data)

async def arequest(self, method: str, path: str, **kwargs) -> dict:
Expand Down

0 comments on commit 11e5581

Please sign in to comment.