ravendb
Version:
RavenDB client for Node.js
93 lines • 3.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VertexSettings = void 0;
const AbstractAiSettings_js_1 = require("./AbstractAiSettings.js");
const AiSettingsCompareDifferences_js_1 = require("../AiSettingsCompareDifferences.js");
const index_js_1 = require("../../../../../Exceptions/index.js");
const StringUtil_js_1 = require("../../../../../Utility/StringUtil.js");
/**
* Settings for Google Vertex AI service.
*/
class VertexSettings extends AbstractAiSettings_js_1.AbstractAiSettings {
/**
* The model ID for the Vertex AI service.
*/
model;
/**
* The Google Cloud service account credentials in JSON format.
*/
googleCredentialsJson;
/**
* The version of Vertex AI to use.
*/
aiVersion;
/**
* The Google Cloud region/location for the Vertex AI service.
*/
location;
constructor(model, googleCredentialsJson, location, aiVersion) {
super();
this.model = model;
this.googleCredentialsJson = googleCredentialsJson;
this.location = location;
this.aiVersion = aiVersion;
}
/**
* Extracts the project ID from the Google credentials JSON.
*/
getProjectId() {
try {
const credentials = JSON.parse(this.googleCredentialsJson);
const projectId = credentials.project_id;
if (!projectId) {
(0, index_js_1.throwError)("InvalidArgumentException", "Couldn't find project_id in the provided googleCredentialsJson.");
}
return projectId;
}
catch (e) {
if (e.name === "InvalidArgumentException") {
throw e;
}
(0, index_js_1.throwError)("InvalidArgumentException", `Failed to parse googleCredentialsJson: ${e.message}`);
}
}
validate(errors) {
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.model)) {
errors.push("Value of 'model' field cannot be empty.");
}
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.googleCredentialsJson)) {
errors.push("Value of 'googleCredentialsJson' field cannot be empty.");
}
else {
try {
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.getProjectId())) {
errors.push("Value of 'project_id' field in 'googleCredentialsJson' cannot be empty.");
}
}
catch (e) {
errors.push(`Invalid 'googleCredentialsJson': ${e.message}`);
}
}
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.location)) {
errors.push("Value of 'location' field cannot be empty.");
}
}
compare(other) {
if (!(other instanceof VertexSettings)) {
return AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.All;
}
let differences = AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.None;
if (this.model !== other.model || this.aiVersion !== other.aiVersion) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.ModelArchitecture;
}
if (this.googleCredentialsJson !== other.googleCredentialsJson) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.AuthenticationSettings;
}
if (this.location !== other.location) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.DeploymentConfiguration;
}
return differences;
}
}
exports.VertexSettings = VertexSettings;
//# sourceMappingURL=VertexSettings.js.map