Skip to content

Add generic inference service and model #127335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/127335.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 127335
summary: Add generic inference service and model
area: Machine Learning
type: enhancement
issues: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.inference.services.generic;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.inference.SecretSettings;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

public class GenericInferenceSecretSettings implements SecretSettings {
private final String NAME = "generic_service_secret_settings";
private final Map<String, Object> settings;

public GenericInferenceSecretSettings(Map<String, Object> settings) {
this.settings = settings;
}

public GenericInferenceSecretSettings(StreamInput in) throws IOException {
this.settings = in.readGenericMap();
}

@Override
public SecretSettings newSecretSettings(Map<String, Object> newSecrets) {
return new GenericInferenceSecretSettings(newSecrets);
}

@Override
public String getWriteableName() {
return NAME;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
return null; // TODO: add minimal support version when launching generic inference service
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeGenericMap(settings);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.map(settings);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.inference.services.generic;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.inference.ChunkedInference;
import org.elasticsearch.inference.InferenceServiceConfiguration;
import org.elasticsearch.inference.InferenceServiceResults;
import org.elasticsearch.inference.InputType;
import org.elasticsearch.inference.Model;
import org.elasticsearch.inference.TaskType;
import org.elasticsearch.xpack.inference.external.http.sender.DocumentsOnlyInput;
import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSender;
import org.elasticsearch.xpack.inference.external.http.sender.InferenceInputs;
import org.elasticsearch.xpack.inference.external.http.sender.UnifiedChatInput;
import org.elasticsearch.xpack.inference.services.SenderService;
import org.elasticsearch.xpack.inference.services.ServiceComponents;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;

public class GenericInferenceService extends SenderService {

public GenericInferenceService(HttpRequestSender.Factory factory, ServiceComponents serviceComponents) {
super(factory, serviceComponents);
}

@Override
public void parseRequestConfig(
String modelId,
TaskType taskType,
Map<String, Object> config,
ActionListener<Model> parsedModelListener
) {
throw new UnsupportedOperationException("Parsing request config is not supported by the generic service");
}

@Override
public Model parsePersistedConfigWithSecrets(
String modelId,
TaskType taskType,
Map<String, Object> config,
Map<String, Object> secrets
) {
throw new UnsupportedOperationException("Parsing persisted config with secrets is not supported by the generic service");
}

@Override
public Model parsePersistedConfig(String modelId, TaskType taskType, Map<String, Object> config) {
throw new UnsupportedOperationException("Parsing persisted config is not supported by the generic service");
}

@Override
protected void doInfer(
Model model,
InferenceInputs inputs,
Map<String, Object> taskSettings,
InputType inputType,
TimeValue timeout,
ActionListener<InferenceServiceResults> listener
) {
throw new UnsupportedOperationException("Inference is not supported by the generic service");
}

@Override
protected void doUnifiedCompletionInfer(
Model model,
UnifiedChatInput inputs,
TimeValue timeout,
ActionListener<InferenceServiceResults> listener
) {
throw new UnsupportedOperationException("Unified completion inference is not supported by the generic service");
}

@Override
protected void doChunkedInfer(
Model model,
DocumentsOnlyInput inputs,
Map<String, Object> taskSettings,
InputType inputType,
TimeValue timeout,
ActionListener<List<ChunkedInference>> listener
) {
throw new UnsupportedOperationException("Chunked inference is not supported by the generic service");
}

@Override
public String name() {
// TODO: Return the name of the service from the parsed service schema
return "generic";
}

@Override
public InferenceServiceConfiguration getConfiguration() {
// TODO: Identify a way to build a configuration for the generic service from the service schema
return null;
}

@Override
public EnumSet<TaskType> supportedTaskTypes() {
// TODO: Add task types as we add support for them
return null;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
// TODO: Add a minimal version when we are ready to launch the generic service
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.inference.services.generic.model;

import org.elasticsearch.inference.Model;
import org.elasticsearch.inference.ModelConfigurations;
import org.elasticsearch.inference.ModelSecrets;
import org.elasticsearch.inference.TaskType;
import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder;
import org.elasticsearch.xpack.inference.services.generic.GenericInferenceSecretSettings;

import java.util.Map;

public class GenericInferenceServiceModel extends Model {

public GenericInferenceServiceModel(String inferenceEntityId, TaskType taskType, String service, Map<String, Object> modelConfig) {
super(
new ModelConfigurations(
inferenceEntityId,
taskType,
service,
new GenericInferenceServiceSettings(modelConfig),
new GenericInferenceTaskSettings(modelConfig),
ChunkingSettingsBuilder.fromMap(modelConfig)
),
new ModelSecrets(new GenericInferenceSecretSettings(modelConfig))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.inference.services.generic.model;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.inference.ServiceSettings;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

public class GenericInferenceServiceSettings implements ServiceSettings {
private final String NAME = "generic_service_settings";
private final Map<String, Object> settings;

public GenericInferenceServiceSettings(Map<String, Object> settings) {
this.settings = settings;
}

public GenericInferenceServiceSettings(StreamInput in) throws IOException {
this.settings = in.readGenericMap();
}

@Override
public String modelId() {
return settings.getOrDefault("model_id", "").toString();
}

@Override
public String getWriteableName() {
return NAME;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
return null; // TODO: add minimal support version when launching generic inference service
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeGenericMap(settings);
}

@Override
public ToXContentObject getFilteredXContentObject() {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.map(settings);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.inference.services.generic.model;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.inference.TaskSettings;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

public class GenericInferenceTaskSettings implements TaskSettings {
private final String NAME = "generic_service_task_settings";
private final Map<String, Object> settings;

public GenericInferenceTaskSettings(Map<String, Object> settings) {
this.settings = settings;
}

public GenericInferenceTaskSettings(StreamInput in) throws IOException {
this.settings = in.readGenericMap();
}

@Override
public boolean isEmpty() {
return settings.isEmpty();
}

@Override
public TaskSettings updatedTaskSettings(Map<String, Object> newSettings) {
return new GenericInferenceTaskSettings(newSettings);
}

@Override
public String getWriteableName() {
return NAME;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
return null; // TODO: add minimal support version when launching generic inference service
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeGenericMap(settings);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.map(settings);
return builder;
}
}
Loading