-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'imagen' of https://github.com/GoogleCloudPlatform/nodej…
…s-docs-samples into imagen
- Loading branch information
Showing
13 changed files
with
307 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,26 +28,5 @@ jobs: | |
contents: 'read' | ||
id-token: 'write' | ||
steps: | ||
- name: authenticate | ||
uses: 'google-github-actions/auth@62cf5bd3e4211a0a0b51f2c6d6a37129d828611d' # v2 | ||
with: | ||
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | ||
service_account: '[email protected]' | ||
create_credentials_file: 'true' | ||
access_token_lifetime: 600s | ||
- name: download test results | ||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 | ||
with: | ||
name: test-results | ||
- name: download FlakyBot | ||
run: | | ||
curl -s -L https://github.com/googleapis/repo-automation-bots/archive/refs/tags/flakybot-v${{ env.FLAKYBOT_VERSION }}.tar.gz -o flakybot.tar.gz | ||
tar xzf flakybot.tar.gz | ||
cp -rT repo-automation-bots-flakybot-v${{ env.FLAKYBOT_VERSION}}/packages/flakybot/ . | ||
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 | ||
with: | ||
cache: true | ||
cache-dependency-path: '${{ github.workspace }}/go.sum' | ||
go-version-file: '${{ github.workspace }}/go.mod' | ||
- name: run FlakyBot | ||
run: go run flakybot.go --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} | ||
- name: DISABLED run FlakyBot | ||
run: echo flakybot error reporting disabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
async function gemma2PredictGpu(predictionServiceClient) { | ||
// [START generativeaionvertexai_gemma2_predict_gpu] | ||
// Imports the Google Cloud Prediction Service Client library | ||
const { | ||
// TODO(developer): Uncomment PredictionServiceClient before running the sample. | ||
// PredictionServiceClient, | ||
helpers, | ||
} = require('@google-cloud/aiplatform'); | ||
/** | ||
* TODO(developer): Update these variables before running the sample. | ||
*/ | ||
const projectId = 'your-project-id'; | ||
const endpointRegion = 'your-vertex-endpoint-region'; | ||
const endpointId = 'your-vertex-endpoint-id'; | ||
|
||
// Default configuration | ||
const config = {maxOutputTokens: 1024, temperature: 0.9, topP: 1.0, topK: 1}; | ||
// Prompt used in the prediction | ||
const prompt = 'Why is the sky blue?'; | ||
|
||
// Encapsulate the prompt in a correct format for GPUs | ||
// Example format: [{inputs: 'Why is the sky blue?', parameters: {temperature: 0.9}}] | ||
const input = { | ||
inputs: prompt, | ||
parameters: config, | ||
}; | ||
|
||
// Convert input message to a list of GAPIC instances for model input | ||
const instances = [helpers.toValue(input)]; | ||
|
||
// TODO(developer): Uncomment apiEndpoint and predictionServiceClient before running the sample. | ||
// const apiEndpoint = `${endpointRegion}-aiplatform.googleapis.com`; | ||
|
||
// Create a client | ||
// predictionServiceClient = new PredictionServiceClient({apiEndpoint}); | ||
|
||
// Call the Gemma2 endpoint | ||
const gemma2Endpoint = `projects/${projectId}/locations/${endpointRegion}/endpoints/${endpointId}`; | ||
|
||
const [response] = await predictionServiceClient.predict({ | ||
endpoint: gemma2Endpoint, | ||
instances, | ||
}); | ||
|
||
const predictions = response.predictions; | ||
const text = predictions[0].stringValue; | ||
|
||
console.log('Predictions:', text); | ||
// [END generativeaionvertexai_gemma2_predict_gpu] | ||
return text; | ||
} | ||
|
||
module.exports = gemma2PredictGpu; | ||
|
||
// TODO(developer): Uncomment below lines before running the sample. | ||
// gemma2PredictGpu(...process.argv.slice(2)).catch(err => { | ||
// console.error(err.message); | ||
// process.exitCode = 1; | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
async function gemma2PredictTpu(predictionServiceClient) { | ||
// [START generativeaionvertexai_gemma2_predict_tpu] | ||
// Imports the Google Cloud Prediction Service Client library | ||
const { | ||
// TODO(developer): Uncomment PredictionServiceClient before running the sample. | ||
// PredictionServiceClient, | ||
helpers, | ||
} = require('@google-cloud/aiplatform'); | ||
/** | ||
* TODO(developer): Update these variables before running the sample. | ||
*/ | ||
const projectId = 'your-project-id'; | ||
const endpointRegion = 'your-vertex-endpoint-region'; | ||
const endpointId = 'your-vertex-endpoint-id'; | ||
|
||
// Prompt used in the prediction | ||
const prompt = 'Why is the sky blue?'; | ||
|
||
// Encapsulate the prompt in a correct format for TPUs | ||
// Example format: [{prompt: 'Why is the sky blue?', temperature: 0.9}] | ||
const input = { | ||
prompt, | ||
// Parameters for default configuration | ||
maxOutputTokens: 1024, | ||
temperature: 0.9, | ||
topP: 1.0, | ||
topK: 1, | ||
}; | ||
|
||
// Convert input message to a list of GAPIC instances for model input | ||
const instances = [helpers.toValue(input)]; | ||
|
||
// TODO(developer): Uncomment apiEndpoint and predictionServiceClient before running the sample. | ||
// const apiEndpoint = `${endpointRegion}-aiplatform.googleapis.com`; | ||
|
||
// Create a client | ||
// predictionServiceClient = new PredictionServiceClient({apiEndpoint}); | ||
|
||
// Call the Gemma2 endpoint | ||
const gemma2Endpoint = `projects/${projectId}/locations/${endpointRegion}/endpoints/${endpointId}`; | ||
|
||
const [response] = await predictionServiceClient.predict({ | ||
endpoint: gemma2Endpoint, | ||
instances, | ||
}); | ||
|
||
const predictions = response.predictions; | ||
const text = predictions[0].stringValue; | ||
|
||
console.log('Predictions:', text); | ||
// [END generativeaionvertexai_gemma2_predict_tpu] | ||
return text; | ||
} | ||
|
||
module.exports = gemma2PredictTpu; | ||
|
||
// TODO(developer): Uncomment below lines before running the sample. | ||
// gemma2PredictTpu(...process.argv.slice(2)).catch(err => { | ||
// console.error(err.message); | ||
// process.exitCode = 1; | ||
// }); |
Oops, something went wrong.