From abe2fde0baf7be9a98575b913ce7b93e8f616290 Mon Sep 17 00:00:00 2001 From: Xu Han Date: Wed, 28 Aug 2024 15:38:49 +0000 Subject: [PATCH 1/3] feat: improve chatbot management API --- source/lambda/etl/chatbot_management.py | 41 ++++++++++++++++++- source/portal/src/locale/en.json | 3 +- source/portal/src/locale/zh.json | 3 +- .../chatbotManagement/ChatbotManagement.tsx | 40 +++++++++--------- source/portal/src/types/index.ts | 2 +- 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/source/lambda/etl/chatbot_management.py b/source/lambda/etl/chatbot_management.py index ad0a79db..1a28df5d 100644 --- a/source/lambda/etl/chatbot_management.py +++ b/source/lambda/etl/chatbot_management.py @@ -144,12 +144,49 @@ def __list_chatbot(event, group_name): output["Config"] = config output["Count"] = len(page_json) - output = {"chatbot_ids": ["Admin"]} + output = {"chatbot_ids": ["admin"]} return output def __get_chatbot(event, group_name): - return {"Message": "Not Implemented"} + + chatbot_id = get_query_parameter(event, "chatbotId") + chatbot_item = chatbot_table.get_item( + Key={"groupName": group_name, "chatbotId": chatbot_id} + ).get("Item") + + def merge_index(chatbot_index_ids, key): + return ",".join(list(chatbot_index_ids.get(key, {}).get("value", {}).values())) + + if chatbot_item: + chatbot_index_ids = chatbot_item.get("indexIds", {}) + + response = { + "GroupName": group_name, + "ChatbotId": chatbot_id, + "Chatbot": { + "inention": { + "index": merge_index(chatbot_index_ids, "intention"), + }, + "qq": { + "index": merge_index(chatbot_index_ids, "qq"), + }, + "qd": { + "index": merge_index(chatbot_index_ids, "qd"), + }, + }, + } + else: + response = { + "GroupName": group_name, + "ChatbotId": chatbot_id, + "Chatbot": { + "inention": {"index": f"{chatbot_id}-intention-default"}, + "qq": {"index": f"{chatbot_id}-qq-default"}, + "qd": {"index": f"{chatbot_id}-qd-default"}, + }, + } + return response def __delete_chatbot(event, group_name): diff --git a/source/portal/src/locale/en.json b/source/portal/src/locale/en.json index 9f2b5756..a1eefd84 100644 --- a/source/portal/src/locale/en.json +++ b/source/portal/src/locale/en.json @@ -76,8 +76,9 @@ "sessionHistory": "Session History", "prompt": "Prompt", "prompts": "Prompts", - "chatbotManagement": "Chat Bot Management", + "chatbot": "Chat Bot", "chatbots": "Chat Bots", + "chatbotManagement": "Chat Bot Management", "type": "Type", "updateBy": "Update by", "updateTime": "Update time", diff --git a/source/portal/src/locale/zh.json b/source/portal/src/locale/zh.json index b7a1a420..af2086c4 100644 --- a/source/portal/src/locale/zh.json +++ b/source/portal/src/locale/zh.json @@ -78,8 +78,9 @@ "sessionHistory": "历史记录", "prompt": "提示词", "prompts": "提示词", - "chatbotManagement": "管理聊天机器人", + "chatbot": "聊天机器人", "chatbots": "聊天机器人", + "chatbotManagement": "管理聊天机器人", "type": "类型", "updateBy": "更新者", "updateTime": "更新时间", diff --git a/source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx b/source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx index 95b08d50..0fc672cd 100644 --- a/source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx +++ b/source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx @@ -97,6 +97,7 @@ const ChatbotManagement: React.FC = () => { }); setChatbotList(getChatbots); setChatbotOption(getChatbots[0]); + console.log('chatbotList:', chatbotList); } catch (error: unknown) { setLoadingGet(false); } @@ -104,9 +105,9 @@ const ChatbotManagement: React.FC = () => { const getChatbotById = async (type: 'create' | 'edit') => { setLoadingGet(true); - let requestUrl = `chatbot-management/chatbots/${modelOption?.value}/common`; + let requestUrl = `chatbot-management/chatbots/${chatbotOption?.value}/common`; if (type === 'edit') { - requestUrl = `chatbot-management/chatbots/${selectedItems[0].ModelId}/common`; + requestUrl = `chatbot-management/chatbots/${selectedItems[0].chatbotId}/common`; setModelOption({ label: selectedItems[0].ModelId, value: selectedItems[0].ModelId, @@ -116,6 +117,9 @@ const ChatbotManagement: React.FC = () => { const data: GetChatbotResponse = await fetchData({ url: requestUrl, method: 'get', + params: { + chatbotId: chatbotOption?.value, + }, }); setLoadingGet(false); setCurrentChatbot(data); @@ -381,23 +385,21 @@ const ChatbotManagement: React.FC = () => { header={t('button.createChatbot')} > - -