Skip to content

Commit

Permalink
refactor: api path etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
530051970 committed Sep 27, 2024
1 parent 87d7f84 commit e97de05
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
56 changes: 28 additions & 28 deletions source/infrastructure/lib/api/api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export class ApiConstruct extends Construct {
proxy: true,
});
const apiResourceChatbotManagement = api.root.addResource("chatbot-management");
const chatbotResource = apiResourceChatbotManagement.addResource('chatbot');
// const chatbotResource = apiResourceChatbotManagement.addResource('chatbot');
const apiResourceCheckChatbot = apiResourceChatbotManagement.addResource('check-chatbot');
apiResourceCheckChatbot.addMethod("POST", lambdaChatbotIntegration, this.genMethodOption(api, auth, null));
const apiResourceChatbots = apiResourceChatbotManagement.addResource("chatbots");
Expand Down Expand Up @@ -563,33 +563,33 @@ export class ApiConstruct extends Construct {
}
})

const apiGetChatbotById = chatbotResource.addResource("{chatbotId}");
apiGetChatbotById.addMethod(
"GET",
new apigw.LambdaIntegration(chatbotManagementLambda.function),
{
...this.genMethodOption(api, auth, {
Items: {
type: JsonSchemaType.ARRAY, items: {
type: JsonSchemaType.OBJECT,
properties: {
chatbotId: { type: JsonSchemaType.STRING },
index: { type: JsonSchemaType.STRING },
model: { type: JsonSchemaType.STRING },
},
required: ['chatbotId', 'index', 'model'],
}
},
Count: { type: JsonSchemaType.INTEGER }
}),
requestParameters: {
'method.request.path.chatbotId': true
},
// requestModels: this.genRequestModel(api, {
// "executionId": { "type": JsonSchemaType.ARRAY, "items": {"type": JsonSchemaType.STRING}},
// })
}
);
// const apiGetChatbotById = chatbotResource.addResource("{chatbotId}");
// apiGetChatbotById.addMethod(
// "GET",
// new apigw.LambdaIntegration(chatbotManagementLambda.function),
// {
// ...this.genMethodOption(api, auth, {
// Items: {
// type: JsonSchemaType.ARRAY, items: {
// type: JsonSchemaType.OBJECT,
// properties: {
// chatbotId: { type: JsonSchemaType.STRING },
// index: { type: JsonSchemaType.STRING },
// model: { type: JsonSchemaType.STRING },
// },
// required: ['chatbotId', 'index', 'model'],
// }
// },
// Count: { type: JsonSchemaType.INTEGER }
// }),
// requestParameters: {
// 'method.request.path.chatbotId': true
// },
// // requestModels: this.genRequestModel(api, {
// // "executionId": { "type": JsonSchemaType.ARRAY, "items": {"type": JsonSchemaType.STRING}},
// // })
// }
// );



Expand Down
11 changes: 4 additions & 7 deletions source/lambda/etl/chatbot_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
DEFAULT_MAX_ITEMS = 50
DEFAULT_SIZE = 50
ROOT_RESOURCE = "/chatbot-management"
CHATBOT_RESOURCE = "/chatbot-management/chatbot"
# CHATBOT_RESOURCE = "/chatbot-management/chatbot"
EMBEDDING_MODELS_RESOURCE = f"{ROOT_RESOURCE}/embeddings"
INDEXES_RESOURCE = f"{ROOT_RESOURCE}/indexes"
CHATBOTS_RESOURCE = f"{ROOT_RESOURCE}/chatbots"
Expand Down Expand Up @@ -174,8 +174,7 @@ def merge_index(chatbot_index_ids, key):


def __get_chatbot(event, group_name):

chatbot_id = event.get("pathParameters", {}).get("chatbotId")
chatbot_id = event.get("pathParameters", {}).get("proxy")
if chatbot_id:
chatbot_item = chatbot_table.get_item(
Key={"groupName": group_name, "chatbotId": chatbot_id}
Expand Down Expand Up @@ -251,14 +250,12 @@ def lambda_handler(event, context):
elif http_method == "GET":
if resource == CHATBOTS_RESOURCE:
output = __list_chatbot(event, group_name)
else:
output = __get_chatbot(event, group_name)
elif http_method == "DELETE":
output = __delete_chatbot(event, group_name)
elif resource == CHATBOTCHECK_RESOURCE:
output = __validate_chatbot(event, group_name)
elif resource.startswith(CHATBOT_RESOURCE):
output = __get_chatbot(event, group_name)
# elif resource.startswith(DETAILS_RESOURCE):
# output == __chatbot_details(resource.split("/").pop(), group_name)

try:
return {
Expand Down
8 changes: 2 additions & 6 deletions source/lambda/intention/intention.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,7 @@ def __create_execution(event, context, email, group_name):
}
)
# write to aos(vectorData)
# # <<<<<<< HEAD
# __save_2_aos(input_body.get("model", {}).get("value"), execution_detail["index"], qaList)
# # =======
__save_2_aos(input_body.get("model"), execution_detail["index"], qaList, bucket, prefix)
# >>>>>>> de5812df214387970b7f0a344707524c82bd19fe
__save_2_aos(input_body.get("model", {}).get("value"), execution_detail["index"], qaList, bucket, prefix)

return {
"execution_id": execution_detail["tableItemId"],
Expand Down Expand Up @@ -468,7 +464,7 @@ def __refresh_index(index: str, modelId: str, qaList):
index, modelId, qaList), chunk_size=BULK_SIZE)
aos_client.indices.refresh(index=index)
logger.info("Successfully added: %d ", success)
logger.info("Failed: %d ", failed)
logger.info("Failed: %d ", len(failed))


def __append_embeddings(index, modelId, qaList: list):
Expand Down
2 changes: 1 addition & 1 deletion source/portal/src/pages/intention/Intention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const Intention: React.FC = () => {

const getChatBotDetail = async (chatbotId: string) =>{
const res: ChatbotsItem = await fetchData({
url: `chatbot-management/chatbot/${chatbotId}`,
url: `chatbot-management/chatbots/${chatbotId}`,
method: 'get',
});
setModel({label: res.model.model_name, value: res.model.model_endpoint})
Expand Down

0 comments on commit e97de05

Please sign in to comment.