Skip to content

Commit 7a360b6

Browse files
authored
Merge pull request #3289 from GoogleCloudPlatform/list-llms
feat(aiplatform): adds list tuned models
2 parents 76c51f0 + e128d9d commit 7a360b6

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
function main(project, location, model = 'text-bison@001') {
19+
// [START aiplatform_list_tuned_models]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.\
22+
* (Not necessary if passing values as arguments)
23+
*/
24+
// const project = 'YOUR_PROJECT_ID';
25+
// const location = 'YOUR_PROJECT_LOCATION';
26+
// const model = 'text-bison@001';
27+
const aiplatform = require('@google-cloud/aiplatform');
28+
29+
const {ModelServiceClient} = aiplatform.v1;
30+
const clientOptions = {
31+
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
32+
};
33+
34+
// Instantiate the service client.
35+
const modelServiceClient = new ModelServiceClient(clientOptions);
36+
37+
function listTunedModels() {
38+
// Configure the parent resource
39+
const parent = `projects/${project}/locations/${location}`;
40+
const filter = `labels.google-vertex-llm-tuning-base-model-id=${model}`;
41+
42+
const request = {
43+
parent,
44+
filter,
45+
};
46+
47+
const [response] = modelServiceClient.listModels(request);
48+
console.log('List Tuned Models response');
49+
for (const model of response) {
50+
console.log(`\tModel name: ${model.name}`);
51+
console.log(`\tDisplay name: ${model.displayName}`);
52+
}
53+
}
54+
listTunedModels();
55+
// [END aiplatform_list_tuned_models]
56+
}
57+
58+
exports.listTunedModels = main;

ai-platform/snippets/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"c8": "^7.13.0",
2222
"chai": "^4.2.0",
2323
"mocha": "^10.0.0",
24-
"uuid": "^9.0.0"
24+
"uuid": "^9.0.0",
25+
"sinon": "^15.1.2"
2526
}
2627
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const {assert} = require('chai');
20+
const {describe, it} = require('mocha');
21+
const sinon = require('sinon');
22+
23+
const LOCATION = 'us-central1';
24+
const project = process.env.CAIP_PROJECT_ID;
25+
26+
const {listTunedModels} = require('../list-tuned-models');
27+
28+
describe('AI platform list tuned models', () => {
29+
const stubConsole = function () {
30+
sinon.stub(console, 'error');
31+
sinon.stub(console, 'log');
32+
};
33+
34+
const restoreConsole = function () {
35+
console.log.restore();
36+
console.error.restore();
37+
};
38+
39+
beforeEach(stubConsole);
40+
afterEach(restoreConsole);
41+
42+
it('should list all tuned LLM models', () => {
43+
listTunedModels(project, LOCATION);
44+
assert.include(console.log.firstCall.args, 'List Tuned Models response');
45+
});
46+
});

0 commit comments

Comments
 (0)