ravendb
Version:
RavenDB client for Node.js
94 lines • 3.84 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenAiBaseSettings = void 0;
const AbstractAiSettings_js_1 = require("./AbstractAiSettings.js");
const AiSettingsCompareDifferences_js_1 = require("../AiSettingsCompareDifferences.js");
const StringUtil_js_1 = require("../../../../../Utility/StringUtil.js");
/**
* Base settings for OpenAI-compatible providers.
*/
class OpenAiBaseSettings extends AbstractAiSettings_js_1.AbstractAiSettings {
/**
* The API key to use to authenticate with the service.
*/
apiKey;
/**
* The service endpoint that the client will send requests to.
*/
endpoint;
/**
* The model that should be used.
*/
model;
/**
* The number of dimensions that the model should use.
*/
dimensions;
/**
* Controls randomness of the model output. Range typically [0.0, 2.0].
* Higher values (e.g., 1.0+) make output more creative and diverse;
* lower values (e.g., 0.2) make it more deterministic.
* When undefined, the parameter is not sent.
*/
temperature;
constructor(apiKey, endpoint, model, dimensions, temperature) {
super();
this.apiKey = apiKey;
this.endpoint = endpoint;
this.model = model;
this.dimensions = dimensions;
this.temperature = temperature;
}
getBaseEndpointUri() {
let endpoint = this.endpoint;
if (!endpoint.endsWith("/")) {
endpoint += "/";
}
return endpoint;
}
validate(errors) {
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.apiKey)) {
errors.push("Value of 'apiKey' field cannot be empty.");
}
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.endpoint)) {
errors.push("Value of 'endpoint' field cannot be empty.");
}
if (StringUtil_js_1.StringUtil.isNullOrWhitespace(this.model)) {
errors.push("Value of 'model' field cannot be empty.");
}
if (this.dimensions != null && this.dimensions <= 0) {
errors.push("Value of 'dimensions' field must be positive.");
}
if (this.temperature != null && this.temperature < 0) {
errors.push("Value of 'temperature' field must be non-negative.");
}
}
compare(other) {
if (!(other instanceof OpenAiBaseSettings)) {
return AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.All;
}
let differences = AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.None;
if (this.apiKey !== other.apiKey) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.AuthenticationSettings;
}
if (this.endpoint !== other.endpoint) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.EndpointConfiguration;
}
if (this.model !== other.model) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.ModelArchitecture;
}
if (this.dimensions !== other.dimensions) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.EmbeddingDimensions;
}
const hasTemperature = this.temperature != null;
const otherHasTemperature = other.temperature != null;
if (hasTemperature !== otherHasTemperature ||
(hasTemperature && otherHasTemperature &&
Math.abs(this.temperature - other.temperature) > 0.0001)) {
differences |= AiSettingsCompareDifferences_js_1.AiSettingsCompareDifferences.EndpointConfiguration;
}
return differences;
}
}
exports.OpenAiBaseSettings = OpenAiBaseSettings;
//# sourceMappingURL=OpenAiBaseSettings.js.map