From 76cbbb03da6b05e12762aed00fdaa890531a7df1 Mon Sep 17 00:00:00 2001 From: Janno Stern Date: Mon, 3 Jun 2024 10:37:05 +0300 Subject: [PATCH] Implement loading trained model --- DSL/load_trained_model.yml | 5 +++++ scripts/load_trained_model.sh | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 DSL/load_trained_model.yml create mode 100755 scripts/load_trained_model.sh diff --git a/DSL/load_trained_model.yml b/DSL/load_trained_model.yml new file mode 100644 index 0000000..92ee91a --- /dev/null +++ b/DSL/load_trained_model.yml @@ -0,0 +1,5 @@ +load_trained_model_now: + trigger: off + type: exec + command: "./scripts/load_trained_model.sh" + allowedEnvs: ["versionNumber"] diff --git a/scripts/load_trained_model.sh b/scripts/load_trained_model.sh new file mode 100755 index 0000000..393e9dc --- /dev/null +++ b/scripts/load_trained_model.sh @@ -0,0 +1,41 @@ +#!/bin/bash +echo 'Start script...' + +pwd +. constants.ini + +if [ -z "$versionNumber" ]; then + resql_response=$(curl -X POST -H "Content-Type: application/json" "$TRAINING_RESQL/get-latest-ready-model") +else + resql_response=$(curl -X POST -H "Content-Type: application/json" -d '{"versionNumber":"'$versionNumber'"}' "$TRAINING_RESQL/get-ready-model-by-version-number") +fi + +if [ "$resql_response" == [] ]; then + echo "error: specified model not found in the database" + exit 1 +fi + +filename=$(echo "$resql_response" | grep -o '"fileName":"[^"]*' | grep -o '[^"]*$') +model_type=$(echo "$resql_response" | grep -o '"modelType":"[^"]*' | grep -o '[^"]*$') +version_number=$(echo "$resql_response" | grep -o '"versionNumber":"[^"]*' | grep -o '[^"]*$') +model_version=$(echo "$resql_response" | grep -o '"modelVersion":"[^"]*' | grep -o '[^"]*$') + +copy_file_body_dto='{"destinationFilePath":"'$filename'","destinationStorageType":"FS","sourceFilePath":"'$filename'","sourceStorageType":"S3"}' +copy_file_response=$(curl -s -w "%{http_code}" -X POST -H "Content-Type: application/json" -d "$copy_file_body_dto" "$S3_FERRY/v1/files/copy") +copy_file_status="${copy_file_response: -3}" +if [ "$copy_file_status" != "201" ]; then + echo "error: model copying from remote to local storage failed with status code $copy_file_status" + exit 1 +fi + +load_status=$(curl -s -w "%{http_code}" -X PUT -H "Content-Type: application/json" -d '{"model_file":"/app/models/'$filename'"}' "$TRAINING_RASA/model") +if [ "$load_status" != "204" ]; then + echo "error: failed to load trained model from RASA with status code $load_status" + exit 1 +fi + +add_deployed_model_body_dto='{"fileName":"'$filename'","modelType":"'$model_type'","versionNumber":"'$version_number'","modelVersion":"'$model_version'"}' +curl -X POST -H "x-ruuter-skip-authentication: true" -H "Content-Type: application/json" -d "$add_deployed_model_body_dto" "$TRAINING_PUBLIC_RUUTER/rasa/model/add-new-model-deployed" + +shopt -s extglob +rm /data/!($filename) \ No newline at end of file