Skip to content

Commit a6a8653

Browse files
fix: do not create more than 1 assistant projects (#30)
1 parent 4803ebc commit a6a8653

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

solutions/banking/watson-scripts/assistant-project-creation.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ set -e
44

55
IAM_TOKEN="$1"
66
WATSON_ASSISTANT_URL=$2
7+
project_name="gen-ai-rag-sample-app-assistant"
78

89
token="$(echo "$IAM_TOKEN" | awk '{print $2}')"
910

10-
curl -X POST --location "$WATSON_ASSISTANT_URL/v2/assistants?version=2023-06-15" \
11+
ASSISTANT_ID=$(curl --retry 3 -fLsS -X GET --location "$WATSON_ASSISTANT_URL/v2/assistants?version=2023-06-15" \
1112
--header "Authorization: Bearer $token" \
1213
--header "Content-Type: application/json" \
13-
--data "{\"name\":\"gen-ai-rag-sample-app-assistant\",\"language\":\"en\",\"description\":\"Generative AI sample app assistant\"}"
14+
| jq -r '.assistants[] | select(.name == "'$project_name'") | .assistant_id ')
15+
16+
if [[ -z "$ASSISTANT_ID" ]]; then
17+
# if not ASSISTANT_ID is found then create a new assistant project
18+
curl --retry 3 -fLsS -X POST --location "$WATSON_ASSISTANT_URL/v2/assistants?version=2023-06-15" \
19+
--header "Authorization: Bearer $token" \
20+
--header "Content-Type: application/json" \
21+
--data "{\"name\":\"$project_name\",\"language\":\"en\",\"description\":\"Generative AI sample app assistant\"}"
22+
else
23+
# If ASSISTANT_ID exists in a project then do not create another project.
24+
echo "$project_name project already exists."
25+
exit 0
26+
fi

0 commit comments

Comments
 (0)