-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvertex.js
57 lines (40 loc) · 1.32 KB
/
vertex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
require('dotenv').config();
async function generateBlog(promptText, location = "us-central1") {
const aiplatform = require("@google-cloud/aiplatform");
const { PredictionServiceClient } = aiplatform.v1;
const { helpers } = aiplatform;
const clientOptions = {
apiEndpoint: "us-central1-aiplatform.googleapis.com",
};
const publisher = "google";
const model = "text-bison@001";
const projectId = "vertexai-399501";
// Instantiates a client
const predictionServiceClient = new PredictionServiceClient(clientOptions);
async function callPredict() {
const endpoint = `projects/${projectId}/locations/${location}/publishers/${publisher}/models/${model}`;
const prompt = {
prompt: promptText.toString(),
};
const instanceValue = helpers.toValue(prompt);
const instances = [instanceValue];
const parameter = {
candidateCount: 1,
temperature: 0.1,
maxOutputTokens: 1024,
topP: 0.9,
topK: 40,
};
const parameters = helpers.toValue(parameter);
const request = {
endpoint,
instances,
parameters,
};
const response = await predictionServiceClient.predict(request);
return response[0].predictions[0].structValue.fields.content.stringValue;
}
return callPredict();
}
module.exports = { generateBlog };