From ef4c85b84435e6ccbac551436f786c54314fe291 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Tue, 1 Oct 2024 12:14:16 -0700 Subject: [PATCH 1/3] Removing OAuth from tuning for REST --- samples/rest/tuned_models.sh | 41 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/samples/rest/tuned_models.sh b/samples/rest/tuned_models.sh index 1e105377e..076e3c943 100644 --- a/samples/rest/tuned_models.sh +++ b/samples/rest/tuned_models.sh @@ -1,14 +1,11 @@ set -eu -access_token=$(gcloud auth application-default print-access-token) - +GOOGLE_API_KEY=AIzaSyB1bw8ghsEm65evO_Yn9CeorYEh2oDEw-M 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", @@ -82,10 +79,8 @@ tuning_done=false while [[ "$tuning_done" != "true" ]]; do sleep 5 - curl -X GET https://generativelanguage.googleapis.com/v1/${operation} \ - -H 'Content-Type: application/json' \ - -H "Authorization: Bearer ${access_token}" \ - -H "x-goog-user-project: ${project_id}" 2> /dev/null > tuning_operation.json + curl -X GET "https://generativelanguage.googleapis.com/v1/${operation}?key=$GOOGLE_API_KEY" \ + -H 'Content-Type: application/json' \ 2> /dev/null > tuning_operation.json complete=$(jq .metadata.completedPercent < tuning_operation.json) tput cuu1 @@ -96,10 +91,8 @@ 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] @@ -107,10 +100,8 @@ cat tuned_model.json | jq ".state" 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": [{ @@ -122,10 +113,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]" @@ -142,18 +131,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] \ No newline at end of file From bf63b1862238fe4933580318257f35928c69f427 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Tue, 1 Oct 2024 12:58:25 -0700 Subject: [PATCH 2/3] remove key --- samples/rest/tuned_models.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/rest/tuned_models.sh b/samples/rest/tuned_models.sh index 076e3c943..2fcd23c25 100644 --- a/samples/rest/tuned_models.sh +++ b/samples/rest/tuned_models.sh @@ -1,7 +1,5 @@ set -eu -GOOGLE_API_KEY=AIzaSyB1bw8ghsEm65evO_Yn9CeorYEh2oDEw-M - echo "[START tuned_models_create]" # [START tuned_models_create] curl -X POST "https://generativelanguage.googleapis.com/v1beta/tunedModels?key=$GOOGLE_API_KEY" \ From 889102b0372856f2493ddc13d92a495846c93e9e Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 1 Oct 2024 13:22:34 -0700 Subject: [PATCH 3/3] Fix line continuation Change-Id: I639aa453699766bf31f7722a59f4157a53cf7de4 --- samples/rest/tuned_models.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/rest/tuned_models.sh b/samples/rest/tuned_models.sh index 2fcd23c25..9b652febd 100644 --- a/samples/rest/tuned_models.sh +++ b/samples/rest/tuned_models.sh @@ -78,7 +78,8 @@ while [[ "$tuning_done" != "true" ]]; do sleep 5 curl -X GET "https://generativelanguage.googleapis.com/v1/${operation}?key=$GOOGLE_API_KEY" \ - -H 'Content-Type: application/json' \ 2> /dev/null > tuning_operation.json + -H 'Content-Type: application/json' \ + 2> /dev/null > tuning_operation.json complete=$(jq .metadata.completedPercent < tuning_operation.json) tput cuu1