16
16
17
17
'use strict' ;
18
18
19
- // [START generativeaionvertexai_sdk_embedding]
20
- async function main (
21
- project ,
22
- model = 'text-embedding-preview-0409' ,
23
- texts = 'banana bread?;banana muffins?' ,
24
- task = 'QUESTION_ANSWERING' ,
25
- dimensionality = 256 ,
26
- apiEndpoint = 'us-central1-aiplatform.googleapis.com'
27
- ) {
19
+ async function main ( ) {
20
+ // [START generativeaionvertexai_sdk_embedding]
21
+
22
+ // TODO(developer): Update the following for your own use case.
23
+ const project = 'long-door-651' ;
24
+ const model = 'text-embedding-preview-0815' ;
25
+ const location = 'us-central1' ;
26
+ // Calculate the embedding for code blocks. Using 'RETRIEVAL_DOCUMENT' for corpus.
27
+ // Specify the task type as 'CODE_RETRIEVAL_QUERY' for query, e.g. 'Retrieve a function that adds two numbers'.
28
+ const texts =
29
+ 'def func(a, b): return a + b;def func(a, b): return a - b;def func(a, b): return (a ** 2 + b ** 2) ** 0.5' ;
30
+ const task = 'RETRIEVAL_DOCUMENT' ;
31
+ const dimensionality = 3 ;
32
+ const apiEndpoint = 'us-central1-aiplatform.googleapis.com' ;
33
+
28
34
const aiplatform = require ( '@google-cloud/aiplatform' ) ;
29
35
const { PredictionServiceClient} = aiplatform . v1 ;
30
36
const { helpers} = aiplatform ; // helps construct protobuf.Value objects.
31
37
const clientOptions = { apiEndpoint : apiEndpoint } ;
32
- const location = 'us-central1' ;
33
38
const endpoint = `projects/${ project } /locations/${ location } /publishers/google/models/${ model } ` ;
34
39
const parameters = helpers . toValue ( {
35
40
outputDimensionality : parseInt ( dimensionality ) ,
@@ -50,14 +55,11 @@ async function main(
50
55
} ) ;
51
56
console . log ( 'Got embeddings: \n' + JSON . stringify ( embeddings ) ) ;
52
57
}
53
-
54
- callPredict ( ) ;
58
+ await callPredict ( ) ;
59
+ // [END generativeaionvertexai_sdk_embedding]
55
60
}
56
- // [END generativeaionvertexai_sdk_embedding]
57
61
58
- process . on ( 'unhandledRejection' , err => {
59
- console . error ( err . message ) ;
62
+ main ( ) . catch ( err => {
63
+ console . error ( err ) ;
60
64
process . exitCode = 1 ;
61
65
} ) ;
62
-
63
- main ( ...process . argv . slice ( 2 ) ) ;
0 commit comments