diff --git a/source/lambda/etl/chatbot_management.py b/source/lambda/etl/chatbot_management.py index ad0a79db..7b31240f 100644 --- a/source/lambda/etl/chatbot_management.py +++ b/source/lambda/etl/chatbot_management.py @@ -86,6 +86,7 @@ def __create_chatbot(event, group_name): chatbot_table, group_name, chatbot_id, + chatbot_description, index_id, index_type, tag, @@ -133,7 +134,18 @@ def __list_chatbot(event, group_name): page_json = [] for item in page_items: item_json = {} - item_json["chatbotId"] = item.get("chatbotId", {"S": ""})["S"] + chatbot_id = item.get("chatbotId", {"S": ""})["S"] + item_json["ChatbotId"] = chatbot_id + chatbot_model_item = model_table.get_item( + Key={ + "groupName": group_name, + "modelId": f"{chatbot_id}-embedding", + } + ).get("Item") + item_json["ModelName"] = chatbot_model_item.get("parameter", {}).get( + "ModelEndpoint", "" + ) + item_json["LastModifiedTime"] = item.get("updateTime", {"S": ""})["S"] page_json.append(item_json) output["Items"] = page_json if "LastEvaluatedKey" in page: @@ -144,12 +156,54 @@ def __list_chatbot(event, group_name): output["Config"] = config output["Count"] = len(page_json) - output = {"chatbot_ids": ["Admin"]} + output["chatbot_ids"] = [item["ChatbotId"] for item in page_json] return output +def merge_index(chatbot_index_ids, key): + return ",".join(list(chatbot_index_ids.get(key, {}).get("value", {}).values())) + + def __get_chatbot(event, group_name): - return {"Message": "Not Implemented"} + + chatbot_id = get_query_parameter(event, "chatbotId") + + if chatbot_id: + chatbot_item = chatbot_table.get_item( + Key={"groupName": group_name, "chatbotId": chatbot_id} + ).get("Item") + else: + chatbot_item = None + + 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/lambda/etl/utils/ddb_utils.py b/source/lambda/etl/utils/ddb_utils.py index acdcfcee..4bea4990 100644 --- a/source/lambda/etl/utils/ddb_utils.py +++ b/source/lambda/etl/utils/ddb_utils.py @@ -104,7 +104,14 @@ def initiate_index( def initiate_chatbot( - chatbot_table, group_name, chatbot_id, index_id, index_type, tag, create_time=None + chatbot_table, + group_name, + chatbot_id, + chatbot_description, + index_id, + index_type, + tag, + create_time=None, ): existing_item = item_exist( chatbot_table, {"groupName": group_name, "chatbotId": chatbot_id} @@ -136,7 +143,7 @@ def initiate_chatbot( { "groupName": group_name, "chatbotId": chatbot_id, - "languages": ["zh"], + "chatbotDescription": chatbot_description, "indexIds": {index_type: {"count": 1, "value": {tag: index_id}}}, "createTime": create_time, "updateTime": create_time, 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..901ae911 100644 --- a/source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx +++ b/source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx @@ -22,7 +22,8 @@ import { import { CreateChatbotResponse, GetChatbotResponse, - ChatbotItem + ChatbotItem, + ChatbotResponse } from 'src/types'; import useAxiosRequest from 'src/hooks/useAxiosRequest'; import { useTranslation } from 'react-i18next'; @@ -32,8 +33,8 @@ const ChatbotManagement: React.FC = () => { const [selectedItems, setSelectedItems] = useState([]); const fetchData = useAxiosRequest(); const { t } = useTranslation(); - const [loadingData] = useState(false); - const [allChatbotList] = useState([]); + const [loadingData, setLoadingData] = useState(false); + const [allChatbotList, setAllChatbotList] = useState([]); const [tableChatbotList, setTableChatbotList] = useState([]); const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(10); @@ -43,7 +44,7 @@ const ChatbotManagement: React.FC = () => { const [loadingSave, setLoadingSave] = useState(false); const [currentChatbot, setCurrentChatbot] = useState(); const [modelList, setModelList] = useState([]); - const [chatbotList, setChatbotList] = useState([]); + // const [chatbotList, setChatbotList] = useState([]); const [modelOption, setModelOption] = useState( null, ); @@ -82,40 +83,54 @@ const ChatbotManagement: React.FC = () => { }; const getChatbotList = async () => { - setLoadingGet(true); + setLoadingData(true); + setSelectedItems([]); + const params = { + max_items: 9999, + page_size: 9999, + }; try { const data = await fetchData({ url: 'chatbot-management/chatbots', method: 'get', + params, }); - const items: string[] = data.chatbot_ids; - const getChatbots = items.map((item) => { + const items: ChatbotResponse = data; + const preSortItem = items.Items.map((chatbot) => { return { - label: item, - value: item, + ...chatbot, + uuid: chatbot.ChatbotId, }; }); - setChatbotList(getChatbots); - setChatbotOption(getChatbots[0]); + setAllChatbotList(preSortItem); + setTableChatbotList(preSortItem.slice(0, pageSize)); + setLoadingData(false); } catch (error: unknown) { - setLoadingGet(false); + setLoadingData(false); } }; const getChatbotById = async (type: 'create' | 'edit') => { setLoadingGet(true); - let requestUrl = `chatbot-management/chatbots/${modelOption?.value}/common`; + let requestUrl = `chatbot-management/chatbots/default`; if (type === 'edit') { - requestUrl = `chatbot-management/chatbots/${selectedItems[0].ModelId}/common`; + requestUrl = `chatbot-management/chatbots/common`; + setChatbotOption({ + label: selectedItems[0].ChatbotId, + value: selectedItems[0].ChatbotId, + }); setModelOption({ - label: selectedItems[0].ModelId, - value: selectedItems[0].ModelId, + label: selectedItems[0].ModelName, + value: selectedItems[0].ModelName, }); } try { const data: GetChatbotResponse = await fetchData({ url: requestUrl, method: 'get', + params: { + chatbotId: selectedItems[0].ChatbotId, + }, }); setLoadingGet(false); setCurrentChatbot(data); @@ -132,7 +147,7 @@ const ChatbotManagement: React.FC = () => { setLoadingSave(true); try { await fetchData({ - url: `chatbot-management/chatbots/${selectedItems[0].ModelId}/common`, + url: `chatbot-management/chatbots/common`, method: 'delete', }); setLoadingSave(false); @@ -227,17 +242,18 @@ const ChatbotManagement: React.FC = () => { } ${t('selected')}`, }} columnDefinitions={[ + { + id: 'chatbotId', + header: t('chatbotName'), + cell: (item: ChatbotItem) => item.ChatbotId, + isRowHeader: true, + }, { id: 'modelId', header: t('modelName'), - cell: (item: ChatbotItem) => item.ModelId, + cell: (item: ChatbotItem) => item.ModelName, isRowHeader: true, }, - // { - // id: 'updateBy', - // header: t('updateBy'), - // cell: (item: ChatbotItem) => item.LastModifiedBy, - // }, { id: 'updateTime', header: t('updateTime'), @@ -381,23 +397,21 @@ const ChatbotManagement: React.FC = () => { header={t('button.createChatbot')} > - -