Skip to content

Commit

Permalink
Removing OAuth from tuning for REST (#579)
Browse files Browse the repository at this point in the history
* Removing OAuth from tuning for REST

* remove key

* Fix line continuation

Change-Id: I639aa453699766bf31f7722a59f4157a53cf7de4

---------

Co-authored-by: Mark Daoust <markdaoust@google.com>
  • Loading branch information
shilpakancharla and MarkDaoust authored Oct 1, 2024
1 parent 4354af6 commit 8f77cc6
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions samples/rest/tuned_models.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
set -eu

access_token=$(gcloud auth application-default print-access-token)


echo "[START tuned_models_create]"
# [START tuned_models_create]
curl -X POST https://generativelanguage.googleapis.com/v1beta/tunedModels \
curl -X POST "https://generativelanguage.googleapis.com/v1beta/tunedModels?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" \
-d '
{
"display_name": "number generator model",
Expand Down Expand Up @@ -82,10 +77,9 @@ tuning_done=false
while [[ "$tuning_done" != "true" ]];
do
sleep 5
curl -X GET https://generativelanguage.googleapis.com/v1/${operation} \
curl -X GET "https://generativelanguage.googleapis.com/v1/${operation}?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" 2> /dev/null > tuning_operation.json
2> /dev/null > tuning_operation.json

complete=$(jq .metadata.completedPercent < tuning_operation.json)
tput cuu1
Expand All @@ -96,21 +90,17 @@ done

# Or get the TunedModel and check it's state. The model is ready to use if the state is active.
modelname=$(cat tunemodel.json | jq ".metadata.tunedModel" | tr -d '"')
curl -X GET https://generativelanguage.googleapis.com/v1beta/${modelname} \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" > tuned_model.json
curl -X GET https://generativelanguage.googleapis.com/v1beta/${modelname}?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json' > tuned_model.json

cat tuned_model.json | jq ".state"
# [END tuned_models_create]


echo "[START tuned_models_generate_content]"
# [START tuned_models_generate_content]
curl -X POST https://generativelanguage.googleapis.com/v1beta/$modelname:generateContent \
curl -X POST https://generativelanguage.googleapis.com/v1beta/$modelname:generateContent?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" \
-d '{
"contents": [{
"parts": [{
Expand All @@ -122,10 +112,8 @@ curl -X POST https://generativelanguage.googleapis.com/v1beta/$modelname:generat

echo "[START tuned_models_get]"
# [START tuned_models_get]
curl -X GET https://generativelanguage.googleapis.com/v1beta/${modelname} \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" | grep state
curl -X GET https://generativelanguage.googleapis.com/v1beta/${modelname}?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json' | grep state
# [END tuned_models_get]

echo "[START tuned_models_list]"
Expand All @@ -142,18 +130,14 @@ jq .tunedModels[].name < tuned_models.json
page_token=$(jq .nextPageToken < tuned_models.json | tr -d '"')

if [[ "$page_token" != "null"" ]]; then
curl -X GET https://generativelanguage.googleapis.com/v1beta/tunedModels?page_size=5\&page_token=${page_token} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" > tuned_models2.json
curl -X GET https://generativelanguage.googleapis.com/v1beta/tunedModels?page_size=5\&page_token=${page_token}?key=$GOOGLE_API_KEY \
-H "Content-Type: application/json" > tuned_models2.json
jq .tunedModels[].name < tuned_models.json
fi
# [END tuned_models_list]
echo "[START tuned_models_delete]"
# [START tuned_models_delete]
curl -X DELETE https://generativelanguage.googleapis.com/v1beta/${modelname} \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}"
curl -X DELETE https://generativelanguage.googleapis.com/v1beta/${modelname}?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json'
# [END tuned_models_delete]

0 comments on commit 8f77cc6

Please sign in to comment.