diff --git a/server/src/main/java/org/elasticsearch/inference/EmptySettingsConfiguration.java b/server/src/main/java/org/elasticsearch/inference/EmptySettingsConfiguration.java deleted file mode 100644 index 8a3f96750f2ea..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/EmptySettingsConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference; - -import java.util.Collections; -import java.util.Map; - -public class EmptySettingsConfiguration { - public static Map get() { - return Collections.emptyMap(); - } -} diff --git a/server/src/main/java/org/elasticsearch/inference/InferenceServiceConfiguration.java b/server/src/main/java/org/elasticsearch/inference/InferenceServiceConfiguration.java index c8bd4f2e27e8b..41cf339c751d1 100644 --- a/server/src/main/java/org/elasticsearch/inference/InferenceServiceConfiguration.java +++ b/server/src/main/java/org/elasticsearch/inference/InferenceServiceConfiguration.java @@ -25,10 +25,12 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; @@ -37,75 +39,88 @@ */ public class InferenceServiceConfiguration implements Writeable, ToXContentObject { - private final String provider; - private final List taskTypes; - private final Map configuration; + private final String service; + private final String name; + private final EnumSet taskTypes; + private final Map configurations; /** * Constructs a new {@link InferenceServiceConfiguration} instance with specified properties. * - * @param provider The name of the service provider. - * @param taskTypes A list of {@link TaskSettingsConfiguration} supported by the service provider. - * @param configuration The configuration of the service provider, defined by {@link SettingsConfiguration}. + * @param service The name of the service provider. + * @param name The user-friendly name of the service provider. + * @param taskTypes A list of {@link TaskType} supported by the service provider. + * @param configurations The configuration of the service provider, defined by {@link SettingsConfiguration}. */ private InferenceServiceConfiguration( - String provider, - List taskTypes, - Map configuration + String service, + String name, + EnumSet taskTypes, + Map configurations ) { - this.provider = provider; + this.service = service; + this.name = name; this.taskTypes = taskTypes; - this.configuration = configuration; + this.configurations = configurations; } public InferenceServiceConfiguration(StreamInput in) throws IOException { - this.provider = in.readString(); - this.taskTypes = in.readCollectionAsList(TaskSettingsConfiguration::new); - this.configuration = in.readMap(SettingsConfiguration::new); + this.service = in.readString(); + this.name = in.readString(); + this.taskTypes = in.readEnumSet(TaskType.class); + this.configurations = in.readMap(SettingsConfiguration::new); } - static final ParseField PROVIDER_FIELD = new ParseField("provider"); + static final ParseField SERVICE_FIELD = new ParseField("service"); + static final ParseField NAME_FIELD = new ParseField("name"); static final ParseField TASK_TYPES_FIELD = new ParseField("task_types"); - static final ParseField CONFIGURATION_FIELD = new ParseField("configuration"); + static final ParseField CONFIGURATIONS_FIELD = new ParseField("configurations"); @SuppressWarnings("unchecked") private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "inference_service_configuration", true, args -> { - List taskTypes = (ArrayList) args[1]; - return new InferenceServiceConfiguration.Builder().setProvider((String) args[0]) - .setTaskTypes((List) args[1]) - .setConfiguration((Map) args[2]) + List taskTypes = (ArrayList) args[2]; + return new InferenceServiceConfiguration.Builder().setService((String) args[0]) + .setName((String) args[1]) + .setTaskTypes(EnumSet.copyOf(taskTypes.stream().map(TaskType::fromString).collect(Collectors.toList()))) + .setConfigurations((Map) args[3]) .build(); } ); static { - PARSER.declareString(constructorArg(), PROVIDER_FIELD); - PARSER.declareObjectArray(constructorArg(), (p, c) -> TaskSettingsConfiguration.fromXContent(p), TASK_TYPES_FIELD); - PARSER.declareObject(constructorArg(), (p, c) -> p.map(), CONFIGURATION_FIELD); + PARSER.declareString(constructorArg(), SERVICE_FIELD); + PARSER.declareString(constructorArg(), NAME_FIELD); + PARSER.declareStringArray(constructorArg(), TASK_TYPES_FIELD); + PARSER.declareObject(constructorArg(), (p, c) -> p.map(), CONFIGURATIONS_FIELD); } - public String getProvider() { - return provider; + public String getService() { + return service; } - public List getTaskTypes() { + public String getName() { + return name; + } + + public EnumSet getTaskTypes() { return taskTypes; } - public Map getConfiguration() { - return configuration; + public Map getConfigurations() { + return configurations; } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); { - builder.field(PROVIDER_FIELD.getPreferredName(), provider); + builder.field(SERVICE_FIELD.getPreferredName(), service); + builder.field(NAME_FIELD.getPreferredName(), name); builder.field(TASK_TYPES_FIELD.getPreferredName(), taskTypes); - builder.field(CONFIGURATION_FIELD.getPreferredName(), configuration); + builder.field(CONFIGURATIONS_FIELD.getPreferredName(), configurations); } builder.endObject(); return builder; @@ -125,17 +140,19 @@ public static InferenceServiceConfiguration fromXContentBytes(BytesReference sou @Override public void writeTo(StreamOutput out) throws IOException { - out.writeString(provider); + out.writeString(service); + out.writeString(name); out.writeCollection(taskTypes); - out.writeMapValues(configuration); + out.writeMapValues(configurations); } public Map toMap() { Map map = new HashMap<>(); - map.put(PROVIDER_FIELD.getPreferredName(), provider); + map.put(SERVICE_FIELD.getPreferredName(), service); + map.put(NAME_FIELD.getPreferredName(), name); map.put(TASK_TYPES_FIELD.getPreferredName(), taskTypes); - map.put(CONFIGURATION_FIELD.getPreferredName(), configuration); + map.put(CONFIGURATIONS_FIELD.getPreferredName(), configurations); return map; } @@ -145,39 +162,46 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; InferenceServiceConfiguration that = (InferenceServiceConfiguration) o; - return provider.equals(that.provider) + return service.equals(that.service) + && name.equals(that.name) && Objects.equals(taskTypes, that.taskTypes) - && Objects.equals(configuration, that.configuration); + && Objects.equals(configurations, that.configurations); } @Override public int hashCode() { - return Objects.hash(provider, taskTypes, configuration); + return Objects.hash(service, name, taskTypes, configurations); } public static class Builder { - private String provider; - private List taskTypes; - private Map configuration; + private String service; + private String name; + private EnumSet taskTypes; + private Map configurations; + + public Builder setService(String service) { + this.service = service; + return this; + } - public Builder setProvider(String provider) { - this.provider = provider; + public Builder setName(String name) { + this.name = name; return this; } - public Builder setTaskTypes(List taskTypes) { + public Builder setTaskTypes(EnumSet taskTypes) { this.taskTypes = taskTypes; return this; } - public Builder setConfiguration(Map configuration) { - this.configuration = configuration; + public Builder setConfigurations(Map configurations) { + this.configurations = configurations; return this; } public InferenceServiceConfiguration build() { - return new InferenceServiceConfiguration(provider, taskTypes, configuration); + return new InferenceServiceConfiguration(service, name, taskTypes, configurations); } } } diff --git a/server/src/main/java/org/elasticsearch/inference/SettingsConfiguration.java b/server/src/main/java/org/elasticsearch/inference/SettingsConfiguration.java index fb97e62f01b19..188b8a7e82b57 100644 --- a/server/src/main/java/org/elasticsearch/inference/SettingsConfiguration.java +++ b/server/src/main/java/org/elasticsearch/inference/SettingsConfiguration.java @@ -16,11 +16,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.core.Nullable; -import org.elasticsearch.inference.configuration.SettingsConfigurationDependency; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; -import org.elasticsearch.inference.configuration.SettingsConfigurationValidation; import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.ParseField; @@ -32,9 +28,7 @@ import org.elasticsearch.xcontent.XContentType; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -47,120 +41,62 @@ */ public class SettingsConfiguration implements Writeable, ToXContentObject { - @Nullable - private final String category; @Nullable private final Object defaultValue; @Nullable - private final List dependsOn; - @Nullable - private final SettingsConfigurationDisplayType display; + private final String description; private final String label; - @Nullable - private final List options; - @Nullable - private final Integer order; - @Nullable - private final String placeholder; private final boolean required; private final boolean sensitive; - @Nullable - private final String tooltip; - @Nullable + private final boolean updatable; private final SettingsConfigurationFieldType type; - @Nullable - private final List uiRestrictions; - @Nullable - private final List validations; - @Nullable - private final Object value; /** * Constructs a new {@link SettingsConfiguration} instance with specified properties. * - * @param category The category of the configuration field. * @param defaultValue The default value for the configuration. - * @param dependsOn A list of {@link SettingsConfigurationDependency} indicating dependencies on other configurations. - * @param display The display type, defined by {@link SettingsConfigurationDisplayType}. + * @param description A description of the configuration. * @param label The display label associated with the config field. - * @param options A list of {@link SettingsConfigurationSelectOption} for selectable options. - * @param order The order in which this configuration appears. - * @param placeholder A placeholder text for the configuration field. * @param required A boolean indicating whether the configuration is required. * @param sensitive A boolean indicating whether the configuration contains sensitive information. - * @param tooltip A tooltip text providing additional information about the configuration. + * @param updatable A boolean indicating whether the configuration can be updated. * @param type The type of the configuration field, defined by {@link SettingsConfigurationFieldType}. - * @param uiRestrictions A list of UI restrictions in string format. - * @param validations A list of {@link SettingsConfigurationValidation} for validating the configuration. - * @param value The current value of the configuration. */ private SettingsConfiguration( - String category, Object defaultValue, - List dependsOn, - SettingsConfigurationDisplayType display, + String description, String label, - List options, - Integer order, - String placeholder, boolean required, boolean sensitive, - String tooltip, - SettingsConfigurationFieldType type, - List uiRestrictions, - List validations, - Object value + boolean updatable, + SettingsConfigurationFieldType type ) { - this.category = category; this.defaultValue = defaultValue; - this.dependsOn = dependsOn; - this.display = display; + this.description = description; this.label = label; - this.options = options; - this.order = order; - this.placeholder = placeholder; this.required = required; this.sensitive = sensitive; - this.tooltip = tooltip; + this.updatable = updatable; this.type = type; - this.uiRestrictions = uiRestrictions; - this.validations = validations; - this.value = value; } public SettingsConfiguration(StreamInput in) throws IOException { - this.category = in.readString(); this.defaultValue = in.readGenericValue(); - this.dependsOn = in.readOptionalCollectionAsList(SettingsConfigurationDependency::new); - this.display = in.readEnum(SettingsConfigurationDisplayType.class); + this.description = in.readOptionalString(); this.label = in.readString(); - this.options = in.readOptionalCollectionAsList(SettingsConfigurationSelectOption::new); - this.order = in.readOptionalInt(); - this.placeholder = in.readOptionalString(); this.required = in.readBoolean(); this.sensitive = in.readBoolean(); - this.tooltip = in.readOptionalString(); + this.updatable = in.readBoolean(); this.type = in.readEnum(SettingsConfigurationFieldType.class); - this.uiRestrictions = in.readOptionalStringCollectionAsList(); - this.validations = in.readOptionalCollectionAsList(SettingsConfigurationValidation::new); - this.value = in.readGenericValue(); } - static final ParseField CATEGORY_FIELD = new ParseField("category"); static final ParseField DEFAULT_VALUE_FIELD = new ParseField("default_value"); - static final ParseField DEPENDS_ON_FIELD = new ParseField("depends_on"); - static final ParseField DISPLAY_FIELD = new ParseField("display"); + static final ParseField DESCRIPTION_FIELD = new ParseField("description"); static final ParseField LABEL_FIELD = new ParseField("label"); - static final ParseField OPTIONS_FIELD = new ParseField("options"); - static final ParseField ORDER_FIELD = new ParseField("order"); - static final ParseField PLACEHOLDER_FIELD = new ParseField("placeholder"); static final ParseField REQUIRED_FIELD = new ParseField("required"); static final ParseField SENSITIVE_FIELD = new ParseField("sensitive"); - static final ParseField TOOLTIP_FIELD = new ParseField("tooltip"); + static final ParseField UPDATABLE_FIELD = new ParseField("updatable"); static final ParseField TYPE_FIELD = new ParseField("type"); - static final ParseField UI_RESTRICTIONS_FIELD = new ParseField("ui_restrictions"); - static final ParseField VALIDATIONS_FIELD = new ParseField("validations"); - static final ParseField VALUE_FIELD = new ParseField("value"); @SuppressWarnings("unchecked") private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( @@ -168,27 +104,18 @@ public SettingsConfiguration(StreamInput in) throws IOException { true, args -> { int i = 0; - return new SettingsConfiguration.Builder().setCategory((String) args[i++]) - .setDefaultValue(args[i++]) - .setDependsOn((List) args[i++]) - .setDisplay((SettingsConfigurationDisplayType) args[i++]) + return new SettingsConfiguration.Builder().setDefaultValue(args[i++]) + .setDescription((String) args[i++]) .setLabel((String) args[i++]) - .setOptions((List) args[i++]) - .setOrder((Integer) args[i++]) - .setPlaceholder((String) args[i++]) .setRequired((Boolean) args[i++]) .setSensitive((Boolean) args[i++]) - .setTooltip((String) args[i++]) + .setUpdatable((Boolean) args[i++]) .setType((SettingsConfigurationFieldType) args[i++]) - .setUiRestrictions((List) args[i++]) - .setValidations((List) args[i++]) - .setValue(args[i]) .build(); } ); static { - PARSER.declareString(optionalConstructorArg(), CATEGORY_FIELD); PARSER.declareField(optionalConstructorArg(), (p, c) -> { if (p.currentToken() == XContentParser.Token.VALUE_STRING) { return p.text(); @@ -201,68 +128,31 @@ public SettingsConfiguration(StreamInput in) throws IOException { } throw new XContentParseException("Unsupported token [" + p.currentToken() + "]"); }, DEFAULT_VALUE_FIELD, ObjectParser.ValueType.VALUE); - PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> SettingsConfigurationDependency.fromXContent(p), DEPENDS_ON_FIELD); - PARSER.declareField( - optionalConstructorArg(), - (p, c) -> SettingsConfigurationDisplayType.displayType(p.text()), - DISPLAY_FIELD, - ObjectParser.ValueType.STRING_OR_NULL - ); + PARSER.declareStringOrNull(optionalConstructorArg(), DESCRIPTION_FIELD); PARSER.declareString(constructorArg(), LABEL_FIELD); - PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> SettingsConfigurationSelectOption.fromXContent(p), OPTIONS_FIELD); - PARSER.declareInt(optionalConstructorArg(), ORDER_FIELD); - PARSER.declareStringOrNull(optionalConstructorArg(), PLACEHOLDER_FIELD); PARSER.declareBoolean(optionalConstructorArg(), REQUIRED_FIELD); PARSER.declareBoolean(optionalConstructorArg(), SENSITIVE_FIELD); - PARSER.declareStringOrNull(optionalConstructorArg(), TOOLTIP_FIELD); + PARSER.declareBoolean(optionalConstructorArg(), UPDATABLE_FIELD); PARSER.declareField( optionalConstructorArg(), (p, c) -> p.currentToken() == XContentParser.Token.VALUE_NULL ? null : SettingsConfigurationFieldType.fieldType(p.text()), TYPE_FIELD, ObjectParser.ValueType.STRING_OR_NULL ); - PARSER.declareStringArray(optionalConstructorArg(), UI_RESTRICTIONS_FIELD); - PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> SettingsConfigurationValidation.fromXContent(p), VALIDATIONS_FIELD); - PARSER.declareField( - optionalConstructorArg(), - (p, c) -> parseConfigurationValue(p), - VALUE_FIELD, - ObjectParser.ValueType.VALUE_OBJECT_ARRAY - ); - } - - public String getCategory() { - return category; } public Object getDefaultValue() { return defaultValue; } - public List getDependsOn() { - return dependsOn; - } - - public SettingsConfigurationDisplayType getDisplay() { - return display; + public String getDescription() { + return description; } public String getLabel() { return label; } - public List getOptions() { - return options; - } - - public Integer getOrder() { - return order; - } - - public String getPlaceholder() { - return placeholder; - } - public boolean isRequired() { return required; } @@ -271,26 +161,14 @@ public boolean isSensitive() { return sensitive; } - public String getTooltip() { - return tooltip; + public boolean isUpdatable() { + return updatable; } public SettingsConfigurationFieldType getType() { return type; } - public List getUiRestrictions() { - return uiRestrictions; - } - - public List getValidations() { - return validations; - } - - public Object getValue() { - return value; - } - /** * Parses a configuration value from a parser context. * This method can parse strings, numbers, booleans, objects, and null values, matching the types commonly @@ -319,47 +197,20 @@ public static Object parseConfigurationValue(XContentParser p) throws IOExceptio public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); { - if (category != null) { - builder.field(CATEGORY_FIELD.getPreferredName(), category); - } - builder.field(DEFAULT_VALUE_FIELD.getPreferredName(), defaultValue); - if (dependsOn != null) { - builder.xContentList(DEPENDS_ON_FIELD.getPreferredName(), dependsOn); - } else { - builder.xContentList(DEPENDS_ON_FIELD.getPreferredName(), new ArrayList<>()); + if (defaultValue != null) { + builder.field(DEFAULT_VALUE_FIELD.getPreferredName(), defaultValue); } - if (display != null) { - builder.field(DISPLAY_FIELD.getPreferredName(), display.toString()); + if (description != null) { + builder.field(DESCRIPTION_FIELD.getPreferredName(), description); } builder.field(LABEL_FIELD.getPreferredName(), label); - if (options != null) { - builder.xContentList(OPTIONS_FIELD.getPreferredName(), options); - } - if (order != null) { - builder.field(ORDER_FIELD.getPreferredName(), order); - } - if (placeholder != null) { - builder.field(PLACEHOLDER_FIELD.getPreferredName(), placeholder); - } builder.field(REQUIRED_FIELD.getPreferredName(), required); builder.field(SENSITIVE_FIELD.getPreferredName(), sensitive); - if (tooltip != null) { - builder.field(TOOLTIP_FIELD.getPreferredName(), tooltip); - } + builder.field(UPDATABLE_FIELD.getPreferredName(), updatable); + if (type != null) { builder.field(TYPE_FIELD.getPreferredName(), type.toString()); } - if (uiRestrictions != null) { - builder.stringListField(UI_RESTRICTIONS_FIELD.getPreferredName(), uiRestrictions); - } else { - builder.stringListField(UI_RESTRICTIONS_FIELD.getPreferredName(), new ArrayList<>()); - } - if (validations != null) { - builder.xContentList(VALIDATIONS_FIELD.getPreferredName(), validations); - } else { - builder.xContentList(VALIDATIONS_FIELD.getPreferredName(), new ArrayList<>()); - } - builder.field(VALUE_FIELD.getPreferredName(), value); } builder.endObject(); return builder; @@ -379,57 +230,29 @@ public static SettingsConfiguration fromXContentBytes(BytesReference source, XCo @Override public void writeTo(StreamOutput out) throws IOException { - out.writeString(category); out.writeGenericValue(defaultValue); - out.writeOptionalCollection(dependsOn); - out.writeEnum(display); + out.writeOptionalString(description); out.writeString(label); - out.writeOptionalCollection(options); - out.writeOptionalInt(order); - out.writeOptionalString(placeholder); out.writeBoolean(required); out.writeBoolean(sensitive); - out.writeOptionalString(tooltip); + out.writeBoolean(updatable); out.writeEnum(type); - out.writeOptionalStringCollection(uiRestrictions); - out.writeOptionalCollection(validations); - out.writeGenericValue(value); } public Map toMap() { Map map = new HashMap<>(); - Optional.ofNullable(category).ifPresent(c -> map.put(CATEGORY_FIELD.getPreferredName(), c)); map.put(DEFAULT_VALUE_FIELD.getPreferredName(), defaultValue); - - Optional.ofNullable(dependsOn) - .ifPresent(d -> map.put(DEPENDS_ON_FIELD.getPreferredName(), d.stream().map(SettingsConfigurationDependency::toMap).toList())); - - Optional.ofNullable(display).ifPresent(d -> map.put(DISPLAY_FIELD.getPreferredName(), d.toString())); + Optional.ofNullable(description).ifPresent(t -> map.put(DESCRIPTION_FIELD.getPreferredName(), t)); map.put(LABEL_FIELD.getPreferredName(), label); - Optional.ofNullable(options) - .ifPresent(o -> map.put(OPTIONS_FIELD.getPreferredName(), o.stream().map(SettingsConfigurationSelectOption::toMap).toList())); - - Optional.ofNullable(order).ifPresent(o -> map.put(ORDER_FIELD.getPreferredName(), o)); - - Optional.ofNullable(placeholder).ifPresent(p -> map.put(PLACEHOLDER_FIELD.getPreferredName(), p)); - map.put(REQUIRED_FIELD.getPreferredName(), required); map.put(SENSITIVE_FIELD.getPreferredName(), sensitive); - - Optional.ofNullable(tooltip).ifPresent(t -> map.put(TOOLTIP_FIELD.getPreferredName(), t)); + map.put(UPDATABLE_FIELD.getPreferredName(), updatable); Optional.ofNullable(type).ifPresent(t -> map.put(TYPE_FIELD.getPreferredName(), t.toString())); - Optional.ofNullable(uiRestrictions).ifPresent(u -> map.put(UI_RESTRICTIONS_FIELD.getPreferredName(), u)); - - Optional.ofNullable(validations) - .ifPresent(v -> map.put(VALIDATIONS_FIELD.getPreferredName(), v.stream().map(SettingsConfigurationValidation::toMap).toList())); - - map.put(VALUE_FIELD.getPreferredName(), value); - return map; } @@ -440,77 +263,35 @@ public boolean equals(Object o) { SettingsConfiguration that = (SettingsConfiguration) o; return required == that.required && sensitive == that.sensitive - && Objects.equals(category, that.category) + && updatable == that.updatable && Objects.equals(defaultValue, that.defaultValue) - && Objects.equals(dependsOn, that.dependsOn) - && display == that.display + && Objects.equals(description, that.description) && Objects.equals(label, that.label) - && Objects.equals(options, that.options) - && Objects.equals(order, that.order) - && Objects.equals(placeholder, that.placeholder) - && Objects.equals(tooltip, that.tooltip) - && type == that.type - && Objects.equals(uiRestrictions, that.uiRestrictions) - && Objects.equals(validations, that.validations) - && Objects.equals(value, that.value); + && type == that.type; } @Override public int hashCode() { - return Objects.hash( - category, - defaultValue, - dependsOn, - display, - label, - options, - order, - placeholder, - required, - sensitive, - tooltip, - type, - uiRestrictions, - validations, - value - ); + return Objects.hash(defaultValue, description, label, required, sensitive, updatable, type); } public static class Builder { - private String category; private Object defaultValue; - private List dependsOn; - private SettingsConfigurationDisplayType display; + private String description; private String label; - private List options; - private Integer order; - private String placeholder; private boolean required; private boolean sensitive; - private String tooltip; + private boolean updatable; private SettingsConfigurationFieldType type; - private List uiRestrictions; - private List validations; - private Object value; - - public Builder setCategory(String category) { - this.category = category; - return this; - } public Builder setDefaultValue(Object defaultValue) { this.defaultValue = defaultValue; return this; } - public Builder setDependsOn(List dependsOn) { - this.dependsOn = dependsOn; - return this; - } - - public Builder setDisplay(SettingsConfigurationDisplayType display) { - this.display = display; + public Builder setDescription(String description) { + this.description = description; return this; } @@ -519,21 +300,6 @@ public Builder setLabel(String label) { return this; } - public Builder setOptions(List options) { - this.options = options; - return this; - } - - public Builder setOrder(Integer order) { - this.order = order; - return this; - } - - public Builder setPlaceholder(String placeholder) { - this.placeholder = placeholder; - return this; - } - public Builder setRequired(Boolean required) { this.required = Objects.requireNonNullElse(required, false); return this; @@ -544,8 +310,8 @@ public Builder setSensitive(Boolean sensitive) { return this; } - public Builder setTooltip(String tooltip) { - this.tooltip = tooltip; + public Builder setUpdatable(Boolean updatable) { + this.updatable = Objects.requireNonNullElse(updatable, false); return this; } @@ -554,39 +320,8 @@ public Builder setType(SettingsConfigurationFieldType type) { return this; } - public Builder setUiRestrictions(List uiRestrictions) { - this.uiRestrictions = uiRestrictions; - return this; - } - - public Builder setValidations(List validations) { - this.validations = validations; - return this; - } - - public Builder setValue(Object value) { - this.value = value; - return this; - } - public SettingsConfiguration build() { - return new SettingsConfiguration( - category, - defaultValue, - dependsOn, - display, - label, - options, - order, - placeholder, - required, - sensitive, - tooltip, - type, - uiRestrictions, - validations, - value - ); + return new SettingsConfiguration(defaultValue, description, label, required, sensitive, updatable, type); } } } diff --git a/server/src/main/java/org/elasticsearch/inference/TaskSettingsConfiguration.java b/server/src/main/java/org/elasticsearch/inference/TaskSettingsConfiguration.java deleted file mode 100644 index 150532f138e8d..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/TaskSettingsConfiguration.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference; - -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xcontent.XContentParserConfiguration; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; - -/** - * Represents the configuration field settings for a specific task type inference provider. - */ -public class TaskSettingsConfiguration implements Writeable, ToXContentObject { - - private final TaskType taskType; - private final Map configuration; - - /** - * Constructs a new {@link TaskSettingsConfiguration} instance with specified properties. - * - * @param taskType The {@link TaskType} this configuration describes. - * @param configuration The configuration of the task, defined by {@link SettingsConfiguration}. - */ - private TaskSettingsConfiguration(TaskType taskType, Map configuration) { - this.taskType = taskType; - this.configuration = configuration; - } - - public TaskSettingsConfiguration(StreamInput in) throws IOException { - this.taskType = in.readEnum(TaskType.class); - this.configuration = in.readMap(SettingsConfiguration::new); - } - - static final ParseField TASK_TYPE_FIELD = new ParseField("task_type"); - static final ParseField CONFIGURATION_FIELD = new ParseField("configuration"); - - @SuppressWarnings("unchecked") - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "task_configuration", - true, - args -> { - return new TaskSettingsConfiguration.Builder().setTaskType(TaskType.fromString((String) args[0])) - .setConfiguration((Map) args[1]) - .build(); - } - ); - - static { - PARSER.declareString(constructorArg(), TASK_TYPE_FIELD); - PARSER.declareObject(constructorArg(), (p, c) -> p.map(), CONFIGURATION_FIELD); - } - - public TaskType getTaskType() { - return taskType; - } - - public Map getConfiguration() { - return configuration; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(TASK_TYPE_FIELD.getPreferredName(), taskType); - builder.field(CONFIGURATION_FIELD.getPreferredName(), configuration); - } - builder.endObject(); - return builder; - } - - public static TaskSettingsConfiguration fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - public static TaskSettingsConfiguration fromXContentBytes(BytesReference source, XContentType xContentType) { - try (XContentParser parser = XContentHelper.createParser(XContentParserConfiguration.EMPTY, source, xContentType)) { - return TaskSettingsConfiguration.fromXContent(parser); - } catch (IOException e) { - throw new ElasticsearchParseException("failed to parse task configuration", e); - } - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeEnum(taskType); - out.writeMapValues(configuration); - } - - public Map toMap() { - Map map = new HashMap<>(); - - map.put(TASK_TYPE_FIELD.getPreferredName(), taskType); - map.put(CONFIGURATION_FIELD.getPreferredName(), configuration); - - return map; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TaskSettingsConfiguration that = (TaskSettingsConfiguration) o; - return Objects.equals(taskType, that.taskType) && Objects.equals(configuration, that.configuration); - } - - @Override - public int hashCode() { - return Objects.hash(taskType, configuration); - } - - public static class Builder { - - private TaskType taskType; - private Map configuration; - - public Builder setTaskType(TaskType taskType) { - this.taskType = taskType; - return this; - } - - public Builder setConfiguration(Map configuration) { - this.configuration = configuration; - return this; - } - - public TaskSettingsConfiguration build() { - return new TaskSettingsConfiguration(taskType, configuration); - } - } -} diff --git a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationDependency.java b/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationDependency.java deleted file mode 100644 index d319d1a395f85..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationDependency.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParseException; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; - -/** - * Represents a dependency within a connector configuration, defining a specific field and its associated value. - * This class is used to encapsulate configuration dependencies in a structured format. - */ -public class SettingsConfigurationDependency implements Writeable, ToXContentObject { - - private final String field; - private final Object value; - - /** - * Constructs a new instance of SettingsConfigurationDependency. - * - * @param field The name of the field in the service dependency. - * @param value The value associated with the field. - */ - public SettingsConfigurationDependency(String field, Object value) { - this.field = field; - this.value = value; - } - - public SettingsConfigurationDependency(StreamInput in) throws IOException { - this.field = in.readString(); - this.value = in.readGenericValue(); - } - - private static final ParseField FIELD_FIELD = new ParseField("field"); - private static final ParseField VALUE_FIELD = new ParseField("value"); - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "service_configuration_dependency", - true, - args -> new SettingsConfigurationDependency.Builder().setField((String) args[0]).setValue(args[1]).build() - ); - - static { - PARSER.declareString(constructorArg(), FIELD_FIELD); - PARSER.declareField(constructorArg(), (p, c) -> { - if (p.currentToken() == XContentParser.Token.VALUE_STRING) { - return p.text(); - } else if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return p.numberValue(); - } else if (p.currentToken() == XContentParser.Token.VALUE_BOOLEAN) { - return p.booleanValue(); - } else if (p.currentToken() == XContentParser.Token.VALUE_NULL) { - return null; - } - throw new XContentParseException("Unsupported token [" + p.currentToken() + "]"); - }, VALUE_FIELD, ObjectParser.ValueType.VALUE); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(FIELD_FIELD.getPreferredName(), field); - builder.field(VALUE_FIELD.getPreferredName(), value); - } - builder.endObject(); - return builder; - } - - public Map toMap() { - Map map = new HashMap<>(); - map.put(FIELD_FIELD.getPreferredName(), field); - map.put(VALUE_FIELD.getPreferredName(), value); - return map; - } - - public static SettingsConfigurationDependency fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(field); - out.writeGenericValue(value); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SettingsConfigurationDependency that = (SettingsConfigurationDependency) o; - return Objects.equals(field, that.field) && Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(field, value); - } - - public static class Builder { - - private String field; - private Object value; - - public Builder setField(String field) { - this.field = field; - return this; - } - - public Builder setValue(Object value) { - this.value = value; - return this; - } - - public SettingsConfigurationDependency build() { - return new SettingsConfigurationDependency(field, value); - } - } -} diff --git a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationDisplayType.java b/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationDisplayType.java deleted file mode 100644 index e072238a52d01..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationDisplayType.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import java.util.Locale; - -public enum SettingsConfigurationDisplayType { - TEXT, - TEXTBOX, - TEXTAREA, - NUMERIC, - TOGGLE, - DROPDOWN; - - @Override - public String toString() { - return name().toLowerCase(Locale.ROOT); - } - - public static SettingsConfigurationDisplayType displayType(String type) { - for (SettingsConfigurationDisplayType displayType : SettingsConfigurationDisplayType.values()) { - if (displayType.name().equalsIgnoreCase(type)) { - return displayType; - } - } - throw new IllegalArgumentException("Unknown " + SettingsConfigurationDisplayType.class.getSimpleName() + " [" + type + "]."); - } -} diff --git a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationSelectOption.java b/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationSelectOption.java deleted file mode 100644 index 8ad8d561da58e..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationSelectOption.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParseException; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; - -public class SettingsConfigurationSelectOption implements Writeable, ToXContentObject { - private final String label; - private final Object value; - - private SettingsConfigurationSelectOption(String label, Object value) { - this.label = label; - this.value = value; - } - - public SettingsConfigurationSelectOption(StreamInput in) throws IOException { - this.label = in.readString(); - this.value = in.readGenericValue(); - } - - private static final ParseField LABEL_FIELD = new ParseField("label"); - private static final ParseField VALUE_FIELD = new ParseField("value"); - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "service_configuration_select_option", - true, - args -> new SettingsConfigurationSelectOption.Builder().setLabel((String) args[0]).setValue(args[1]).build() - ); - - static { - PARSER.declareString(constructorArg(), LABEL_FIELD); - PARSER.declareField(constructorArg(), (p, c) -> { - if (p.currentToken() == XContentParser.Token.VALUE_STRING) { - return p.text(); - } else if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return p.numberValue(); - } - throw new XContentParseException("Unsupported token [" + p.currentToken() + "]"); - }, VALUE_FIELD, ObjectParser.ValueType.VALUE); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(LABEL_FIELD.getPreferredName(), label); - builder.field(VALUE_FIELD.getPreferredName(), value); - } - builder.endObject(); - return builder; - } - - public Map toMap() { - Map map = new HashMap<>(); - map.put(LABEL_FIELD.getPreferredName(), label); - map.put(VALUE_FIELD.getPreferredName(), value); - return map; - } - - public static SettingsConfigurationSelectOption fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(label); - out.writeGenericValue(value); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SettingsConfigurationSelectOption that = (SettingsConfigurationSelectOption) o; - return Objects.equals(label, that.label) && Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(label, value); - } - - public static class Builder { - - private String label; - private Object value; - - public Builder setLabel(String label) { - this.label = label; - return this; - } - - public Builder setValue(Object value) { - this.value = value; - return this; - } - - public Builder setLabelAndValue(String labelAndValue) { - this.label = labelAndValue; - this.value = labelAndValue; - return this; - } - - public SettingsConfigurationSelectOption build() { - return new SettingsConfigurationSelectOption(label, value); - } - } - -} diff --git a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidation.java b/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidation.java deleted file mode 100644 index f106442d6d4ac..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidation.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParseException; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; - -/** - * Represents a configuration validation entity, encapsulating a validation constraint and its corresponding type. - * This class is used to define and handle specific validation rules or requirements within a configuration context. - */ -public class SettingsConfigurationValidation implements Writeable, ToXContentObject { - - private final Object constraint; - private final SettingsConfigurationValidationType type; - - /** - * Constructs a new SettingsConfigurationValidation instance with specified constraint and type. - * This constructor initializes the object with a given validation constraint and its associated validation type. - * - * @param constraint The validation constraint (string, number or list), represented as generic Object type. - * @param type The type of configuration validation, specified as an instance of {@link SettingsConfigurationValidationType}. - */ - private SettingsConfigurationValidation(Object constraint, SettingsConfigurationValidationType type) { - this.constraint = constraint; - this.type = type; - } - - public SettingsConfigurationValidation(StreamInput in) throws IOException { - this.constraint = in.readGenericValue(); - this.type = in.readEnum(SettingsConfigurationValidationType.class); - } - - private static final ParseField CONSTRAINT_FIELD = new ParseField("constraint"); - private static final ParseField TYPE_FIELD = new ParseField("type"); - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "service_configuration_validation", - true, - args -> new SettingsConfigurationValidation.Builder().setConstraint(args[0]) - .setType((SettingsConfigurationValidationType) args[1]) - .build() - ); - - static { - PARSER.declareField( - constructorArg(), - (p, c) -> parseConstraintValue(p), - CONSTRAINT_FIELD, - ObjectParser.ValueType.VALUE_OBJECT_ARRAY - ); - PARSER.declareField( - constructorArg(), - (p, c) -> SettingsConfigurationValidationType.validationType(p.text()), - TYPE_FIELD, - ObjectParser.ValueType.STRING - ); - } - - /** - * Parses the value of a constraint from the XContentParser stream. - * This method is designed to handle various types of constraint values as per the connector's protocol original specification. - * The constraints can be of type string, number, or list of values. - */ - private static Object parseConstraintValue(XContentParser p) throws IOException { - if (p.currentToken() == XContentParser.Token.VALUE_STRING) { - return p.text(); - } else if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return p.numberValue(); - } else if (p.currentToken() == XContentParser.Token.START_ARRAY) { - return p.list(); - } - throw new XContentParseException("Unsupported token [" + p.currentToken() + "]"); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - { - builder.field(CONSTRAINT_FIELD.getPreferredName(), constraint); - builder.field(TYPE_FIELD.getPreferredName(), type.toString()); - } - builder.endObject(); - return builder; - } - - public Map toMap() { - return Map.of(CONSTRAINT_FIELD.getPreferredName(), constraint, TYPE_FIELD.getPreferredName(), type.toString()); - } - - public static SettingsConfigurationValidation fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeGenericValue(constraint); - out.writeEnum(type); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SettingsConfigurationValidation that = (SettingsConfigurationValidation) o; - return Objects.equals(constraint, that.constraint) && type == that.type; - } - - @Override - public int hashCode() { - return Objects.hash(constraint, type); - } - - public static class Builder { - - private Object constraint; - private SettingsConfigurationValidationType type; - - public Builder setConstraint(Object constraint) { - this.constraint = constraint; - return this; - } - - public Builder setType(SettingsConfigurationValidationType type) { - this.type = type; - return this; - } - - public SettingsConfigurationValidation build() { - return new SettingsConfigurationValidation(constraint, type); - } - } -} diff --git a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidationType.java b/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidationType.java deleted file mode 100644 index 6fb07d38d7db5..0000000000000 --- a/server/src/main/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidationType.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import java.util.Locale; - -public enum SettingsConfigurationValidationType { - LESS_THAN, - GREATER_THAN, - LIST_TYPE, - INCLUDED_IN, - REGEX; - - @Override - public String toString() { - return name().toLowerCase(Locale.ROOT); - } - - public static SettingsConfigurationValidationType validationType(String type) { - for (SettingsConfigurationValidationType displayType : SettingsConfigurationValidationType.values()) { - if (displayType.name().equalsIgnoreCase(type)) { - return displayType; - } - } - throw new IllegalArgumentException("Unknown " + SettingsConfigurationValidationType.class.getSimpleName() + " [" + type + "]."); - } -} diff --git a/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTestUtils.java b/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTestUtils.java index 8d145202f7165..2d7fe0dcb5558 100644 --- a/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTestUtils.java +++ b/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTestUtils.java @@ -9,8 +9,8 @@ package org.elasticsearch.inference; +import java.util.EnumSet; import java.util.HashMap; -import java.util.List; import java.util.Map; import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength; @@ -19,14 +19,16 @@ public class InferenceServiceConfigurationTestUtils { public static InferenceServiceConfiguration getRandomServiceConfigurationField() { - return new InferenceServiceConfiguration.Builder().setProvider(randomAlphaOfLength(10)) - .setTaskTypes(getRandomTaskTypeConfiguration()) - .setConfiguration(getRandomServiceConfiguration(10)) + return new InferenceServiceConfiguration.Builder().setService(randomAlphaOfLength(10)) + .setName(randomAlphaOfLength(6)) + .setTaskTypes(getRandomTaskTypes()) + .setConfigurations(getRandomServiceConfiguration(10)) .build(); } - private static List getRandomTaskTypeConfiguration() { - return List.of(TaskSettingsConfigurationTestUtils.getRandomTaskSettingsConfigurationField()); + private static EnumSet getRandomTaskTypes() { + TaskType[] values = TaskType.values(); + return EnumSet.of(values[randomInt(values.length - 1)]); } private static Map getRandomServiceConfiguration(int numFields) { diff --git a/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTests.java b/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTests.java index 7d97f85360c57..490ed68ab3e66 100644 --- a/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTests.java +++ b/server/src/test/java/org/elasticsearch/inference/InferenceServiceConfigurationTests.java @@ -28,139 +28,26 @@ public class InferenceServiceConfigurationTests extends ESTestCase { public void testToXContent() throws IOException { String content = XContentHelper.stripWhitespace(""" { - "provider": "some_provider", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { + "service": "some_provider", + "name": "Some Provider", + "task_types": ["text_embedding", "completion"], + "configurations": { "text_field_configuration": { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", + "description": "Wow, this tooltip is useful.", "label": "Very important field", - "options": [], - "order": 4, "required": true, "sensitive": true, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": null, - "value": "" + "updatable": false, + "type": "str" }, "numeric_field_configuration": { "default_value": 3, - "depends_on": null, - "display": "numeric", + "description": "Wow, this tooltip is useful.", "label": "Very important numeric field", - "options": [], - "order": 2, "required": true, "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "int", - "ui_restrictions": [], - "validations": [ - { - "constraint": 0, - "type": "greater_than" - } - ], - "value": "" - } - } - }, - { - "task_type": "completion", - "configuration": { - "text_field_configuration": { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", - "label": "Very important field", - "options": [], - "order": 4, - "required": true, - "sensitive": true, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": null, - "value": "" - }, - "numeric_field_configuration": { - "default_value": 3, - "depends_on": null, - "display": "numeric", - "label": "Very important numeric field", - "options": [], - "order": 2, - "required": true, - "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "int", - "ui_restrictions": [], - "validations": [ - { - "constraint": 0, - "type": "greater_than" - } - ], - "value": "" - } - } - } - ], - "configuration": { - "text_field_configuration": { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", - "label": "Very important field", - "options": [], - "order": 4, - "required": true, - "sensitive": true, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": null, - "value": "" - }, - "numeric_field_configuration": { - "default_value": 3, - "depends_on": null, - "display": "numeric", - "label": "Very important numeric field", - "options": [], - "order": 2, - "required": true, - "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "int", - "ui_restrictions": [], - "validations": [ - { - "constraint": 0, - "type": "greater_than" - } - ], - "value": "" + "updatable": true, + "type": "int" } } } @@ -183,8 +70,9 @@ public void testToMap() { InferenceServiceConfiguration configField = InferenceServiceConfigurationTestUtils.getRandomServiceConfigurationField(); Map configFieldAsMap = configField.toMap(); - assertThat(configFieldAsMap.get("provider"), equalTo(configField.getProvider())); + assertThat(configFieldAsMap.get("service"), equalTo(configField.getService())); + assertThat(configFieldAsMap.get("name"), equalTo(configField.getName())); assertThat(configFieldAsMap.get("task_types"), equalTo(configField.getTaskTypes())); - assertThat(configFieldAsMap.get("configuration"), equalTo(configField.getConfiguration())); + assertThat(configFieldAsMap.get("configurations"), equalTo(configField.getConfigurations())); } } diff --git a/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTestUtils.java b/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTestUtils.java index 728dafc5383c1..ed78baeb9abe6 100644 --- a/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTestUtils.java +++ b/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTestUtils.java @@ -9,14 +9,7 @@ package org.elasticsearch.inference; -import org.elasticsearch.inference.configuration.SettingsConfigurationDependency; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; -import org.elasticsearch.inference.configuration.SettingsConfigurationValidation; -import org.elasticsearch.inference.configuration.SettingsConfigurationValidationType; - -import java.util.List; import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength; import static org.elasticsearch.test.ESTestCase.randomBoolean; @@ -25,50 +18,18 @@ public class SettingsConfigurationTestUtils { public static SettingsConfiguration getRandomSettingsConfigurationField() { - return new SettingsConfiguration.Builder().setCategory(randomAlphaOfLength(10)) - .setDefaultValue(randomAlphaOfLength(10)) - .setDependsOn(List.of(getRandomSettingsConfigurationDependency())) - .setDisplay(getRandomSettingsConfigurationDisplayType()) + return new SettingsConfiguration.Builder().setDefaultValue(randomAlphaOfLength(10)) + .setDescription(randomAlphaOfLength(10)) .setLabel(randomAlphaOfLength(10)) - .setOptions(List.of(getRandomSettingsConfigurationSelectOption(), getRandomSettingsConfigurationSelectOption())) - .setOrder(randomInt()) - .setPlaceholder(randomAlphaOfLength(10)) .setRequired(randomBoolean()) .setSensitive(randomBoolean()) - .setTooltip(randomAlphaOfLength(10)) + .setUpdatable(randomBoolean()) .setType(getRandomConfigurationFieldType()) - .setUiRestrictions(List.of(randomAlphaOfLength(10), randomAlphaOfLength(10))) - .setValidations(List.of(getRandomSettingsConfigurationValidation())) - .setValue(randomAlphaOfLength(10)) - .build(); - } - - private static SettingsConfigurationDependency getRandomSettingsConfigurationDependency() { - return new SettingsConfigurationDependency.Builder().setField(randomAlphaOfLength(10)).setValue(randomAlphaOfLength(10)).build(); - } - - private static SettingsConfigurationSelectOption getRandomSettingsConfigurationSelectOption() { - return new SettingsConfigurationSelectOption.Builder().setLabel(randomAlphaOfLength(10)).setValue(randomAlphaOfLength(10)).build(); - } - - private static SettingsConfigurationValidation getRandomSettingsConfigurationValidation() { - return new SettingsConfigurationValidation.Builder().setConstraint(randomAlphaOfLength(10)) - .setType(getRandomConfigurationValidationType()) .build(); } - public static SettingsConfigurationDisplayType getRandomSettingsConfigurationDisplayType() { - SettingsConfigurationDisplayType[] values = SettingsConfigurationDisplayType.values(); - return values[randomInt(values.length - 1)]; - } - public static SettingsConfigurationFieldType getRandomConfigurationFieldType() { SettingsConfigurationFieldType[] values = SettingsConfigurationFieldType.values(); return values[randomInt(values.length - 1)]; } - - public static SettingsConfigurationValidationType getRandomConfigurationValidationType() { - SettingsConfigurationValidationType[] values = SettingsConfigurationValidationType.values(); - return values[randomInt(values.length - 1)]; - } } diff --git a/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTests.java b/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTests.java index e1293366a1152..551a25fe52f18 100644 --- a/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTests.java +++ b/server/src/test/java/org/elasticsearch/inference/SettingsConfigurationTests.java @@ -12,16 +12,12 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.inference.configuration.SettingsConfigurationDependency; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; -import org.elasticsearch.inference.configuration.SettingsConfigurationValidation; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentType; import java.io.IOException; -import java.util.List; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentHelper.toXContent; @@ -33,29 +29,12 @@ public class SettingsConfigurationTests extends ESTestCase { public void testToXContent() throws IOException { String content = XContentHelper.stripWhitespace(""" { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", + "description": "Wow, this tooltip is useful.", "label": "Very important field", - "options": [], - "order": 4, "required": true, "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": [ - { - "constraint": 0, - "type": "greater_than" - } - ], - "value": "" + "updatable": true, + "type": "str" } """); @@ -72,38 +51,12 @@ public void testToXContent() throws IOException { public void testToXContent_WithNumericSelectOptions() throws IOException { String content = XContentHelper.stripWhitespace(""" { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", + "description": "Wow, this tooltip is useful.", "label": "Very important field", - "options": [ - { - "label": "five", - "value": 5 - }, - { - "label": "ten", - "value": 10 - } - ], - "order": 4, "required": true, "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": [ - { - "constraint": 0, - "type": "greater_than" - } - ], - "value": "" + "updatable": true, + "type": "str" } """); @@ -135,153 +88,28 @@ public void testToXContentCrawlerConfig_WithNullValue() throws IOException { assertToXContentEquivalent(originalBytes, toXContent(parsed, XContentType.JSON, humanReadable), XContentType.JSON); } - public void testToXContentWithMultipleConstraintTypes() throws IOException { - String content = XContentHelper.stripWhitespace(""" - { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", - "label": "Very important field", - "options": [], - "order": 4, - "required": true, - "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": [ - { - "constraint": 32, - "type": "less_than" - }, - { - "constraint": "^\\\\\\\\d{4}-\\\\\\\\d{2}-\\\\\\\\d{2}$", - "type": "regex" - }, - { - "constraint": "int", - "type": "list_type" - }, - { - "constraint": [ - 1, - 2, - 3 - ], - "type": "included_in" - }, - { - "constraint": [ - "string_1", - "string_2", - "string_3" - ], - "type": "included_in" - } - ], - "value": "" - } - """); - - SettingsConfiguration configuration = SettingsConfiguration.fromXContentBytes(new BytesArray(content), XContentType.JSON); - boolean humanReadable = true; - BytesReference originalBytes = toShuffledXContent(configuration, XContentType.JSON, ToXContent.EMPTY_PARAMS, humanReadable); - SettingsConfiguration parsed; - try (XContentParser parser = createParser(XContentType.JSON.xContent(), originalBytes)) { - parsed = SettingsConfiguration.fromXContent(parser); - } - assertToXContentEquivalent(originalBytes, toXContent(parsed, XContentType.JSON, humanReadable), XContentType.JSON); - } - public void testToMap() { SettingsConfiguration configField = SettingsConfigurationTestUtils.getRandomSettingsConfigurationField(); Map configFieldAsMap = configField.toMap(); - if (configField.getCategory() != null) { - assertThat(configFieldAsMap.get("category"), equalTo(configField.getCategory())); - } else { - assertFalse(configFieldAsMap.containsKey("category")); - } - assertThat(configFieldAsMap.get("default_value"), equalTo(configField.getDefaultValue())); - if (configField.getDependsOn() != null) { - List> dependsOnAsList = configField.getDependsOn() - .stream() - .map(SettingsConfigurationDependency::toMap) - .toList(); - assertThat(configFieldAsMap.get("depends_on"), equalTo(dependsOnAsList)); - } else { - assertFalse(configFieldAsMap.containsKey("depends_on")); - } - - if (configField.getDisplay() != null) { - assertThat(configFieldAsMap.get("display"), equalTo(configField.getDisplay().toString())); + if (configField.getDescription() != null) { + assertThat(configFieldAsMap.get("description"), equalTo(configField.getDescription())); } else { - assertFalse(configFieldAsMap.containsKey("display")); + assertFalse(configFieldAsMap.containsKey("description")); } assertThat(configFieldAsMap.get("label"), equalTo(configField.getLabel())); - if (configField.getOptions() != null) { - List> optionsAsList = configField.getOptions() - .stream() - .map(SettingsConfigurationSelectOption::toMap) - .toList(); - assertThat(configFieldAsMap.get("options"), equalTo(optionsAsList)); - } else { - assertFalse(configFieldAsMap.containsKey("options")); - } - - if (configField.getOrder() != null) { - assertThat(configFieldAsMap.get("order"), equalTo(configField.getOrder())); - } else { - assertFalse(configFieldAsMap.containsKey("order")); - } - - if (configField.getPlaceholder() != null) { - assertThat(configFieldAsMap.get("placeholder"), equalTo(configField.getPlaceholder())); - } else { - assertFalse(configFieldAsMap.containsKey("placeholder")); - } - assertThat(configFieldAsMap.get("required"), equalTo(configField.isRequired())); assertThat(configFieldAsMap.get("sensitive"), equalTo(configField.isSensitive())); - - if (configField.getTooltip() != null) { - assertThat(configFieldAsMap.get("tooltip"), equalTo(configField.getTooltip())); - } else { - assertFalse(configFieldAsMap.containsKey("tooltip")); - } + assertThat(configFieldAsMap.get("updatable"), equalTo(configField.isUpdatable())); if (configField.getType() != null) { assertThat(configFieldAsMap.get("type"), equalTo(configField.getType().toString())); } else { assertFalse(configFieldAsMap.containsKey("type")); } - - if (configField.getUiRestrictions() != null) { - assertThat(configFieldAsMap.get("ui_restrictions"), equalTo(configField.getUiRestrictions())); - } else { - assertFalse(configFieldAsMap.containsKey("ui_restrictions")); - } - - if (configField.getValidations() != null) { - List> validationsAsList = configField.getValidations() - .stream() - .map(SettingsConfigurationValidation::toMap) - .toList(); - assertThat(configFieldAsMap.get("validations"), equalTo(validationsAsList)); - } else { - assertFalse(configFieldAsMap.containsKey("validations")); - } - - assertThat(configFieldAsMap.get("value"), equalTo(configField.getValue())); - } } diff --git a/server/src/test/java/org/elasticsearch/inference/TaskSettingsConfigurationTestUtils.java b/server/src/test/java/org/elasticsearch/inference/TaskSettingsConfigurationTestUtils.java deleted file mode 100644 index 81abeaefd9f1a..0000000000000 --- a/server/src/test/java/org/elasticsearch/inference/TaskSettingsConfigurationTestUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference; - -import java.util.HashMap; -import java.util.Map; - -import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength; -import static org.elasticsearch.test.ESTestCase.randomInt; - -public class TaskSettingsConfigurationTestUtils { - - public static TaskSettingsConfiguration getRandomTaskSettingsConfigurationField() { - return new TaskSettingsConfiguration.Builder().setTaskType(getRandomTaskType()) - .setConfiguration(getRandomServiceConfiguration(10)) - .build(); - } - - private static TaskType getRandomTaskType() { - TaskType[] values = TaskType.values(); - return values[randomInt(values.length - 1)]; - } - - private static Map getRandomServiceConfiguration(int numFields) { - var numConfigFields = randomInt(numFields); - Map configuration = new HashMap<>(); - for (int i = 0; i < numConfigFields; i++) { - configuration.put(randomAlphaOfLength(10), SettingsConfigurationTestUtils.getRandomSettingsConfigurationField()); - } - - return configuration; - } -} diff --git a/server/src/test/java/org/elasticsearch/inference/TaskSettingsConfigurationTests.java b/server/src/test/java/org/elasticsearch/inference/TaskSettingsConfigurationTests.java deleted file mode 100644 index d37fffc78ebd6..0000000000000 --- a/server/src/test/java/org/elasticsearch/inference/TaskSettingsConfigurationTests.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference; - -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xcontent.ToXContent; -import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xcontent.XContentType; - -import java.io.IOException; -import java.util.Map; - -import static org.elasticsearch.common.xcontent.XContentHelper.toXContent; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; -import static org.hamcrest.CoreMatchers.equalTo; - -public class TaskSettingsConfigurationTests extends ESTestCase { - public void testToXContent() throws IOException { - String content = XContentHelper.stripWhitespace(""" - { - "task_type": "text_embedding", - "configuration": { - "text_field_configuration": { - "default_value": null, - "depends_on": [ - { - "field": "some_field", - "value": true - } - ], - "display": "textbox", - "label": "Very important field", - "options": [], - "order": 4, - "required": true, - "sensitive": true, - "tooltip": "Wow, this tooltip is useful.", - "type": "str", - "ui_restrictions": [], - "validations": null, - "value": "" - }, - "numeric_field_configuration": { - "default_value": 3, - "depends_on": null, - "display": "numeric", - "label": "Very important numeric field", - "options": [], - "order": 2, - "required": true, - "sensitive": false, - "tooltip": "Wow, this tooltip is useful.", - "type": "int", - "ui_restrictions": [], - "validations": [ - { - "constraint": 0, - "type": "greater_than" - } - ], - "value": "" - } - } - } - """); - - TaskSettingsConfiguration configuration = TaskSettingsConfiguration.fromXContentBytes(new BytesArray(content), XContentType.JSON); - boolean humanReadable = true; - BytesReference originalBytes = toShuffledXContent(configuration, XContentType.JSON, ToXContent.EMPTY_PARAMS, humanReadable); - TaskSettingsConfiguration parsed; - try (XContentParser parser = createParser(XContentType.JSON.xContent(), originalBytes)) { - parsed = TaskSettingsConfiguration.fromXContent(parser); - } - assertToXContentEquivalent(originalBytes, toXContent(parsed, XContentType.JSON, humanReadable), XContentType.JSON); - } - - public void testToMap() { - TaskSettingsConfiguration configField = TaskSettingsConfigurationTestUtils.getRandomTaskSettingsConfigurationField(); - Map configFieldAsMap = configField.toMap(); - - assertThat(configFieldAsMap.get("task_type"), equalTo(configField.getTaskType())); - assertThat(configFieldAsMap.get("configuration"), equalTo(configField.getConfiguration())); - } -} diff --git a/server/src/test/java/org/elasticsearch/inference/configuration/SettingsConfigurationDisplayTypeTests.java b/server/src/test/java/org/elasticsearch/inference/configuration/SettingsConfigurationDisplayTypeTests.java deleted file mode 100644 index 603ea9480783c..0000000000000 --- a/server/src/test/java/org/elasticsearch/inference/configuration/SettingsConfigurationDisplayTypeTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import org.elasticsearch.inference.SettingsConfigurationTestUtils; -import org.elasticsearch.test.ESTestCase; - -import static org.hamcrest.Matchers.equalTo; - -public class SettingsConfigurationDisplayTypeTests extends ESTestCase { - - public void testDisplayType_WithValidConfigurationDisplayTypeString() { - SettingsConfigurationDisplayType displayType = SettingsConfigurationTestUtils.getRandomSettingsConfigurationDisplayType(); - assertThat(SettingsConfigurationDisplayType.displayType(displayType.toString()), equalTo(displayType)); - } - - public void testDisplayType_WithInvalidConfigurationDisplayTypeString_ExpectIllegalArgumentException() { - expectThrows( - IllegalArgumentException.class, - () -> SettingsConfigurationDisplayType.displayType("invalid configuration display type") - ); - } -} diff --git a/server/src/test/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidationTypeTests.java b/server/src/test/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidationTypeTests.java deleted file mode 100644 index d35968004ea0d..0000000000000 --- a/server/src/test/java/org/elasticsearch/inference/configuration/SettingsConfigurationValidationTypeTests.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.inference.configuration; - -import org.elasticsearch.inference.SettingsConfigurationTestUtils; -import org.elasticsearch.test.ESTestCase; - -import static org.hamcrest.Matchers.equalTo; - -public class SettingsConfigurationValidationTypeTests extends ESTestCase { - - public void testValidationType_WithValidConfigurationValidationTypeString() { - SettingsConfigurationValidationType validationType = SettingsConfigurationTestUtils.getRandomConfigurationValidationType(); - - assertThat(SettingsConfigurationValidationType.validationType(validationType.toString()), equalTo(validationType)); - } - - public void testValidationType_WithInvalidConfigurationValidationTypeString_ExpectIllegalArgumentException() { - assertThrows(IllegalArgumentException.class, () -> SettingsConfigurationValidationType.validationType("invalid validation type")); - } - -} diff --git a/x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceCrudIT.java b/x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceCrudIT.java index 2f8cfc8f3e659..58d870ceed6f2 100644 --- a/x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceCrudIT.java +++ b/x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceCrudIT.java @@ -158,11 +158,9 @@ public void testGetServicesWithoutTaskType() throws IOException { String[] providers = new String[services.size()]; for (int i = 0; i < services.size(); i++) { Map serviceConfig = (Map) services.get(i); - providers[i] = (String) serviceConfig.get("provider"); + providers[i] = (String) serviceConfig.get("service"); } - Arrays.sort(providers); - var providerList = new ArrayList<>( Arrays.asList( "alibabacloud-ai-search", @@ -200,10 +198,9 @@ public void testGetServicesWithTextEmbeddingTaskType() throws IOException { String[] providers = new String[services.size()]; for (int i = 0; i < services.size(); i++) { Map serviceConfig = (Map) services.get(i); - providers[i] = (String) serviceConfig.get("provider"); + providers[i] = (String) serviceConfig.get("service"); } - Arrays.sort(providers); assertArrayEquals( List.of( "alibabacloud-ai-search", @@ -233,10 +230,9 @@ public void testGetServicesWithRerankTaskType() throws IOException { String[] providers = new String[services.size()]; for (int i = 0; i < services.size(); i++) { Map serviceConfig = (Map) services.get(i); - providers[i] = (String) serviceConfig.get("provider"); + providers[i] = (String) serviceConfig.get("service"); } - Arrays.sort(providers); assertArrayEquals( List.of("alibabacloud-ai-search", "cohere", "elasticsearch", "googlevertexai", "jinaai", "test_reranking_service").toArray(), providers @@ -251,10 +247,9 @@ public void testGetServicesWithCompletionTaskType() throws IOException { String[] providers = new String[services.size()]; for (int i = 0; i < services.size(); i++) { Map serviceConfig = (Map) services.get(i); - providers[i] = (String) serviceConfig.get("provider"); + providers[i] = (String) serviceConfig.get("service"); } - Arrays.sort(providers); assertArrayEquals( providers, List.of( @@ -285,11 +280,9 @@ public void testGetServicesWithSparseEmbeddingTaskType() throws IOException { String[] providers = new String[services.size()]; for (int i = 0; i < services.size(); i++) { Map serviceConfig = (Map) services.get(i); - providers[i] = (String) serviceConfig.get("provider"); + providers[i] = (String) serviceConfig.get("service"); } - Arrays.sort(providers); - var providerList = new ArrayList<>(Arrays.asList("alibabacloud-ai-search", "elasticsearch", "hugging_face", "test_service")); if ((ElasticInferenceServiceFeature.DEPRECATED_ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG.isEnabled() || ElasticInferenceServiceFeature.ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG.isEnabled())) { diff --git a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestDenseInferenceServiceExtension.java b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestDenseInferenceServiceExtension.java index a6888f28159f4..89c79dd148598 100644 --- a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestDenseInferenceServiceExtension.java +++ b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestDenseInferenceServiceExtension.java @@ -18,7 +18,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceExtension; import org.elasticsearch.inference.InferenceServiceResults; @@ -29,10 +28,8 @@ import org.elasticsearch.inference.ServiceSettings; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.inference.UnifiedCompletionRequest; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xcontent.ToXContentObject; @@ -260,23 +257,18 @@ public static InferenceServiceConfiguration get() { configurationMap.put( "model", - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("Model") - .setOrder(1) .setRequired(true) .setSensitive(true) - .setTooltip("") .setType(SettingsConfigurationFieldType.STRING) .build() ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestRerankingServiceExtension.java b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestRerankingServiceExtension.java index bbb773aa5129a..77c762a38baaf 100644 --- a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestRerankingServiceExtension.java +++ b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestRerankingServiceExtension.java @@ -17,7 +17,6 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceExtension; import org.elasticsearch.inference.InferenceServiceResults; @@ -27,10 +26,8 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.ServiceSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.inference.UnifiedCompletionRequest; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xcontent.ToXContentObject; @@ -174,23 +171,18 @@ public static InferenceServiceConfiguration get() { configurationMap.put( "model", - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("Model") - .setOrder(1) .setRequired(true) .setSensitive(true) - .setTooltip("") .setType(SettingsConfigurationFieldType.STRING) .build() ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java index eea64304f503a..bef0b1812beda 100644 --- a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java +++ b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java @@ -17,7 +17,6 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceExtension; import org.elasticsearch.inference.InferenceServiceResults; @@ -27,10 +26,8 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.ServiceSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.inference.UnifiedCompletionRequest; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xcontent.ToXContentObject; @@ -208,35 +205,28 @@ public static InferenceServiceConfiguration get() { configurationMap.put( "model", - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("Model") - .setOrder(1) .setRequired(true) .setSensitive(false) - .setTooltip("") .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( "hidden_field", - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("Hidden Field") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("") .setType(SettingsConfigurationFieldType.STRING) .build() ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestStreamingCompletionServiceExtension.java b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestStreamingCompletionServiceExtension.java index a39be00d9e7fa..e071b704c233e 100644 --- a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestStreamingCompletionServiceExtension.java +++ b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestStreamingCompletionServiceExtension.java @@ -19,7 +19,6 @@ import org.elasticsearch.common.xcontent.ChunkedToXContentHelper; import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceExtension; import org.elasticsearch.inference.InferenceServiceResults; @@ -28,10 +27,8 @@ import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ServiceSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.inference.UnifiedCompletionRequest; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xcontent.ToXContentObject; @@ -260,23 +257,18 @@ public static InferenceServiceConfiguration get() { configurationMap.put( "model_id", - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("Model ID") - .setOrder(1) .setRequired(true) .setSensitive(true) - .setTooltip("") .setType(SettingsConfigurationFieldType.STRING) .build() ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceServicesAction.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceServicesAction.java index 002b2b0fe93b0..0d8d7e81019a6 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceServicesAction.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceServicesAction.java @@ -21,9 +21,9 @@ import org.elasticsearch.xpack.core.inference.action.GetInferenceServicesAction; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; public class TransportGetInferenceServicesAction extends HandledTransportAction< @@ -72,7 +72,8 @@ private void getServiceConfigurationsForTaskType( service -> service.getValue().hideFromConfigurationApi() == false && service.getValue().supportedTaskTypes().contains(requestedTaskType) ) - .collect(Collectors.toSet()); + .sorted(Comparator.comparing(service -> service.getValue().name())) + .collect(Collectors.toCollection(ArrayList::new)); getServiceConfigurationsForServices(filteredServices, listener.delegateFailureAndWrap((delegate, configurations) -> { delegate.onResponse(new GetInferenceServicesAction.Response(configurations)); @@ -84,14 +85,15 @@ private void getAllServiceConfigurations(ActionListener service.getValue().hideFromConfigurationApi() == false) - .collect(Collectors.toSet()); + .sorted(Comparator.comparing(service -> service.getValue().name())) + .collect(Collectors.toCollection(ArrayList::new)); getServiceConfigurationsForServices(availableServices, listener.delegateFailureAndWrap((delegate, configurations) -> { delegate.onResponse(new GetInferenceServicesAction.Response(configurations)); })); } private void getServiceConfigurationsForServices( - Set> services, + ArrayList> services, ActionListener> listener ) { try { diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchService.java index 42a276c6ee838..24f7fa182b7c2 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,11 +24,8 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; import org.elasticsearch.xpack.inference.chunking.EmbeddingRequestChunker; @@ -56,7 +52,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Stream; import static org.elasticsearch.xpack.inference.services.ServiceUtils.createInvalidModelException; import static org.elasticsearch.xpack.inference.services.ServiceUtils.parsePersistedConfigErrorMsg; @@ -73,6 +68,7 @@ public class AlibabaCloudSearchService extends SenderService { public static final String NAME = AlibabaCloudSearchUtils.SERVICE_NAME; + private static final String SERVICE_NAME = "AlibabaCloud AI Search"; private static final EnumSet supportedTaskTypes = EnumSet.of( TaskType.TEXT_EMBEDDING, @@ -383,86 +379,62 @@ public static InferenceServiceConfiguration get() { configurationMap.put( SERVICE_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) + new SettingsConfiguration.Builder().setDescription("The name of the model service to use for the {infer} task.") .setLabel("Project ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the model service to use for the {infer} task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of( - "ops-text-embedding-001", - "ops-text-embedding-zh-001", - "ops-text-embedding-en-001", - "ops-text-embedding-002", - "ops-text-sparse-embedding-001", - "ops-bge-reranker-larger" - ).map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()).toList() - ) .build() ); configurationMap.put( HOST, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription( + "The name of the host address used for the {infer} task. You can find the host address at " + + "https://opensearch.console.aliyun.com/cn-shanghai/rag/api-key[ the API keys section] " + + "of the documentation." + ) .setLabel("Host") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip( - "The name of the host address used for the {infer} task. You can find the host address at " - + "https://opensearch.console.aliyun.com/cn-shanghai/rag/api-key[ the API keys section] " - + "of the documentation." - ) + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( HTTP_SCHEMA_NAME, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) + new SettingsConfiguration.Builder().setDescription("") .setLabel("HTTP Schema") - .setOrder(4) .setRequired(true) .setSensitive(false) - .setTooltip("") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("https", "http") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) .build() ); configurationMap.put( WORKSPACE_NAME, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The name of the workspace used for the {infer} task.") .setLabel("Workspace") - .setOrder(5) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the workspace used for the {infer} task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.putAll( - DefaultSecretSettings.toSettingsConfigurationWithTooltip("A valid API key for the AlibabaCloud AI Search API.") + DefaultSecretSettings.toSettingsConfigurationWithDescription("A valid API key for the AlibabaCloud AI Search API.") ); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = AlibabaCloudSearchEmbeddingsModel.Configuration.get(); - case SPARSE_EMBEDDING -> taskSettingsConfig = AlibabaCloudSearchSparseModel.Configuration.get(); - // COMPLETION, RERANK task types have no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/embeddings/AlibabaCloudSearchEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/embeddings/AlibabaCloudSearchEmbeddingsModel.java index 1bcc802ab18ea..2654ee4d22ce6 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/embeddings/AlibabaCloudSearchEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/embeddings/AlibabaCloudSearchEmbeddingsModel.java @@ -7,28 +7,19 @@ package org.elasticsearch.xpack.inference.services.alibabacloudsearch.embeddings; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.alibabacloudsearch.AlibabaCloudSearchActionVisitor; -import org.elasticsearch.xpack.inference.external.request.alibabacloudsearch.AlibabaCloudSearchEmbeddingsRequestEntity; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; import org.elasticsearch.xpack.inference.services.alibabacloudsearch.AlibabaCloudSearchModel; import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import java.util.stream.Stream; public class AlibabaCloudSearchEmbeddingsModel extends AlibabaCloudSearchModel { public static AlibabaCloudSearchEmbeddingsModel of( @@ -114,35 +105,4 @@ public DefaultSecretSettings getSecretSettings() { public ExecutableAction accept(AlibabaCloudSearchActionVisitor visitor, Map taskSettings, InputType inputType) { return visitor.create(this, taskSettings, inputType); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - AlibabaCloudSearchEmbeddingsRequestEntity.INPUT_TYPE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) - .setLabel("Input Type") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the type of input passed to the model.") - .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("ingest", "search") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/sparse/AlibabaCloudSearchSparseModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/sparse/AlibabaCloudSearchSparseModel.java index 95bf500434c5a..0155d8fbc1f08 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/sparse/AlibabaCloudSearchSparseModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/sparse/AlibabaCloudSearchSparseModel.java @@ -7,28 +7,19 @@ package org.elasticsearch.xpack.inference.services.alibabacloudsearch.sparse; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.alibabacloudsearch.AlibabaCloudSearchActionVisitor; -import org.elasticsearch.xpack.inference.external.request.alibabacloudsearch.AlibabaCloudSearchSparseRequestEntity; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; import org.elasticsearch.xpack.inference.services.alibabacloudsearch.AlibabaCloudSearchModel; import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import java.util.stream.Stream; public class AlibabaCloudSearchSparseModel extends AlibabaCloudSearchModel { public static AlibabaCloudSearchSparseModel of( @@ -108,50 +99,4 @@ public DefaultSecretSettings getSecretSettings() { public ExecutableAction accept(AlibabaCloudSearchActionVisitor visitor, Map taskSettings, InputType inputType) { return visitor.create(this, taskSettings, inputType); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - AlibabaCloudSearchSparseRequestEntity.INPUT_TYPE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) - .setLabel("Input Type") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the type of input passed to the model.") - .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("ingest", "search") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) - .setValue("") - .build() - ); - configurationMap.put( - AlibabaCloudSearchSparseRequestEntity.RETURN_TOKEN_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TOGGLE) - .setLabel("Return Token") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip( - "If `true`, the token name will be returned in the response. Defaults to `false` which means only the " - + "token ID will be returned in the response." - ) - .setType(SettingsConfigurationFieldType.BOOLEAN) - .setValue(true) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockSecretSettings.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockSecretSettings.java index b5818d7e4a287..2105da235babe 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockSecretSettings.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockSecretSettings.java @@ -18,7 +18,6 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SecretSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xcontent.XContentBuilder; @@ -129,23 +128,21 @@ public static Map get() { var configurationMap = new HashMap(); configurationMap.put( ACCESS_KEY_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("A valid AWS access key that has permissions to use Amazon Bedrock.") .setLabel("Access Key") - .setOrder(1) .setRequired(true) .setSensitive(true) - .setTooltip("A valid AWS access key that has permissions to use Amazon Bedrock.") + .setUpdatable(true) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( SECRET_KEY_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("A valid AWS secret key that is paired with the access_key.") .setLabel("Secret Key") - .setOrder(2) .setRequired(true) .setSensitive(true) - .setTooltip("A valid AWS secret key that is paired with the access_key.") + .setUpdatable(true) .setType(SettingsConfigurationFieldType.STRING) .build() ); diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockService.java index a88881220f933..07c5e91776192 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockService.java @@ -18,7 +18,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -26,11 +25,8 @@ import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; import org.elasticsearch.xpack.inference.chunking.EmbeddingRequestChunker; @@ -57,7 +53,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Stream; import static org.elasticsearch.xpack.inference.services.ServiceUtils.createInvalidModelException; import static org.elasticsearch.xpack.inference.services.ServiceUtils.parsePersistedConfigErrorMsg; @@ -77,6 +72,7 @@ public class AmazonBedrockService extends SenderService { public static final String NAME = "amazonbedrock"; + private static final String SERVICE_NAME = "Amazon Bedrock"; private final Sender amazonBedrockSender; @@ -382,61 +378,51 @@ public static InferenceServiceConfiguration get() { configurationMap.put( PROVIDER_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) + new SettingsConfiguration.Builder().setDescription("The model provider for your deployment.") .setLabel("Provider") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip("The model provider for your deployment.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("amazontitan", "anthropic", "ai21labs", "cohere", "meta", "mistral") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) .build() ); configurationMap.put( MODEL_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription( + "The base model ID or an ARN to a custom model based on a foundational model." + ) .setLabel("Model") - .setOrder(4) .setRequired(true) .setSensitive(false) - .setTooltip("The base model ID or an ARN to a custom model based on a foundational model.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( REGION_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The region that your model or ARN is deployed in.") .setLabel("Region") - .setOrder(5) .setRequired(true) .setSensitive(false) - .setTooltip("The region that your model or ARN is deployed in.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.putAll(AmazonBedrockSecretSettings.Configuration.get()); configurationMap.putAll( - RateLimitSettings.toSettingsConfigurationWithTooltip( + RateLimitSettings.toSettingsConfigurationWithDescription( "By default, the amazonbedrock service sets the number of requests allowed per minute to 240." ) ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case COMPLETION -> taskSettingsConfig = AmazonBedrockChatCompletionModel.Configuration.get(); - // TEXT_EMBEDDING task type has no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/completion/AmazonBedrockChatCompletionModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/completion/AmazonBedrockChatCompletionModel.java index 9339a8a05dc81..27dc607d671aa 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/completion/AmazonBedrockChatCompletionModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/amazonbedrock/completion/AmazonBedrockChatCompletionModel.java @@ -7,30 +7,19 @@ package org.elasticsearch.xpack.inference.services.amazonbedrock.completion; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.inference.Model; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskSettings; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.amazonbedrock.AmazonBedrockActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; import org.elasticsearch.xpack.inference.services.amazonbedrock.AmazonBedrockModel; import org.elasticsearch.xpack.inference.services.amazonbedrock.AmazonBedrockSecretSettings; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.amazonbedrock.AmazonBedrockConstants.MAX_NEW_TOKENS_FIELD; -import static org.elasticsearch.xpack.inference.services.amazonbedrock.AmazonBedrockConstants.TEMPERATURE_FIELD; -import static org.elasticsearch.xpack.inference.services.amazonbedrock.AmazonBedrockConstants.TOP_K_FIELD; -import static org.elasticsearch.xpack.inference.services.amazonbedrock.AmazonBedrockConstants.TOP_P_FIELD; - public class AmazonBedrockChatCompletionModel extends AmazonBedrockModel { public static AmazonBedrockChatCompletionModel of(AmazonBedrockChatCompletionModel completionModel, Map taskSettings) { @@ -91,62 +80,4 @@ public AmazonBedrockChatCompletionServiceSettings getServiceSettings() { public AmazonBedrockChatCompletionTaskSettings getTaskSettings() { return (AmazonBedrockChatCompletionTaskSettings) super.getTaskSettings(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - MAX_NEW_TOKENS_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Max New Tokens") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Sets the maximum number for the output tokens to be generated.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TEMPERATURE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Temperature") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("A number between 0.0 and 1.0 that controls the apparent creativity of the results.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TOP_P_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top P") - .setOrder(3) - .setRequired(false) - .setSensitive(false) - .setTooltip("Alternative to temperature. A number in the range of 0.0 to 1.0, to eliminate low-probability tokens.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TOP_K_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top K") - .setOrder(4) - .setRequired(false) - .setSensitive(false) - .setTooltip("Only available for anthropic, cohere, and mistral providers. Alternative to temperature.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicService.java index 41852e4758a8c..9dbfb0732f463 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicService.java @@ -15,7 +15,6 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -23,9 +22,7 @@ import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.external.action.anthropic.AnthropicActionCreator; @@ -57,6 +54,7 @@ public class AnthropicService extends SenderService { public static final String NAME = "anthropic"; + private static final String SERVICE_NAME = "Anthropic"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.COMPLETION); @@ -258,31 +256,27 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The name of the model to use for the inference task.") .setLabel("Model ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the model to use for the inference task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll( - RateLimitSettings.toSettingsConfigurationWithTooltip( + RateLimitSettings.toSettingsConfigurationWithDescription( "By default, the anthropic service sets the number of requests allowed per minute to 50." ) ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case COMPLETION -> taskSettingsConfig = AnthropicChatCompletionModel.Configuration.get(); - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/completion/AnthropicChatCompletionModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/completion/AnthropicChatCompletionModel.java index df54ee4ec97c4..942cae8960daf 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/completion/AnthropicChatCompletionModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/anthropic/completion/AnthropicChatCompletionModel.java @@ -8,14 +8,10 @@ package org.elasticsearch.xpack.inference.services.anthropic.completion; import org.apache.http.client.utils.URIBuilder; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.anthropic.AnthropicActionVisitor; import org.elasticsearch.xpack.inference.external.request.anthropic.AnthropicRequestUtils; @@ -26,15 +22,8 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.anthropic.AnthropicServiceFields.MAX_TOKENS; -import static org.elasticsearch.xpack.inference.services.anthropic.AnthropicServiceFields.TEMPERATURE_FIELD; -import static org.elasticsearch.xpack.inference.services.anthropic.AnthropicServiceFields.TOP_K_FIELD; -import static org.elasticsearch.xpack.inference.services.anthropic.AnthropicServiceFields.TOP_P_FIELD; - public class AnthropicChatCompletionModel extends AnthropicModel { public static AnthropicChatCompletionModel of(AnthropicChatCompletionModel model, Map taskSettings) { @@ -134,62 +123,4 @@ private static URI buildDefaultUri() throws URISyntaxException { .setPathSegments(AnthropicRequestUtils.API_VERSION_1, AnthropicRequestUtils.MESSAGES_PATH) .build(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - MAX_TOKENS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Max Tokens") - .setOrder(1) - .setRequired(true) - .setSensitive(false) - .setTooltip("The maximum number of tokens to generate before stopping.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TEMPERATURE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("Temperature") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("The amount of randomness injected into the response.") - .setType(SettingsConfigurationFieldType.STRING) - .build() - ); - configurationMap.put( - TOP_K_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top K") - .setOrder(3) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies to only sample from the top K options for each subsequent token.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TOP_P_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top P") - .setOrder(4) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies to use Anthropic’s nucleus sampling.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioService.java index bcd4a1abfbf00..649540f7efc5c 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioService.java @@ -17,7 +17,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -26,11 +25,8 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; import org.elasticsearch.xpack.inference.chunking.EmbeddingRequestChunker; @@ -56,7 +52,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Stream; import static org.elasticsearch.xpack.inference.services.ServiceUtils.createInvalidModelException; import static org.elasticsearch.xpack.inference.services.ServiceUtils.parsePersistedConfigErrorMsg; @@ -77,6 +72,7 @@ public class AzureAiStudioService extends SenderService { static final String NAME = "azureaistudio"; + private static final String SERVICE_NAME = "Azure AI Studio"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.COMPLETION); public AzureAiStudioService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -410,62 +406,47 @@ public static InferenceServiceConfiguration get() { configurationMap.put( TARGET_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The target URL of your Azure AI Studio model deployment.") .setLabel("Target") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("The target URL of your Azure AI Studio model deployment.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( ENDPOINT_TYPE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) + new SettingsConfiguration.Builder().setDescription( + "Specifies the type of endpoint that is used in your model deployment." + ) .setLabel("Endpoint Type") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip("Specifies the type of endpoint that is used in your model deployment.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("token", "realtime") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) .build() ); configurationMap.put( PROVIDER_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) + new SettingsConfiguration.Builder().setDescription("The model provider for your deployment.") .setLabel("Provider") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip("The model provider for your deployment.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("cohere", "meta", "microsoft_phi", "mistral", "openai", "databricks") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) .build() ); configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = AzureAiStudioEmbeddingsModel.Configuration.get(); - case COMPLETION -> taskSettingsConfig = AzureAiStudioChatCompletionModel.Configuration.get(); - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/completion/AzureAiStudioChatCompletionModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/completion/AzureAiStudioChatCompletionModel.java index 0492788c2adcd..5afb3aaed61ff 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/completion/AzureAiStudioChatCompletionModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/completion/AzureAiStudioChatCompletionModel.java @@ -7,14 +7,10 @@ package org.elasticsearch.xpack.inference.services.azureaistudio.completion; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.azureaistudio.AzureAiStudioActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; @@ -25,12 +21,9 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.COMPLETIONS_URI_PATH; -import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.USER_FIELD; public class AzureAiStudioChatCompletionModel extends AzureAiStudioModel { @@ -109,30 +102,4 @@ protected URI getEndpointUri() throws URISyntaxException { public ExecutableAction accept(AzureAiStudioActionVisitor creator, Map taskSettings) { return creator.create(this, taskSettings); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - USER_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("User") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the user issuing the request.") - .setType(SettingsConfigurationFieldType.STRING) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/embeddings/AzureAiStudioEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/embeddings/AzureAiStudioEmbeddingsModel.java index 8b0b52c69b82c..edbefe07cff02 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/embeddings/AzureAiStudioEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureaistudio/embeddings/AzureAiStudioEmbeddingsModel.java @@ -7,15 +7,11 @@ package org.elasticsearch.xpack.inference.services.azureaistudio.embeddings; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.azureaistudio.AzureAiStudioActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; @@ -26,15 +22,9 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.DO_SAMPLE_FIELD; import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.EMBEDDINGS_URI_PATH; -import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.MAX_NEW_TOKENS_FIELD; -import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.TEMPERATURE_FIELD; -import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.TOP_P_FIELD; public class AzureAiStudioEmbeddingsModel extends AzureAiStudioModel { @@ -116,65 +106,4 @@ protected URI getEndpointUri() throws URISyntaxException { public ExecutableAction accept(AzureAiStudioActionVisitor creator, Map taskSettings) { return creator.create(this, taskSettings); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - DO_SAMPLE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Do Sample") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Instructs the inference process to perform sampling or not.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - MAX_NEW_TOKENS_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Max New Tokens") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("Provides a hint for the maximum number of output tokens to be generated.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TEMPERATURE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Temperature") - .setOrder(3) - .setRequired(false) - .setSensitive(false) - .setTooltip("A number in the range of 0.0 to 2.0 that specifies the sampling temperature.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - configurationMap.put( - TOP_P_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top P") - .setOrder(4) - .setRequired(false) - .setSensitive(false) - .setTooltip( - "A number in the range of 0.0 to 2.0 that is an alternative value to temperature. Should not be used " - + "if temperature is specified." - ) - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiSecretSettings.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiSecretSettings.java index 70a29b28a607c..0601daf562ce9 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiSecretSettings.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiSecretSettings.java @@ -18,7 +18,6 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SecretSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xcontent.XContentBuilder; @@ -147,23 +146,21 @@ public static Map get() { var configurationMap = new HashMap(); configurationMap.put( API_KEY, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("You must provide either an API key or an Entra ID.") .setLabel("API Key") - .setOrder(1) .setRequired(false) .setSensitive(true) - .setTooltip("You must provide either an API key or an Entra ID.") + .setUpdatable(true) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( ENTRA_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("You must provide either an API key or an Entra ID.") .setLabel("Entra ID") - .setOrder(2) .setRequired(false) .setSensitive(true) - .setTooltip("You must provide either an API key or an Entra ID.") + .setUpdatable(true) .setType(SettingsConfigurationFieldType.STRING) .build() ); diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java index 0ed69604c258a..4fca5a460a12a 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,9 +24,7 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -68,6 +65,7 @@ public class AzureOpenAiService extends SenderService { public static final String NAME = "azureopenai"; + private static final String SERVICE_NAME = "Azure OpenAI"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.COMPLETION); public AzureOpenAiService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -353,56 +351,49 @@ public static InferenceServiceConfiguration get() { configurationMap.put( RESOURCE_NAME, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The name of your Azure OpenAI resource.") .setLabel("Resource Name") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip("The name of your Azure OpenAI resource.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( API_VERSION, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The Azure API version ID to use.") .setLabel("API Version") - .setOrder(4) .setRequired(true) .setSensitive(false) - .setTooltip("The Azure API version ID to use.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( DEPLOYMENT_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The deployment name of your deployed models.") .setLabel("Deployment ID") - .setOrder(5) .setRequired(true) .setSensitive(false) - .setTooltip("The deployment name of your deployed models.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.putAll(AzureOpenAiSecretSettings.Configuration.get()); configurationMap.putAll( - RateLimitSettings.toSettingsConfigurationWithTooltip( + RateLimitSettings.toSettingsConfigurationWithDescription( "The azureopenai service sets a default number of requests allowed per minute depending on the task type." ) ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = AzureOpenAiEmbeddingsModel.Configuration.get(); - case COMPLETION -> taskSettingsConfig = AzureOpenAiCompletionModel.Configuration.get(); - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/completion/AzureOpenAiCompletionModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/completion/AzureOpenAiCompletionModel.java index 8b2846fd9ced7..ed57187adfe64 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/completion/AzureOpenAiCompletionModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/completion/AzureOpenAiCompletionModel.java @@ -7,14 +7,10 @@ package org.elasticsearch.xpack.inference.services.azureopenai.completion; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.azureopenai.AzureOpenAiActionVisitor; import org.elasticsearch.xpack.inference.external.request.azureopenai.AzureOpenAiUtils; @@ -23,12 +19,8 @@ import org.elasticsearch.xpack.inference.services.azureopenai.AzureOpenAiSecretSettings; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.azureopenai.AzureOpenAiServiceFields.USER; - public class AzureOpenAiCompletionModel extends AzureOpenAiModel { public static AzureOpenAiCompletionModel of(AzureOpenAiCompletionModel model, Map taskSettings) { @@ -127,30 +119,4 @@ public String apiVersion() { public String[] operationPathSegments() { return new String[] { AzureOpenAiUtils.CHAT_PATH, AzureOpenAiUtils.COMPLETIONS_PATH }; } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - USER, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("User") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the user issuing the request.") - .setType(SettingsConfigurationFieldType.STRING) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/embeddings/AzureOpenAiEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/embeddings/AzureOpenAiEmbeddingsModel.java index 0316804664510..dea5a8ca9e50a 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/embeddings/AzureOpenAiEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/embeddings/AzureOpenAiEmbeddingsModel.java @@ -7,15 +7,11 @@ package org.elasticsearch.xpack.inference.services.azureopenai.embeddings; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.azureopenai.AzureOpenAiActionVisitor; import org.elasticsearch.xpack.inference.external.request.azureopenai.AzureOpenAiUtils; @@ -24,12 +20,8 @@ import org.elasticsearch.xpack.inference.services.azureopenai.AzureOpenAiSecretSettings; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.azureopenai.AzureOpenAiServiceFields.USER; - public class AzureOpenAiEmbeddingsModel extends AzureOpenAiModel { public static AzureOpenAiEmbeddingsModel of(AzureOpenAiEmbeddingsModel model, Map taskSettings) { @@ -131,30 +123,4 @@ public String apiVersion() { public String[] operationPathSegments() { return new String[] { AzureOpenAiUtils.EMBEDDINGS_PATH }; } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - USER, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("User") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the user issuing the request.") - .setType(SettingsConfigurationFieldType.STRING) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/CohereService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/CohereService.java index a7d17192bfa92..60ab8ca68d5d9 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/CohereService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/CohereService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,7 +24,6 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -65,6 +63,7 @@ public class CohereService extends SenderService { public static final String NAME = "cohere"; + private static final String SERVICE_NAME = "Cohere"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.COMPLETION, TaskType.RERANK); // TODO Batching - We'll instantiate a batching class within the services that want to support it and pass it through to @@ -367,16 +366,11 @@ public static InferenceServiceConfiguration get() { configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = CohereEmbeddingsModel.Configuration.get(); - case RERANK -> taskSettingsConfig = CohereRerankModel.Configuration.get(); - // COMPLETION task type has no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/embeddings/CohereEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/embeddings/CohereEmbeddingsModel.java index 43a7bc0a5e678..0f62ab51145f4 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/embeddings/CohereEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/embeddings/CohereEmbeddingsModel.java @@ -7,17 +7,12 @@ package org.elasticsearch.xpack.inference.services.cohere.embeddings; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.cohere.CohereActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; @@ -25,13 +20,7 @@ import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; import java.net.URI; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import java.util.stream.Stream; - -import static org.elasticsearch.xpack.inference.external.request.cohere.CohereEmbeddingsRequestEntity.INPUT_TYPE_FIELD; -import static org.elasticsearch.xpack.inference.services.cohere.CohereServiceFields.TRUNCATE; public class CohereEmbeddingsModel extends CohereModel { public static CohereEmbeddingsModel of(CohereEmbeddingsModel model, Map taskSettings, InputType inputType) { @@ -110,52 +99,4 @@ public ExecutableAction accept(CohereActionVisitor visitor, Map public URI uri() { return getServiceSettings().getCommonSettings().uri(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - INPUT_TYPE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) - .setLabel("Input Type") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the type of input passed to the model.") - .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("classification", "clusterning", "ingest", "search") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) - .setValue("") - .build() - ); - configurationMap.put( - TRUNCATE, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) - .setLabel("Truncate") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies how the API handles inputs longer than the maximum token length.") - .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("NONE", "START", "END") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/rerank/CohereRerankModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/rerank/CohereRerankModel.java index cfcfb8a3d5dae..b84b98973bbe5 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/rerank/CohereRerankModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/rerank/CohereRerankModel.java @@ -7,15 +7,11 @@ package org.elasticsearch.xpack.inference.services.cohere.rerank; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.cohere.CohereActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; @@ -23,13 +19,8 @@ import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; import java.net.URI; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.cohere.rerank.CohereRerankTaskSettings.RETURN_DOCUMENTS; -import static org.elasticsearch.xpack.inference.services.cohere.rerank.CohereRerankTaskSettings.TOP_N_DOCS_ONLY; - public class CohereRerankModel extends CohereModel { public static CohereRerankModel of(CohereRerankModel model, Map taskSettings) { var requestTaskSettings = CohereRerankTaskSettings.fromMap(taskSettings); @@ -111,41 +102,4 @@ public ExecutableAction accept(CohereActionVisitor visitor, Map public URI uri() { return getServiceSettings().uri(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - RETURN_DOCUMENTS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TOGGLE) - .setLabel("Return Documents") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specify whether to return doc text within the results.") - .setType(SettingsConfigurationFieldType.BOOLEAN) - .setValue(false) - .build() - ); - configurationMap.put( - TOP_N_DOCS_ONLY, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top N") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("The number of most relevant documents to return, defaults to the number of the documents.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java index 27abc03cb6e82..68782488099a1 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -24,9 +23,7 @@ import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.tasks.Task; @@ -67,6 +64,7 @@ public class ElasticInferenceService extends SenderService { private final ElasticInferenceServiceComponents elasticInferenceServiceComponents; + private static final String SERVICE_NAME = "Elastic"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.SPARSE_EMBEDDING); public ElasticInferenceService( @@ -317,38 +315,33 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The name of the model to use for the inference task.") .setLabel("Model ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the model to use for the inference task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( MAX_INPUT_TOKENS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) + new SettingsConfiguration.Builder().setDescription("Allows you to specify the maximum number of tokens per input.") .setLabel("Maximum Input Tokens") - .setOrder(3) .setRequired(false) .setSensitive(false) - .setTooltip("Allows you to specify the maximum number of tokens per input.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.INTEGER) .build() ); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // SPARSE_EMBEDDING task type has no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/CustomElandRerankModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/CustomElandRerankModel.java index 6388bb33bb78d..b4d579b699cdf 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/CustomElandRerankModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/CustomElandRerankModel.java @@ -7,17 +7,7 @@ package org.elasticsearch.xpack.inference.services.elasticsearch; -import org.elasticsearch.common.util.LazyInitializable; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.elasticsearch.xpack.inference.services.elasticsearch.RerankTaskSettings.RETURN_DOCUMENTS; public class CustomElandRerankModel extends CustomElandModel { @@ -35,30 +25,4 @@ public CustomElandRerankModel( public CustomElandInternalServiceSettings getServiceSettings() { return (CustomElandInternalServiceSettings) super.getServiceSettings(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - RETURN_DOCUMENTS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TOGGLE) - .setLabel("Return Documents") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Returns the document instead of only the index.") - .setType(SettingsConfigurationFieldType.BOOLEAN) - .setValue(true) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java index cb3eb5ca8e826..39ad729b1699e 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java @@ -20,7 +20,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceResults; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceExtension; @@ -29,12 +28,9 @@ import org.elasticsearch.inference.Model; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.inference.UnifiedCompletionRequest; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.core.inference.results.InferenceTextEmbeddingFloatResults; import org.elasticsearch.xpack.core.inference.results.RankedDocsResults; @@ -71,7 +67,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Stream; import static org.elasticsearch.xpack.core.inference.results.ResultUtils.createInvalidChunkedResultException; import static org.elasticsearch.xpack.inference.services.ServiceUtils.removeFromMap; @@ -82,7 +77,6 @@ import static org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalServiceSettings.MODEL_ID; import static org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalServiceSettings.NUM_ALLOCATIONS; import static org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalServiceSettings.NUM_THREADS; -import static org.elasticsearch.xpack.inference.services.elasticsearch.ElserModels.ELSER_V1_MODEL; import static org.elasticsearch.xpack.inference.services.elasticsearch.ElserModels.ELSER_V2_MODEL; import static org.elasticsearch.xpack.inference.services.elasticsearch.ElserModels.ELSER_V2_MODEL_LINUX_X86; @@ -105,6 +99,7 @@ public class ElasticsearchInternalService extends BaseElasticsearchInternalServi public static final String DEFAULT_E5_ID = ".multilingual-e5-small-elasticsearch"; public static final String DEFAULT_RERANK_ID = ".rerank-v1-elasticsearch"; + private static final String SERVICE_NAME = "Elasticsearch"; private static final EnumSet supportedTaskTypes = EnumSet.of( TaskType.RERANK, TaskType.TEXT_EMBEDDING, @@ -1152,61 +1147,45 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) + new SettingsConfiguration.Builder().setDefaultValue(MULTILINGUAL_E5_SMALL_MODEL_ID) + .setDescription("The name of the model to use for the inference task.") .setLabel("Model ID") - .setOrder(1) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the model to use for the inference task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of( - ELSER_V1_MODEL, - ELSER_V2_MODEL, - ELSER_V2_MODEL_LINUX_X86, - MULTILINGUAL_E5_SMALL_MODEL_ID, - MULTILINGUAL_E5_SMALL_MODEL_ID_LINUX_X86 - ).map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()).toList() - ) - .setDefaultValue(MULTILINGUAL_E5_SMALL_MODEL_ID) .build() ); configurationMap.put( NUM_ALLOCATIONS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) + new SettingsConfiguration.Builder().setDefaultValue(1) + .setDescription("The total number of allocations this model is assigned across machine learning nodes.") .setLabel("Number Allocations") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("The total number of allocations this model is assigned across machine learning nodes.") + .setUpdatable(true) .setType(SettingsConfigurationFieldType.INTEGER) - .setDefaultValue(1) .build() ); configurationMap.put( NUM_THREADS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) + new SettingsConfiguration.Builder().setDefaultValue(2) + .setDescription("Sets the number of threads used by each model allocation during inference.") .setLabel("Number Threads") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip("Sets the number of threads used by each model allocation during inference.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.INTEGER) - .setDefaultValue(2) .build() ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case RERANK -> taskSettingsConfig = CustomElandRerankModel.Configuration.get(); - // SPARSE_EMBEDDING, TEXT_EMBEDDING task types have no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioService.java index 837a001d1f8f9..1dbf2ca3e2dad 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,9 +24,7 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -72,6 +69,7 @@ public class GoogleAiStudioService extends SenderService { public static final String NAME = "googleaistudio"; + private static final String SERVICE_NAME = "Google AI Studio"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.COMPLETION); public GoogleAiStudioService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -353,12 +351,11 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("ID of the LLM you're using.") .setLabel("Model ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("ID of the LLM you're using.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); @@ -366,14 +363,11 @@ public static InferenceServiceConfiguration get() { configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // COMPLETION, TEXT_EMBEDDING task types have no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiSecretSettings.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiSecretSettings.java index 272bc9eaa9a62..b185800ed75f4 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiSecretSettings.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiSecretSettings.java @@ -18,7 +18,6 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SecretSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xcontent.XContentBuilder; @@ -123,12 +122,11 @@ public static Map get() { var configurationMap = new HashMap(); configurationMap.put( SERVICE_ACCOUNT_JSON, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("API Key for the provider you're connecting to.") .setLabel("Credentials JSON") - .setOrder(1) .setRequired(true) .setSensitive(true) - .setTooltip("API Key for the provider you're connecting to.") + .setUpdatable(true) .setType(SettingsConfigurationFieldType.STRING) .build() ); diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiService.java index b412f20289880..8fe9f29c73747 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -24,9 +23,7 @@ import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -67,6 +64,7 @@ public class GoogleVertexAiService extends SenderService { public static final String NAME = "googlevertexai"; + private static final String SERVICE_NAME = "Google Vertex AI"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.RERANK); public GoogleVertexAiService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -331,42 +329,39 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("ID of the LLM you're using.") .setLabel("Model ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("ID of the LLM you're using.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( LOCATION, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription( + "Please provide the GCP region where the Vertex AI API(s) is enabled. " + + "For more information, refer to the {geminiVertexAIDocs}." + ) .setLabel("GCP Region") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip( - "Please provide the GCP region where the Vertex AI API(s) is enabled. " - + "For more information, refer to the {geminiVertexAIDocs}." - ) + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( PROJECT_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription( + "The GCP Project ID which has Vertex AI API(s) enabled. For more information " + + "on the URL, refer to the {geminiVertexAIDocs}." + ) .setLabel("GCP Project") - .setOrder(4) .setRequired(true) .setSensitive(false) - .setTooltip( - "The GCP Project ID which has Vertex AI API(s) enabled. For more information " - + "on the URL, refer to the {geminiVertexAIDocs}." - ) + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); @@ -374,15 +369,11 @@ public static InferenceServiceConfiguration get() { configurationMap.putAll(GoogleVertexAiSecretSettings.Configuration.get()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = GoogleVertexAiEmbeddingsModel.Configuration.get(); - case RERANK -> taskSettingsConfig = GoogleVertexAiRerankModel.Configuration.get(); - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/embeddings/GoogleVertexAiEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/embeddings/GoogleVertexAiEmbeddingsModel.java index a5acbb80b76ec..98640623ee21c 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/embeddings/GoogleVertexAiEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/embeddings/GoogleVertexAiEmbeddingsModel.java @@ -8,17 +8,12 @@ package org.elasticsearch.xpack.inference.services.googlevertexai.embeddings; import org.apache.http.client.utils.URIBuilder; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.googlevertexai.GoogleVertexAiActionVisitor; import org.elasticsearch.xpack.inference.external.request.googlevertexai.GoogleVertexAiUtils; @@ -28,14 +23,9 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import java.util.stream.Stream; import static org.elasticsearch.core.Strings.format; -import static org.elasticsearch.xpack.inference.services.googlevertexai.embeddings.GoogleVertexAiEmbeddingsTaskSettings.AUTO_TRUNCATE; -import static org.elasticsearch.xpack.inference.services.googlevertexai.embeddings.GoogleVertexAiEmbeddingsTaskSettings.INPUT_TYPE; public class GoogleVertexAiEmbeddingsModel extends GoogleVertexAiModel { @@ -165,51 +155,4 @@ public static URI buildUri(String location, String projectId, String modelId) th ) .build(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - INPUT_TYPE, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) - .setLabel("Input Type") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the type of input passed to the model.") - .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of( - InputType.CLASSIFICATION.toString(), - InputType.CLUSTERING.toString(), - InputType.INGEST.toString(), - InputType.SEARCH.toString() - ).map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()).toList() - ) - .setValue("") - .build() - ); - - configurationMap.put( - AUTO_TRUNCATE, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TOGGLE) - .setLabel("Auto Truncate") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies if the API truncates inputs longer than the maximum token length automatically.") - .setType(SettingsConfigurationFieldType.BOOLEAN) - .setValue(false) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/rerank/GoogleVertexAiRerankModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/rerank/GoogleVertexAiRerankModel.java index e73d8d2e2613a..f522897b0d716 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/rerank/GoogleVertexAiRerankModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/rerank/GoogleVertexAiRerankModel.java @@ -8,15 +8,11 @@ package org.elasticsearch.xpack.inference.services.googlevertexai.rerank; import org.apache.http.client.utils.URIBuilder; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.googlevertexai.GoogleVertexAiActionVisitor; import org.elasticsearch.xpack.inference.external.request.googlevertexai.GoogleVertexAiUtils; @@ -26,12 +22,9 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import static org.elasticsearch.core.Strings.format; -import static org.elasticsearch.xpack.inference.services.googlevertexai.rerank.GoogleVertexAiRerankTaskSettings.TOP_N; public class GoogleVertexAiRerankModel extends GoogleVertexAiModel { @@ -140,30 +133,4 @@ public static URI buildUri(String projectId) throws URISyntaxException { ) .build(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - TOP_N, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TOGGLE) - .setLabel("Top N") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the number of the top n documents, which should be returned.") - .setType(SettingsConfigurationFieldType.BOOLEAN) - .setValue(false) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceService.java index acb082cd2de8d..ef6beb8ec2627 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceService.java @@ -16,16 +16,13 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.Model; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.EmbeddingRequestChunker; @@ -54,6 +51,7 @@ public class HuggingFaceService extends HuggingFaceBaseService { public static final String NAME = "hugging_face"; + private static final String SERVICE_NAME = "Hugging Face"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.SPARSE_EMBEDDING); public HuggingFaceService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -183,29 +181,24 @@ public static InferenceServiceConfiguration get() { configurationMap.put( URL, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDefaultValue("https://api.openai.com/v1/embeddings") + .setDescription("The URL endpoint to use for the requests.") .setLabel("URL") - .setOrder(1) .setRequired(true) .setSensitive(false) - .setTooltip("The URL endpoint to use for the requests.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setValue("https://api.openai.com/v1/embeddings") - .setDefaultValue("https://api.openai.com/v1/embeddings") .build() ); configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // SPARSE_EMBEDDING, TEXT_EMBEDDING task types have no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/elser/HuggingFaceElserService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/elser/HuggingFaceElserService.java index 01d2a75ebff5d..52d42f570a413 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/elser/HuggingFaceElserService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/huggingface/elser/HuggingFaceElserService.java @@ -17,15 +17,12 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.Model; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceEmbeddingFloat; @@ -58,6 +55,7 @@ public class HuggingFaceElserService extends HuggingFaceBaseService { public static final String NAME = "hugging_face_elser"; + private static final String SERVICE_NAME = "Hugging Face ELSER"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.SPARSE_EMBEDDING); public HuggingFaceElserService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -178,12 +176,11 @@ public static InferenceServiceConfiguration get() { configurationMap.put( URL, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The URL endpoint to use for the requests.") .setLabel("URL") - .setOrder(1) .setRequired(true) .setSensitive(false) - .setTooltip("The URL endpoint to use for the requests.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); @@ -191,14 +188,11 @@ public static InferenceServiceConfiguration get() { configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // SPARSE_EMBEDDING task type has no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxService.java index 482554e060a47..dd368f88a993c 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,9 +24,7 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -68,6 +65,7 @@ public class IbmWatsonxService extends SenderService { public static final String NAME = "watsonxai"; + private static final String SERVICE_NAME = "IBM Watsonx"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING); public IbmWatsonxService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -326,72 +324,64 @@ public static InferenceServiceConfiguration get() { configurationMap.put( API_VERSION, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The IBM Watsonx API version ID to use.") .setLabel("API Version") - .setOrder(1) .setRequired(true) .setSensitive(false) - .setTooltip("The IBM Watsonx API version ID to use.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( PROJECT_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("Project ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The name of the model to use for the inference task.") .setLabel("Model ID") - .setOrder(3) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the model to use for the inference task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( URL, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("") .setLabel("URL") - .setOrder(4) .setRequired(true) .setSensitive(false) - .setTooltip("") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( MAX_INPUT_TOKENS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) + new SettingsConfiguration.Builder().setDescription("Allows you to specify the maximum number of tokens per input.") .setLabel("Maximum Input Tokens") - .setOrder(5) .setRequired(false) .setSensitive(false) - .setTooltip("Allows you to specify the maximum number of tokens per input.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.INTEGER) .build() ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // TEXT_EMBEDDING task type has no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIService.java index 11a72f811e8d3..ed76df5875562 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,7 +24,6 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -63,6 +61,7 @@ public class JinaAIService extends SenderService { public static final String NAME = "jinaai"; + private static final String SERVICE_NAME = "Jina AI"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.RERANK); public JinaAIService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -343,15 +342,11 @@ public static InferenceServiceConfiguration get() { configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = JinaAIEmbeddingsModel.Configuration.get(); - case RERANK -> taskSettingsConfig = JinaAIRerankModel.Configuration.get(); - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/embeddings/JinaAIEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/embeddings/JinaAIEmbeddingsModel.java index dd479802cdf13..2c2a24a75d098 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/embeddings/JinaAIEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/embeddings/JinaAIEmbeddingsModel.java @@ -7,17 +7,12 @@ package org.elasticsearch.xpack.inference.services.jinaai.embeddings; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; -import org.elasticsearch.inference.configuration.SettingsConfigurationSelectOption; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.jinaai.JinaAIActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; @@ -25,12 +20,7 @@ import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; import java.net.URI; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import java.util.stream.Stream; - -import static org.elasticsearch.xpack.inference.external.request.jinaai.JinaAIEmbeddingsRequestEntity.TASK_TYPE_FIELD; public class JinaAIEmbeddingsModel extends JinaAIModel { public static JinaAIEmbeddingsModel of(JinaAIEmbeddingsModel model, Map taskSettings, InputType inputType) { @@ -106,35 +96,4 @@ public ExecutableAction accept(JinaAIActionVisitor visitor, Map public URI uri() { return getServiceSettings().getCommonSettings().uri(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - TASK_TYPE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.DROPDOWN) - .setLabel("Task") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the task type passed to the model.") - .setType(SettingsConfigurationFieldType.STRING) - .setOptions( - Stream.of("retrieval.query", "retrieval.passage", "classification", "separation") - .map(v -> new SettingsConfigurationSelectOption.Builder().setLabelAndValue(v).build()) - .toList() - ) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/rerank/JinaAIRerankModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/rerank/JinaAIRerankModel.java index 2fb9228d3b652..b072d0508c8ee 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/rerank/JinaAIRerankModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/rerank/JinaAIRerankModel.java @@ -7,15 +7,11 @@ package org.elasticsearch.xpack.inference.services.jinaai.rerank; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.jinaai.JinaAIActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; @@ -23,13 +19,8 @@ import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; import java.net.URI; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.jinaai.rerank.JinaAIRerankTaskSettings.RETURN_DOCUMENTS; -import static org.elasticsearch.xpack.inference.services.jinaai.rerank.JinaAIRerankTaskSettings.TOP_N_DOCS_ONLY; - public class JinaAIRerankModel extends JinaAIModel { public static JinaAIRerankModel of(JinaAIRerankModel model, Map taskSettings) { var requestTaskSettings = JinaAIRerankTaskSettings.fromMap(taskSettings); @@ -108,41 +99,4 @@ public ExecutableAction accept(JinaAIActionVisitor visitor, Map public URI uri() { return getServiceSettings().getCommonSettings().uri(); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - RETURN_DOCUMENTS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TOGGLE) - .setLabel("Return Documents") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specify whether to return doc text within the results.") - .setType(SettingsConfigurationFieldType.BOOLEAN) - .setValue(false) - .build() - ); - configurationMap.put( - TOP_N_DOCS_ONLY, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) - .setLabel("Top N") - .setOrder(2) - .setRequired(false) - .setSensitive(false) - .setTooltip("The number of most relevant documents to return, defaults to the number of the documents.") - .setType(SettingsConfigurationFieldType.INTEGER) - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/mistral/MistralService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/mistral/MistralService.java index dc0576651aeba..129d9023a1ebc 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/mistral/MistralService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/mistral/MistralService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,9 +24,7 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -65,6 +62,7 @@ public class MistralService extends SenderService { public static final String NAME = "mistral"; + private static final String SERVICE_NAME = "Mistral"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING); public MistralService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -320,24 +318,24 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription( + "Refer to the Mistral models documentation for the list of available text embedding models." + ) .setLabel("Model") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("Refer to the Mistral models documentation for the list of available text embedding models.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( MAX_INPUT_TOKENS, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) + new SettingsConfiguration.Builder().setDescription("Allows you to specify the maximum number of tokens per input.") .setLabel("Maximum Input Tokens") - .setOrder(3) .setRequired(false) .setSensitive(false) - .setTooltip("Allows you to specify the maximum number of tokens per input.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.INTEGER) .build() ); @@ -345,14 +343,11 @@ public static InferenceServiceConfiguration get() { configurationMap.putAll(DefaultSecretSettings.toSettingsConfiguration()); configurationMap.putAll(RateLimitSettings.toSettingsConfiguration()); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // TEXT_EMBEDDING task type has no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/OpenAiService.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/OpenAiService.java index ed7a01e829dd2..ba9dea8ace8ee 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/OpenAiService.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/OpenAiService.java @@ -16,7 +16,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; import org.elasticsearch.inference.ChunkingSettings; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; @@ -25,9 +24,7 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.SimilarityMeasure; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; @@ -72,6 +69,7 @@ public class OpenAiService extends SenderService { public static final String NAME = "openai"; + private static final String SERVICE_NAME = "OpenAI"; private static final EnumSet supportedTaskTypes = EnumSet.of(TaskType.TEXT_EMBEDDING, TaskType.COMPLETION); public OpenAiService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) { @@ -397,65 +395,58 @@ public static InferenceServiceConfiguration get() { configurationMap.put( MODEL_ID, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The name of the model to use for the inference task.") .setLabel("Model ID") - .setOrder(2) .setRequired(true) .setSensitive(false) - .setTooltip("The name of the model to use for the inference task.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( ORGANIZATION, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription("The unique identifier of your organization.") .setLabel("Organization ID") - .setOrder(3) .setRequired(false) .setSensitive(false) - .setTooltip("The unique identifier of your organization.") + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) .build() ); configurationMap.put( URL, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("URL") - .setOrder(4) - .setRequired(true) - .setSensitive(false) - .setTooltip( + new SettingsConfiguration.Builder().setDefaultValue("https://api.openai.com/v1/chat/completions") + .setDescription( "The OpenAI API endpoint URL. For more information on the URL, refer to the " + "https://platform.openai.com/docs/api-reference." ) + .setLabel("URL") + .setRequired(true) + .setSensitive(false) + .setUpdatable(false) .setType(SettingsConfigurationFieldType.STRING) - .setDefaultValue("https://api.openai.com/v1/chat/completions") .build() ); configurationMap.putAll( - DefaultSecretSettings.toSettingsConfigurationWithTooltip( + DefaultSecretSettings.toSettingsConfigurationWithDescription( "The OpenAI API authentication key. For more details about generating OpenAI API keys, " + "refer to the https://platform.openai.com/account/api-keys." ) ); configurationMap.putAll( - RateLimitSettings.toSettingsConfigurationWithTooltip( + RateLimitSettings.toSettingsConfigurationWithDescription( "Default number of requests allowed per minute. For text_embedding is 3000. For completion is 500." ) ); - return new InferenceServiceConfiguration.Builder().setProvider(NAME).setTaskTypes(supportedTaskTypes.stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - case TEXT_EMBEDDING -> taskSettingsConfig = OpenAiEmbeddingsModel.Configuration.get(); - case COMPLETION -> taskSettingsConfig = OpenAiChatCompletionModel.Configuration.get(); - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()).setConfiguration(configurationMap).build(); + return new InferenceServiceConfiguration.Builder().setService(NAME) + .setName(SERVICE_NAME) + .setTaskTypes(supportedTaskTypes) + .setConfigurations(configurationMap) + .build(); } ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/completion/OpenAiChatCompletionModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/completion/OpenAiChatCompletionModel.java index 7d79d64b3a771..dea703b9ce243 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/completion/OpenAiChatCompletionModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/completion/OpenAiChatCompletionModel.java @@ -7,28 +7,20 @@ package org.elasticsearch.xpack.inference.services.openai.completion; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.inference.UnifiedCompletionRequest; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.openai.OpenAiActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; import org.elasticsearch.xpack.inference.services.openai.OpenAiModel; import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.Objects; -import static org.elasticsearch.xpack.inference.services.openai.OpenAiServiceFields.USER; - public class OpenAiChatCompletionModel extends OpenAiModel { public static OpenAiChatCompletionModel of(OpenAiChatCompletionModel model, Map taskSettings) { @@ -118,30 +110,4 @@ public DefaultSecretSettings getSecretSettings() { public ExecutableAction accept(OpenAiActionVisitor creator, Map taskSettings) { return creator.create(this, taskSettings); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - USER, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("User") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the user issuing the request.") - .setType(SettingsConfigurationFieldType.STRING) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/embeddings/OpenAiEmbeddingsModel.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/embeddings/OpenAiEmbeddingsModel.java index cab2a82fc86c6..5659c46050ad8 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/embeddings/OpenAiEmbeddingsModel.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openai/embeddings/OpenAiEmbeddingsModel.java @@ -7,27 +7,19 @@ package org.elasticsearch.xpack.inference.services.openai.embeddings; -import org.elasticsearch.common.util.LazyInitializable; import org.elasticsearch.core.Nullable; import org.elasticsearch.inference.ChunkingSettings; import org.elasticsearch.inference.ModelConfigurations; import org.elasticsearch.inference.ModelSecrets; -import org.elasticsearch.inference.SettingsConfiguration; import org.elasticsearch.inference.TaskType; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; -import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xpack.inference.external.action.ExecutableAction; import org.elasticsearch.xpack.inference.external.action.openai.OpenAiActionVisitor; import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; import org.elasticsearch.xpack.inference.services.openai.OpenAiModel; import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.inference.services.openai.OpenAiServiceFields.USER; - public class OpenAiEmbeddingsModel extends OpenAiModel { public static OpenAiEmbeddingsModel of(OpenAiEmbeddingsModel model, Map taskSettings) { @@ -105,30 +97,4 @@ public DefaultSecretSettings getSecretSettings() { public ExecutableAction accept(OpenAiActionVisitor creator, Map taskSettings) { return creator.create(this, taskSettings); } - - public static class Configuration { - public static Map get() { - return configuration.getOrCompute(); - } - - private static final LazyInitializable, RuntimeException> configuration = - new LazyInitializable<>(() -> { - var configurationMap = new HashMap(); - - configurationMap.put( - USER, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) - .setLabel("User") - .setOrder(1) - .setRequired(false) - .setSensitive(false) - .setTooltip("Specifies the user issuing the request.") - .setType(SettingsConfigurationFieldType.STRING) - .setValue("") - .build() - ); - - return Collections.unmodifiableMap(configurationMap); - }); - } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/DefaultSecretSettings.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/DefaultSecretSettings.java index 771d2308a502f..15e8128969ddb 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/DefaultSecretSettings.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/DefaultSecretSettings.java @@ -17,7 +17,6 @@ import org.elasticsearch.inference.ModelSecrets; import org.elasticsearch.inference.SecretSettings; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xcontent.XContentBuilder; @@ -52,16 +51,15 @@ public static DefaultSecretSettings fromMap(@Nullable Map map) { return new DefaultSecretSettings(secureApiToken); } - public static Map toSettingsConfigurationWithTooltip(String tooltip) { + public static Map toSettingsConfigurationWithDescription(String description) { var configurationMap = new HashMap(); configurationMap.put( API_KEY, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.TEXTBOX) + new SettingsConfiguration.Builder().setDescription(description) .setLabel("API Key") - .setOrder(1) .setRequired(true) .setSensitive(true) - .setTooltip(tooltip) + .setUpdatable(true) .setType(SettingsConfigurationFieldType.STRING) .build() ); @@ -69,7 +67,7 @@ public static Map toSettingsConfigurationWithTool } public static Map toSettingsConfiguration() { - return DefaultSecretSettings.toSettingsConfigurationWithTooltip("API Key for the provider you're connecting to."); + return DefaultSecretSettings.toSettingsConfigurationWithDescription("API Key for the provider you're connecting to."); } public DefaultSecretSettings { diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/RateLimitSettings.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/RateLimitSettings.java index 416d5bff12ce9..30147a6d24a96 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/RateLimitSettings.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/RateLimitSettings.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.configuration.SettingsConfigurationDisplayType; import org.elasticsearch.inference.configuration.SettingsConfigurationFieldType; import org.elasticsearch.xcontent.ToXContentFragment; import org.elasticsearch.xcontent.XContentBuilder; @@ -52,16 +51,15 @@ public static RateLimitSettings of( return requestsPerMinute == null ? defaultValue : new RateLimitSettings(requestsPerMinute); } - public static Map toSettingsConfigurationWithTooltip(String tooltip) { + public static Map toSettingsConfigurationWithDescription(String description) { var configurationMap = new HashMap(); configurationMap.put( FIELD_NAME + "." + REQUESTS_PER_MINUTE_FIELD, - new SettingsConfiguration.Builder().setDisplay(SettingsConfigurationDisplayType.NUMERIC) + new SettingsConfiguration.Builder().setDescription(description) .setLabel("Rate Limit") - .setOrder(6) .setRequired(false) .setSensitive(false) - .setTooltip(tooltip) + .setUpdatable(false) .setType(SettingsConfigurationFieldType.INTEGER) .build() ); @@ -69,7 +67,7 @@ public static Map toSettingsConfigurationWithTool } public static Map toSettingsConfiguration() { - return RateLimitSettings.toSettingsConfigurationWithTooltip("Minimize the number of rate limit errors."); + return RateLimitSettings.toSettingsConfigurationWithDescription("Minimize the number of rate limit errors."); } /** diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java index f8a5bd8a54d31..69b26585d8d49 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java @@ -12,13 +12,10 @@ import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.core.TimeValue; import org.elasticsearch.inference.ChunkedInference; -import org.elasticsearch.inference.EmptySettingsConfiguration; import org.elasticsearch.inference.InferenceServiceConfiguration; import org.elasticsearch.inference.InferenceServiceResults; import org.elasticsearch.inference.InputType; import org.elasticsearch.inference.Model; -import org.elasticsearch.inference.SettingsConfiguration; -import org.elasticsearch.inference.TaskSettingsConfiguration; import org.elasticsearch.inference.TaskType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -177,16 +174,10 @@ public TransportVersion getMinimalSupportedVersion() { @Override public InferenceServiceConfiguration getConfiguration() { - return new InferenceServiceConfiguration.Builder().setProvider("test service") - .setTaskTypes(supportedTaskTypes().stream().map(t -> { - Map taskSettingsConfig; - switch (t) { - // no task settings - default -> taskSettingsConfig = EmptySettingsConfiguration.get(); - } - return new TaskSettingsConfiguration.Builder().setTaskType(t).setConfiguration(taskSettingsConfig).build(); - }).toList()) - .setConfiguration(new HashMap<>()) + return new InferenceServiceConfiguration.Builder().setService("test service") + .setName("Test") + .setTaskTypes(supportedTaskTypes()) + .setConfigurations(new HashMap<>()) .build(); } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchServiceTests.java index 46c3a062f7db0..e2cb93f731162 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchServiceTests.java @@ -438,209 +438,57 @@ public void testGetConfiguration() throws Exception { String content = XContentHelper.stripWhitespace( """ { - "provider": "alibabacloud-ai-search", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "input_type": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Input Type", - "options": [ - { - "label": "ingest", - "value": "ingest" - }, - { - "label": "search", - "value": "search" - } - ], - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the type of input passed to the model.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - }, - { - "task_type": "sparse_embedding", - "configuration": { - "return_token": { - "default_value": null, - "depends_on": [], - "display": "toggle", - "label": "Return Token", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "If `true`, the token name will be returned in the response. Defaults to `false` which means only the token ID will be returned in the response.", - "type": "bool", - "ui_restrictions": [], - "validations": [], - "value": true - }, - "input_type": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Input Type", - "options": [ - { - "label": "ingest", - "value": "ingest" - }, - { - "label": "search", - "value": "search" - } - ], - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the type of input passed to the model.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - }, - { - "task_type": "rerank", - "configuration": {} - }, - { - "task_type": "completion", - "configuration": {} - } - ], - "configuration": { + "service": "alibabacloud-ai-search", + "name": "AlibabaCloud AI Search", + "task_types": ["text_embedding", "sparse_embedding", "rerank", "completion"], + "configurations": { "workspace": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of the workspace used for the {infer} task.", "label": "Workspace", - "order": 5, "required": true, "sensitive": false, - "tooltip": "The name of the workspace used for the {infer} task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "A valid API key for the AlibabaCloud AI Search API.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "A valid API key for the AlibabaCloud AI Search API.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "service_id": { - "default_value": null, - "depends_on": [], - "display": "dropdown", + "description": "The name of the model service to use for the {infer} task.", "label": "Project ID", - "options": [ - { - "label": "ops-text-embedding-001", - "value": "ops-text-embedding-001" - }, - { - "label": "ops-text-embedding-zh-001", - "value": "ops-text-embedding-zh-001" - }, - { - "label": "ops-text-embedding-en-001", - "value": "ops-text-embedding-en-001" - }, - { - "label": "ops-text-embedding-002", - "value": "ops-text-embedding-002" - }, - { - "label": "ops-text-sparse-embedding-001", - "value": "ops-text-sparse-embedding-001" - }, - { - "label": "ops-bge-reranker-larger", - "value": "ops-bge-reranker-larger" - } - ], - "order": 2, "required": true, "sensitive": false, - "tooltip": "The name of the model service to use for the {infer} task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "host": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of the host address used for the {infer} task. You can find the host address at https://opensearch.console.aliyun.com/cn-shanghai/rag/api-key[ the API keys section] of the documentation.", "label": "Host", - "order": 3, "required": true, "sensitive": false, - "tooltip": "The name of the host address used for the {infer} task. You can find the host address at https://opensearch.console.aliyun.com/cn-shanghai/rag/api-key[ the API keys section] of the documentation.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "http_schema": { - "default_value": null, - "depends_on": [], - "display": "dropdown", + "description": "", "label": "HTTP Schema", - "options": [ - { - "label": "https", - "value": "https" - }, - { - "label": "http", - "value": "http" - } - ], - "order": 4, "required": true, "sensitive": false, - "tooltip": "", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockServiceTests.java index 7ca66d54d8ac3..ce4d928458dca 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockServiceTests.java @@ -154,192 +154,63 @@ public void testParseRequestConfig_ThrowsUnsupportedModelType() throws IOExcepti @SuppressWarnings("checkstyle:LineLength") public void testGetConfiguration() throws Exception { try (var service = createAmazonBedrockService()) { - String content = XContentHelper.stripWhitespace( - """ - { - "provider": "amazonbedrock", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": {} - }, - { - "task_type": "completion", - "configuration": { - "top_p": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top P", - "order": 3, - "required": false, - "sensitive": false, - "tooltip": "Alternative to temperature. A number in the range of 0.0 to 1.0, to eliminate low-probability tokens.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "max_new_tokens": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Max New Tokens", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Sets the maximum number for the output tokens to be generated.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "top_k": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top K", - "order": 4, - "required": false, - "sensitive": false, - "tooltip": "Only available for anthropic, cohere, and mistral providers. Alternative to temperature.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "temperature": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Temperature", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "A number between 0.0 and 1.0 that controls the apparent creativity of the results.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - } - } - } - ], - "configuration": { - "secret_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "Secret Key", - "order": 2, - "required": true, - "sensitive": true, - "tooltip": "A valid AWS secret key that is paired with the access_key.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "provider": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Provider", - "options": [ - { - "label": "amazontitan", - "value": "amazontitan" - }, - { - "label": "anthropic", - "value": "anthropic" - }, - { - "label": "ai21labs", - "value": "ai21labs" - }, - { - "label": "cohere", - "value": "cohere" - }, - { - "label": "meta", - "value": "meta" - }, - { - "label": "mistral", - "value": "mistral" - } - ], - "order": 3, - "required": true, - "sensitive": false, - "tooltip": "The model provider for your deployment.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "access_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "Access Key", - "order": 1, - "required": true, - "sensitive": true, - "tooltip": "A valid AWS access key that has permissions to use Amazon Bedrock.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "model": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "Model", - "order": 4, - "required": true, - "sensitive": false, - "tooltip": "The base model ID or an ARN to a custom model based on a foundational model.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Rate Limit", - "order": 6, - "required": false, - "sensitive": false, - "tooltip": "By default, the amazonbedrock service sets the number of requests allowed per minute to 240.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "region": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "Region", - "order": 5, - "required": true, - "sensitive": false, - "tooltip": "The region that your model or ARN is deployed in.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - } + String content = XContentHelper.stripWhitespace(""" + { + "service": "amazonbedrock", + "name": "Amazon Bedrock", + "task_types": ["text_embedding", "completion"], + "configurations": { + "secret_key": { + "description": "A valid AWS secret key that is paired with the access_key.", + "label": "Secret Key", + "required": true, + "sensitive": true, + "updatable": true, + "type": "str" + }, + "provider": { + "description": "The model provider for your deployment.", + "label": "Provider", + "required": true, + "sensitive": false, + "updatable": false, + "type": "str" + }, + "access_key": { + "description": "A valid AWS access key that has permissions to use Amazon Bedrock.", + "label": "Access Key", + "required": true, + "sensitive": true, + "updatable": true, + "type": "str" + }, + "model": { + "description": "The base model ID or an ARN to a custom model based on a foundational model.", + "label": "Model", + "required": true, + "sensitive": false, + "updatable": false, + "type": "str" + }, + "rate_limit.requests_per_minute": { + "description": "By default, the amazonbedrock service sets the number of requests allowed per minute to 240.", + "label": "Rate Limit", + "required": false, + "sensitive": false, + "updatable": false, + "type": "int" + }, + "region": { + "description": "The region that your model or ARN is deployed in.", + "label": "Region", + "required": true, + "sensitive": false, + "updatable": false, + "type": "str" } } - """ - ); + } + """); InferenceServiceConfiguration configuration = InferenceServiceConfiguration.fromXContentBytes( new BytesArray(content), XContentType.JSON diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicServiceTests.java index 0f802637c6700..7eb7ad1d0a19e 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicServiceTests.java @@ -604,112 +604,33 @@ public void testGetConfiguration() throws Exception { try (var service = createServiceWithMockSender()) { String content = XContentHelper.stripWhitespace(""" { - "provider": "anthropic", - "task_types": [ - { - "task_type": "completion", - "configuration": { - "top_p": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top P", - "order": 4, - "required": false, - "sensitive": false, - "tooltip": "Specifies to use Anthropic’s nucleus sampling.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "max_tokens": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Max Tokens", - "order": 1, - "required": true, - "sensitive": false, - "tooltip": "The maximum number of tokens to generate before stopping.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "top_k": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top K", - "order": 3, - "required": false, - "sensitive": false, - "tooltip": "Specifies to only sample from the top K options for each subsequent token.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "temperature": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "Temperature", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "The amount of randomness injected into the response.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - } - } - } - ], - "configuration": { + "service": "anthropic", + "name": "Anthropic", + "task_types": ["completion"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "API Key for the provider you're connecting to.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "By default, the anthropic service sets the number of requests allowed per minute to 50.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "By default, the anthropic service sets the number of requests allowed per minute to 50.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "model_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of the model to use for the inference task.", "label": "Model ID", - "order": 2, "required": true, "sensitive": false, - "tooltip": "The name of the model to use for the inference task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioServiceTests.java index fe60eaa760e69..72ebd0b96bdc1 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureaistudio/AzureAiStudioServiceTests.java @@ -1389,203 +1389,55 @@ public void testInfer_StreamRequest_ErrorResponse() throws Exception { @SuppressWarnings("checkstyle:LineLength") public void testGetConfiguration() throws Exception { try (var service = createService()) { - String content = XContentHelper.stripWhitespace( - """ - { - "provider": "azureaistudio", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "top_p": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top P", - "order": 4, - "required": false, - "sensitive": false, - "tooltip": "A number in the range of 0.0 to 2.0 that is an alternative value to temperature. Should not be used if temperature is specified.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "max_new_tokens": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Max New Tokens", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "Provides a hint for the maximum number of output tokens to be generated.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "temperature": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Temperature", - "order": 3, - "required": false, - "sensitive": false, - "tooltip": "A number in the range of 0.0 to 2.0 that specifies the sampling temperature.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "do_sample": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Do Sample", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Instructs the inference process to perform sampling or not.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - } - } - }, - { - "task_type": "completion", - "configuration": { - "user": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "User", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the user issuing the request.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - } - ], - "configuration": { - "endpoint_type": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Endpoint Type", - "options": [ - { - "label": "token", - "value": "token" - }, - { - "label": "realtime", - "value": "realtime" - } - ], - "order": 3, - "required": true, - "sensitive": false, - "tooltip": "Specifies the type of endpoint that is used in your model deployment.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "provider": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Provider", - "options": [ - { - "label": "cohere", - "value": "cohere" - }, - { - "label": "meta", - "value": "meta" - }, - { - "label": "microsoft_phi", - "value": "microsoft_phi" - }, - { - "label": "mistral", - "value": "mistral" - }, - { - "label": "openai", - "value": "openai" - }, - { - "label": "databricks", - "value": "databricks" - } - ], - "order": 3, - "required": true, - "sensitive": false, - "tooltip": "The model provider for your deployment.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "API Key", - "order": 1, - "required": true, - "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Rate Limit", - "order": 6, - "required": false, - "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "target": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "Target", - "order": 2, - "required": true, - "sensitive": false, - "tooltip": "The target URL of your Azure AI Studio model deployment.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - } + String content = XContentHelper.stripWhitespace(""" + { + "service": "azureaistudio", + "name": "Azure AI Studio", + "task_types": ["text_embedding", "completion"], + "configurations": { + "endpoint_type": { + "description": "Specifies the type of endpoint that is used in your model deployment.", + "label": "Endpoint Type", + "required": true, + "sensitive": false, + "updatable": false, + "type": "str" + }, + "provider": { + "description": "The model provider for your deployment.", + "label": "Provider", + "required": true, + "sensitive": false, + "updatable": false, + "type": "str" + }, + "api_key": { + "description": "API Key for the provider you're connecting to.", + "label": "API Key", + "required": true, + "sensitive": true, + "updatable": true, + "type": "str" + }, + "rate_limit.requests_per_minute": { + "description": "Minimize the number of rate limit errors.", + "label": "Rate Limit", + "required": false, + "sensitive": false, + "updatable": false, + "type": "int" + }, + "target": { + "description": "The target URL of your Azure AI Studio model deployment.", + "label": "Target", + "required": true, + "sensitive": false, + "updatable": false, + "type": "str" } } - """ - ); + } + """); InferenceServiceConfiguration configuration = InferenceServiceConfiguration.fromXContentBytes( new BytesArray(content), XContentType.JSON diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiServiceTests.java index cf79d70749fda..5c69815cbb0ab 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiServiceTests.java @@ -1460,131 +1460,57 @@ public void testGetConfiguration() throws Exception { String content = XContentHelper.stripWhitespace( """ { - "provider": "azureopenai", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "user": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "User", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the user issuing the request.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - }, - { - "task_type": "completion", - "configuration": { - "user": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "User", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the user issuing the request.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - } - ], - "configuration": { + "service": "azureopenai", + "name": "Azure OpenAI", + "task_types": ["text_embedding", "completion"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "You must provide either an API key or an Entra ID.", "label": "API Key", - "order": 1, "required": false, "sensitive": true, - "tooltip": "You must provide either an API key or an Entra ID.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "entra_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "You must provide either an API key or an Entra ID.", "label": "Entra ID", - "order": 2, "required": false, "sensitive": true, - "tooltip": "You must provide either an API key or an Entra ID.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "The azureopenai service sets a default number of requests allowed per minute depending on the task type.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "The azureopenai service sets a default number of requests allowed per minute depending on the task type.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "deployment_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The deployment name of your deployed models.", "label": "Deployment ID", - "order": 5, "required": true, "sensitive": false, - "tooltip": "The deployment name of your deployed models.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "resource_name": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of your Azure OpenAI resource.", "label": "Resource Name", - "order": 3, "required": true, "sensitive": false, - "tooltip": "The name of your Azure OpenAI resource.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "api_version": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The Azure API version ID to use.", "label": "API Version", - "order": 4, "required": true, "sensitive": false, - "tooltip": "The Azure API version ID to use.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java index bf67db3b2a117..dbad76fd46fc4 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java @@ -1633,147 +1633,31 @@ public void testInfer_StreamRequest_ErrorResponse() throws Exception { @SuppressWarnings("checkstyle:LineLength") public void testGetConfiguration() throws Exception { try (var service = createCohereService()) { - String content = XContentHelper.stripWhitespace( - """ - { - "provider": "cohere", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "truncate": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Truncate", - "options": [ - { - "label": "NONE", - "value": "NONE" - }, - { - "label": "START", - "value": "START" - }, - { - "label": "END", - "value": "END" - } - ], - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "Specifies how the API handles inputs longer than the maximum token length.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - }, - "input_type": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Input Type", - "options": [ - { - "label": "classification", - "value": "classification" - }, - { - "label": "clusterning", - "value": "clusterning" - }, - { - "label": "ingest", - "value": "ingest" - }, - { - "label": "search", - "value": "search" - } - ], - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the type of input passed to the model.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - }, - { - "task_type": "rerank", - "configuration": { - "top_n": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top N", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "The number of most relevant documents to return, defaults to the number of the documents.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "return_documents": { - "default_value": null, - "depends_on": [], - "display": "toggle", - "label": "Return Documents", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specify whether to return doc text within the results.", - "type": "bool", - "ui_restrictions": [], - "validations": [], - "value": false - } - } - }, - { - "task_type": "completion", - "configuration": {} - } - ], - "configuration": { - "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "API Key", - "order": 1, - "required": true, - "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Rate Limit", - "order": 6, - "required": false, - "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - } + String content = XContentHelper.stripWhitespace(""" + { + "service": "cohere", + "name": "Cohere", + "task_types": ["text_embedding", "rerank", "completion"], + "configurations": { + "api_key": { + "description": "API Key for the provider you're connecting to.", + "label": "API Key", + "required": true, + "sensitive": true, + "updatable": true, + "type": "str" + }, + "rate_limit.requests_per_minute": { + "description": "Minimize the number of rate limit errors.", + "label": "Rate Limit", + "required": false, + "sensitive": false, + "updatable": false, + "type": "int" } } - """ - ); + } + """); InferenceServiceConfiguration configuration = InferenceServiceConfiguration.fromXContentBytes( new BytesArray(content), XContentType.JSON diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java index 6cdd58c4cd99f..4b2308b9f1565 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java @@ -496,55 +496,33 @@ public void testGetConfiguration() throws Exception { try (var service = createServiceWithMockSender()) { String content = XContentHelper.stripWhitespace(""" { - "provider": "elastic", - "task_types": [ - { - "task_type": "sparse_embedding", - "configuration": {} - } - ], - "configuration": { + "service": "elastic", + "name": "Elastic", + "task_types": ["sparse_embedding"], + "configurations": { "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "model_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of the model to use for the inference task.", "label": "Model ID", - "order": 2, "required": true, "sensitive": false, - "tooltip": "The name of the model to use for the inference task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "max_input_tokens": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Allows you to specify the maximum number of tokens per input.", "label": "Maximum Input Tokens", - "order": 3, "required": false, "sensitive": false, - "tooltip": "Allows you to specify the maximum number of tokens per input.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalServiceTests.java index 21d7efbc7b03c..803151a5b3476 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalServiceTests.java @@ -1553,100 +1553,36 @@ public void testGetConfiguration() throws Exception { try (var service = createService(mock(Client.class))) { String content = XContentHelper.stripWhitespace(""" { - "provider": "elasticsearch", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": {} - }, - { - "task_type": "sparse_embedding", - "configuration": {} - }, - { - "task_type": "rerank", - "configuration": { - "return_documents": { - "default_value": null, - "depends_on": [], - "display": "toggle", - "label": "Return Documents", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Returns the document instead of only the index.", - "type": "bool", - "ui_restrictions": [], - "validations": [], - "value": true - } - } - } - ], - "configuration": { + "service": "elasticsearch", + "name": "Elasticsearch", + "task_types": ["text_embedding", "sparse_embedding", "rerank"], + "configurations": { "num_allocations": { "default_value": 1, - "depends_on": [], - "display": "numeric", + "description": "The total number of allocations this model is assigned across machine learning nodes.", "label": "Number Allocations", - "order": 2, "required": true, "sensitive": false, - "tooltip": "The total number of allocations this model is assigned across machine learning nodes.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "int" }, "num_threads": { "default_value": 2, - "depends_on": [], - "display": "numeric", + "description": "Sets the number of threads used by each model allocation during inference.", "label": "Number Threads", - "order": 3, "required": true, "sensitive": false, - "tooltip": "Sets the number of threads used by each model allocation during inference.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "model_id": { "default_value": ".multilingual-e5-small", - "depends_on": [], - "display": "dropdown", + "description": "The name of the model to use for the inference task.", "label": "Model ID", - "options": [ - { - "label": ".elser_model_1", - "value": ".elser_model_1" - }, - { - "label": ".elser_model_2", - "value": ".elser_model_2" - }, - { - "label": ".elser_model_2_linux-x86_64", - "value": ".elser_model_2_linux-x86_64" - }, - { - "label": ".multilingual-e5-small", - "value": ".multilingual-e5-small" - }, - { - "label": ".multilingual-e5-small_linux-x86_64", - "value": ".multilingual-e5-small_linux-x86_64" - } - ], - "order": 1, "required": true, "sensitive": false, - "tooltip": "The name of the model to use for the inference task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioServiceTests.java index 3e43bd7c77684..aa45666eb0fb1 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioServiceTests.java @@ -1123,59 +1123,33 @@ public void testGetConfiguration() throws Exception { try (var service = createGoogleAiStudioService()) { String content = XContentHelper.stripWhitespace(""" { - "provider": "googleaistudio", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": {} - }, - { - "task_type": "completion", - "configuration": {} - } - ], - "configuration": { + "service": "googleaistudio", + "name": "Google AI Studio", + "task_types": ["text_embedding", "completion"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "API Key for the provider you're connecting to.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "model_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "ID of the LLM you're using.", "label": "Model ID", - "order": 2, "required": true, "sensitive": false, - "tooltip": "ID of the LLM you're using.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiServiceTests.java index 2aeba5fcbe209..555e9f0785fa2 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiServiceTests.java @@ -869,149 +869,49 @@ public void testGetConfiguration() throws Exception { String content = XContentHelper.stripWhitespace( """ { - "provider": "googlevertexai", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "input_type": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Input Type", - "options": [ - { - "label": "classification", - "value": "classification" - }, - { - "label": "clustering", - "value": "clustering" - }, - { - "label": "ingest", - "value": "ingest" - }, - { - "label": "search", - "value": "search" - } - ], - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the type of input passed to the model.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - }, - "auto_truncate": { - "default_value": null, - "depends_on": [], - "display": "toggle", - "label": "Auto Truncate", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "Specifies if the API truncates inputs longer than the maximum token length automatically.", - "type": "bool", - "ui_restrictions": [], - "validations": [], - "value": false - } - } - }, - { - "task_type": "rerank", - "configuration": { - "top_n": { - "default_value": null, - "depends_on": [], - "display": "toggle", - "label": "Top N", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the number of the top n documents, which should be returned.", - "type": "bool", - "ui_restrictions": [], - "validations": [], - "value": false - } - } - } - ], - "configuration": { + "service": "googlevertexai", + "name": "Google Vertex AI", + "task_types": ["text_embedding", "rerank"], + "configurations": { "service_account_json": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "API Key for the provider you're connecting to.", "label": "Credentials JSON", - "order": 1, "required": true, "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "project_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The GCP Project ID which has Vertex AI API(s) enabled. For more information on the URL, refer to the {geminiVertexAIDocs}.", "label": "GCP Project", - "order": 4, "required": true, "sensitive": false, - "tooltip": "The GCP Project ID which has Vertex AI API(s) enabled. For more information on the URL, refer to the {geminiVertexAIDocs}.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "location": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "Please provide the GCP region where the Vertex AI API(s) is enabled. For more information, refer to the {geminiVertexAIDocs}.", "label": "GCP Region", - "order": 3, "required": true, "sensitive": false, - "tooltip": "Please provide the GCP region where the Vertex AI API(s) is enabled. For more information, refer to the {geminiVertexAIDocs}.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "model_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "ID of the LLM you're using.", "label": "Model ID", - "order": 2, "required": true, "sensitive": false, - "tooltip": "ID of the LLM you're using.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceElserServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceElserServiceTests.java index 12811b6be87b3..0b774badd56b6 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceElserServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceElserServiceTests.java @@ -140,55 +140,33 @@ public void testGetConfiguration() throws Exception { ) { String content = XContentHelper.stripWhitespace(""" { - "provider": "hugging_face_elser", - "task_types": [ - { - "task_type": "sparse_embedding", - "configuration": {} - } - ], - "configuration": { + "service": "hugging_face_elser", + "name": "Hugging Face ELSER", + "task_types": ["sparse_embedding"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "API Key for the provider you're connecting to.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "url": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The URL endpoint to use for the requests.", "label": "URL", - "order": 1, "required": true, "sensitive": false, - "tooltip": "The URL endpoint to use for the requests.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceServiceTests.java index 2d30fd5aba4c2..1399712450af1 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceServiceTests.java @@ -858,59 +858,34 @@ public void testGetConfiguration() throws Exception { try (var service = createHuggingFaceService()) { String content = XContentHelper.stripWhitespace(""" { - "provider": "hugging_face", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": {} - }, - { - "task_type": "sparse_embedding", - "configuration": {} - } - ], - "configuration": { + "service": "hugging_face", + "name": "Hugging Face", + "task_types": ["text_embedding", "sparse_embedding"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "API Key for the provider you're connecting to.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "url": { "default_value": "https://api.openai.com/v1/embeddings", - "depends_on": [], - "display": "textbox", + "description": "The URL endpoint to use for the requests.", "label": "URL", - "order": 1, "required": true, "sensitive": false, - "tooltip": "The URL endpoint to use for the requests.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "https://api.openai.com/v1/embeddings" + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxServiceTests.java index 3d298823ea19f..6e744fffbff41 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxServiceTests.java @@ -975,83 +975,49 @@ public void testGetConfiguration() throws Exception { try (var service = createIbmWatsonxService()) { String content = XContentHelper.stripWhitespace(""" { - "provider": "watsonxai", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": {} - } - ], - "configuration": { + "service": "watsonxai", + "name": "IBM Watsonx", + "task_types": ["text_embedding"], + "configurations": { "project_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "", "label": "Project ID", - "order": 2, "required": true, "sensitive": false, - "tooltip": "", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "model_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of the model to use for the inference task.", "label": "Model ID", - "order": 3, "required": true, "sensitive": false, - "tooltip": "The name of the model to use for the inference task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "api_version": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The IBM Watsonx API version ID to use.", "label": "API Version", - "order": 1, "required": true, "sensitive": false, - "tooltip": "The IBM Watsonx API version ID to use.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "max_input_tokens": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Allows you to specify the maximum number of tokens per input.", "label": "Maximum Input Tokens", - "order": 5, "required": false, "sensitive": false, - "tooltip": "Allows you to specify the maximum number of tokens per input.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "url": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "", "label": "URL", - "order": 4, "required": true, "sensitive": false, - "tooltip": "", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIServiceTests.java index 5a1bf8ec383c1..6e68bde6a1266 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIServiceTests.java @@ -1831,115 +1831,31 @@ public void testDefaultSimilarity() { @SuppressWarnings("checkstyle:LineLength") public void testGetConfiguration() throws Exception { try (var service = createJinaAIService()) { - String content = XContentHelper.stripWhitespace( - """ - { - "provider": "jinaai", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "task": { - "default_value": null, - "depends_on": [], - "display": "dropdown", - "label": "Task", - "options": [ - { - "label": "retrieval.query", - "value": "retrieval.query" - }, - { - "label": "retrieval.passage", - "value": "retrieval.passage" - }, - { - "label": "classification", - "value": "classification" - }, - { - "label": "separation", - "value": "separation" - } - ], - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the task type passed to the model.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - }, - { - "task_type": "rerank", - "configuration": { - "top_n": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Top N", - "order": 2, - "required": false, - "sensitive": false, - "tooltip": "The number of most relevant documents to return, defaults to the number of the documents.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "return_documents": { - "default_value": null, - "depends_on": [], - "display": "toggle", - "label": "Return Documents", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specify whether to return doc text within the results.", - "type": "bool", - "ui_restrictions": [], - "validations": [], - "value": false - } - } - } - ], - "configuration": { - "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "API Key", - "order": 1, - "required": true, - "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null - }, - "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", - "label": "Rate Limit", - "order": 6, - "required": false, - "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null - } + String content = XContentHelper.stripWhitespace(""" + { + "service": "jinaai", + "name": "Jina AI", + "task_types": ["text_embedding", "rerank"], + "configurations": { + "api_key": { + "description": "API Key for the provider you're connecting to.", + "label": "API Key", + "required": true, + "sensitive": true, + "updatable": true, + "type": "str" + }, + "rate_limit.requests_per_minute": { + "description": "Minimize the number of rate limit errors.", + "label": "Rate Limit", + "required": false, + "sensitive": false, + "updatable": false, + "type": "int" } } - """ - ); + } + """); InferenceServiceConfiguration configuration = InferenceServiceConfiguration.fromXContentBytes( new BytesArray(content), XContentType.JSON diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/mistral/MistralServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/mistral/MistralServiceTests.java index f164afe604b43..395e29240dfd4 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/mistral/MistralServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/mistral/MistralServiceTests.java @@ -748,69 +748,41 @@ public void testGetConfiguration() throws Exception { try (var service = createService()) { String content = XContentHelper.stripWhitespace(""" { - "provider": "mistral", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": {} - } - ], - "configuration": { + "service": "mistral", + "name": "Mistral", + "task_types": ["text_embedding"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "API Key for the provider you're connecting to.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "API Key for the provider you're connecting to.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "model": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "Refer to the Mistral models documentation for the list of available text embedding models.", "label": "Model", - "order": 2, "required": true, "sensitive": false, - "tooltip": "Refer to the Mistral models documentation for the list of available text embedding models.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Minimize the number of rate limit errors.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Minimize the number of rate limit errors.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "max_input_tokens": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Allows you to specify the maximum number of tokens per input.", "label": "Maximum Input Tokens", - "order": 3, "required": false, "sensitive": false, - "tooltip": "Allows you to specify the maximum number of tokens per input.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" } } } diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/openai/OpenAiServiceTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/openai/OpenAiServiceTests.java index b595862775053..03eacf17a8250 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/openai/OpenAiServiceTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/openai/OpenAiServiceTests.java @@ -1661,117 +1661,50 @@ public void testGetConfiguration() throws Exception { String content = XContentHelper.stripWhitespace( """ { - "provider": "openai", - "task_types": [ - { - "task_type": "text_embedding", - "configuration": { - "user": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "User", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the user issuing the request.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - }, - { - "task_type": "completion", - "configuration": { - "user": { - "default_value": null, - "depends_on": [], - "display": "textbox", - "label": "User", - "order": 1, - "required": false, - "sensitive": false, - "tooltip": "Specifies the user issuing the request.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": "" - } - } - } - ], - "configuration": { + "service": "openai", + "name": "OpenAI", + "task_types": ["text_embedding", "completion"], + "configurations": { "api_key": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The OpenAI API authentication key. For more details about generating OpenAI API keys, refer to the https://platform.openai.com/account/api-keys.", "label": "API Key", - "order": 1, "required": true, "sensitive": true, - "tooltip": "The OpenAI API authentication key. For more details about generating OpenAI API keys, refer to the https://platform.openai.com/account/api-keys.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": true, + "type": "str" }, "organization_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The unique identifier of your organization.", "label": "Organization ID", - "order": 3, "required": false, "sensitive": false, - "tooltip": "The unique identifier of your organization.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "rate_limit.requests_per_minute": { - "default_value": null, - "depends_on": [], - "display": "numeric", + "description": "Default number of requests allowed per minute. For text_embedding is 3000. For completion is 500.", "label": "Rate Limit", - "order": 6, "required": false, "sensitive": false, - "tooltip": "Default number of requests allowed per minute. For text_embedding is 3000. For completion is 500.", - "type": "int", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "int" }, "model_id": { - "default_value": null, - "depends_on": [], - "display": "textbox", + "description": "The name of the model to use for the inference task.", "label": "Model ID", - "order": 2, "required": true, "sensitive": false, - "tooltip": "The name of the model to use for the inference task.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" }, "url": { "default_value": "https://api.openai.com/v1/chat/completions", - "depends_on": [], - "display": "textbox", + "description": "The OpenAI API endpoint URL. For more information on the URL, refer to the https://platform.openai.com/docs/api-reference.", "label": "URL", - "order": 4, "required": true, "sensitive": false, - "tooltip": "The OpenAI API endpoint URL. For more information on the URL, refer to the https://platform.openai.com/docs/api-reference.", - "type": "str", - "ui_restrictions": [], - "validations": [], - "value": null + "updatable": false, + "type": "str" } } }