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

fix: bug fix in chatbot and intention #378

Merged
merged 5 commits into from
Sep 5, 2024
Merged
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
11 changes: 6 additions & 5 deletions source/infrastructure/lib/api/api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,17 @@ export class ApiConstruct extends Construct {
const apiResourceChatbotManagement = api.root.addResource("chatbot-management");
const apiResourceCheckChatbot = apiResourceChatbotManagement.addResource('check-chatbot')
apiResourceCheckChatbot.addMethod("POST", lambdaChatbotIntegration, this.genMethodOption(api, auth, null))
const apiResourceChatbot = apiResourceChatbotManagement.addResource("chatbots");
apiResourceChatbot.addMethod("POST", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));
apiResourceChatbot.addMethod("GET", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));
const apiResourceChatbotDetail = apiResourceChatbot.addResource('detail')
const apiResourceChatbots = apiResourceChatbotManagement.addResource("chatbots");
apiResourceChatbots.addMethod("POST", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));
apiResourceChatbots.addMethod("GET", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));
const apiResourceChatbot = apiResourceChatbotManagement.addResource("chatbot");
const apiResourceChatbotDetail = apiResourceChatbot.addResource('{chatbotId}')
apiResourceChatbotDetail.addMethod("GET", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));

const apiResourceChatbotManagementEmbeddings = apiResourceChatbotManagement.addResource("embeddings")
apiResourceChatbotManagementEmbeddings.addMethod("GET", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));

const apiResourceChatbotProxy = apiResourceChatbot.addResource("{proxy+}")
const apiResourceChatbotProxy = apiResourceChatbots.addResource("{proxy+}")
apiResourceChatbotProxy.addMethod("DELETE", lambdaChatbotIntegration, this.genMethodOption(api, auth, null),);
apiResourceChatbotProxy.addMethod("GET", lambdaChatbotIntegration, this.genMethodOption(api, auth, null),);

Expand Down
25 changes: 12 additions & 13 deletions source/lambda/etl/chatbot_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
EMBEDDING_MODELS_RESOURCE = f"{ROOT_RESOURCE}/embeddings"
INDEXES_RESOURCE = f"{ROOT_RESOURCE}/indexes"
CHATBOTS_RESOURCE = f"{ROOT_RESOURCE}/chatbots"
DETAILS_RESOURCE = f"{CHATBOTS_RESOURCE}/details"
DETAILS_RESOURCE = f"{ROOT_RESOURCE}/chatbot"
CHATBOTCHECK_RESOURCE = f"{ROOT_RESOURCE}/check-chatbot"
logger = logging.getLogger(__name__)
encoder = TokenEncoder()
Expand Down Expand Up @@ -62,8 +62,8 @@ def __create_chatbot(event, group_name):
"chatbotDescription", "Answer question based on search result"
)
chatbot_embedding = request_body.get("modelId", embedding_endpoint)
# model_id = f"{chatbot_id}-embedding"
model_id = request_body.get("modelId", f"{chatbot_id}-embedding")
model_id = f"{chatbot_id}-embedding"
# model_id = request_body.get("modelId", f"{chatbot_id}-embedding")
create_time = str(datetime.now(timezone.utc))

initiate_model(model_table, group_name, model_id, chatbot_embedding, create_time)
Expand Down Expand Up @@ -173,6 +173,7 @@ def __list_chatbot(event, group_name):
item_json["ModelId"] = chatbot_model_item.get("modelId", "")
item_json["LastModifiedTime"] = item.get("updateTime", {"S": ""})["S"]
page_json.append(item_json)
page_json.sort(key=lambda x: x["LastModifiedTime"], reverse=True)
output["Items"] = page_json
if "LastEvaluatedKey" in page:
output["LastEvaluatedKey"] = encoder.encode(
Expand Down Expand Up @@ -261,8 +262,8 @@ def lambda_handler(event, context):
output = __delete_chatbot(event, group_name)
elif resource == CHATBOTCHECK_RESOURCE:
output = __validate_chatbot(event, group_name)
elif resource == DETAILS_RESOURCE:
output == __chatbot_details(event, group_name)
elif resource.startswith(DETAILS_RESOURCE):
output == __chatbot_details(resource.split("/").pop(), group_name)

try:
return {
Expand Down Expand Up @@ -293,7 +294,7 @@ def __validate_chatbot(event, group_name):
if chatbot_type=="create":
chatbot_item = chatbot_table.get_item(
Key={"groupName": group_name, "chatbotId": chatbot_id}
)
).get("Item")
if chatbot_item:
return {
"result": False,
Expand All @@ -317,7 +318,7 @@ def __validate_chatbot(event, group_name):
FilterExpression=Attr('indexId').is_in(list(index_set))
)
items = response.get('Items')
if not items:
if items:
for item in items:
if item['groupName'] != group_name:
# 其他人用了index,报错
Expand All @@ -327,7 +328,7 @@ def __validate_chatbot(event, group_name):
"Message": "repeat in other group name"
}
else:
if item.get("modelIds", {}).get("embedding",{}).get("S") != model:
if item.get("modelIds", {}).get("embedding","") != model:
# 自己用了index,但是模型 不对,报错
return {
"result": False,
Expand All @@ -342,12 +343,11 @@ def __validate_chatbot(event, group_name):

def __find_key(index, index_id):
for key, value in index.items():
if value.contains(index_id):
if index_id in value.split(","):
return key
return None

def __chatbot_details(event, group_name):
chatbot_id = get_query_parameter(event, "chatbotId", "admin")
def __chatbot_details(chatbot_id, group_name):
res={chatbot_id:chatbot_id}
index = chatbot_table.get_item(
Key={"groupName": group_name,
Expand All @@ -357,5 +357,4 @@ def __chatbot_details(event, group_name):
for key, value in index.items():
value.get("value",{}).get("M",{}).keys()
res[key]=""

pass
return res
1 change: 1 addition & 0 deletions source/portal/src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"upload": "Upload",
"createPrompt": "Create Prompt",
"createChatbot": "Create Chatbot",
"editChatbot": "Edit Chatbot",
"edit": "Edit",
"save": "Save",
"action": "Action"
Expand Down
6 changes: 4 additions & 2 deletions source/portal/src/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"settings": "设置",
"signOut": "退出登录",
"chatSpace": "聊天",
"chat": "当前会话",
"chatBot": "聊天机器人",
"docLibrary": "文档库",
"addLibrary": "添加文档",
Expand Down Expand Up @@ -77,7 +76,7 @@
"scenario": "场景",
"maxTokens": "最大 Token 数",
"temperature": "发散度",
"sessionHistory": "会话历史",
"sessionHistory": "历史记录",
"prompt": "提示词",
"prompts": "提示词",
"chatbot": "聊天机器人",
Expand Down Expand Up @@ -121,6 +120,7 @@
"upload": "上传",
"createPrompt": "创建提示",
"createChatbot": "创建聊天机器人",
"editChatbot": "编辑聊天机器人",
"edit": "编辑",
"save": "保存",
"action": "操作"
Expand All @@ -132,6 +132,8 @@
"validation": {
"requireModel": "请选择或输入一个模型",
"requireChatbotName": "请输入机器人名称",
"repeatChatbotName": "该名称已经被使用,请更换新的名称",
"repeatIndex": "该索引名称已经被使用,请更换新的索引名称",
"requireChatbot": "请选择一个机器人",
"requireTemperature": "请输入模型发散度",
"requireMaxTokens": "请输入一个最大 token 数",
Expand Down
1 change: 0 additions & 1 deletion source/portal/src/pages/chatbot/ChatBot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { useAuth } from 'react-oidc-context';
import {
LLM_BOT_COMMON_MODEL_LIST,
LLM_BOT_RETAIL_MODEL_LIST,
LLM_BOT_CHATBOT_LIST,
SCENARIO_LIST,
RETAIL_GOODS_LIST,
} from 'src/utils/const';
Expand Down
Loading
Loading