From 8f77cc6ac99937cd3a81299ecf79608b91b06bbb Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Tue, 1 Oct 2024 13:24:26 -0700 Subject: [PATCH] Removing OAuth from tuning for REST (#579) * Removing OAuth from tuning for REST * remove key * Fix line continuation Change-Id: I639aa453699766bf31f7722a59f4157a53cf7de4 --------- Co-authored-by: Mark Daoust --- samples/rest/tuned_models.sh | 40 +++++++++++------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/samples/rest/tuned_models.sh b/samples/rest/tuned_models.sh index 1e105377e..9b652febd 100644 --- a/samples/rest/tuned_models.sh +++ b/samples/rest/tuned_models.sh @@ -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", @@ -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 @@ -96,10 +90,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 +99,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 +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]" @@ -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] \ No newline at end of file