Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing OAuth from tuning for REST #579

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions samples/rest/tuned_models.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
set -eu

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

GOOGLE_API_KEY=AIzaSyB1bw8ghsEm65evO_Yn9CeorYEh2oDEw-M
MarkDaoust marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this line.

Use environment variables to avoid this. Put:

export GOOGLE_API_KEY=...

In your ~/.bash_profile file.


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 +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
Expand All @@ -96,21 +91,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 +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]"
Expand All @@ -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]
Loading