ravendb
Version:
RavenDB client for Node.js
90 lines • 3.35 kB
JavaScript
import { AbstractAiSettings } from "./AbstractAiSettings.js";
import { AiSettingsCompareDifferences } from "../AiSettingsCompareDifferences.js";
import { StringUtil } from "../../../../../Utility/StringUtil.js";
/**
* Base settings for OpenAI-compatible providers.
*/
export class OpenAiBaseSettings extends 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.isNullOrWhitespace(this.apiKey)) {
errors.push("Value of 'apiKey' field cannot be empty.");
}
if (StringUtil.isNullOrWhitespace(this.endpoint)) {
errors.push("Value of 'endpoint' field cannot be empty.");
}
if (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.All;
}
let differences = AiSettingsCompareDifferences.None;
if (this.apiKey !== other.apiKey) {
differences |= AiSettingsCompareDifferences.AuthenticationSettings;
}
if (this.endpoint !== other.endpoint) {
differences |= AiSettingsCompareDifferences.EndpointConfiguration;
}
if (this.model !== other.model) {
differences |= AiSettingsCompareDifferences.ModelArchitecture;
}
if (this.dimensions !== other.dimensions) {
differences |= 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.EndpointConfiguration;
}
return differences;
}
}
//# sourceMappingURL=OpenAiBaseSettings.js.map