|
16 | 16 | import org.elasticsearch.inference.TaskSettings; |
17 | 17 | import org.elasticsearch.inference.TaskType; |
18 | 18 | import org.elasticsearch.inference.UnifiedCompletionRequest; |
| 19 | +import org.elasticsearch.xpack.inference.external.request.openai.OpenAiUnifiedChatCompletionRequest; |
19 | 20 | import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; |
20 | 21 | import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceComponents; |
21 | 22 | import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceModel; |
22 | 23 | import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceSparseEmbeddingsServiceSettings; |
23 | | -import org.elasticsearch.xpack.inference.services.elasticsearch.ElserModels; |
24 | | -import org.elasticsearch.xpack.inference.services.openai.completion.OpenAiChatCompletionModel; |
25 | | -import org.elasticsearch.xpack.inference.services.openai.completion.OpenAiChatCompletionServiceSettings; |
26 | 24 |
|
27 | 25 | import java.net.URI; |
28 | 26 | import java.net.URISyntaxException; |
29 | | -import java.util.Locale; |
30 | 27 | import java.util.Map; |
31 | 28 | import java.util.Objects; |
32 | 29 |
|
33 | | -import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.ELASTIC_INFERENCE_SERVICE_IDENTIFIER; |
34 | | - |
35 | 30 | public class ElasticInferenceServiceCompletionModel extends ElasticInferenceServiceModel { |
36 | 31 |
|
37 | | - public static ElasticInferenceServiceCompletionModel of(ElasticInferenceServiceCompletionModel model, UnifiedCompletionRequest request) { |
| 32 | + public static ElasticInferenceServiceCompletionModel of( |
| 33 | + ElasticInferenceServiceCompletionModel model, |
| 34 | + UnifiedCompletionRequest request |
| 35 | + ) { |
38 | 36 | var originalModelServiceSettings = model.getServiceSettings(); |
39 | 37 | var overriddenServiceSettings = new ElasticInferenceServiceCompletionServiceSettings( |
40 | 38 | Objects.requireNonNullElse(request.model(), originalModelServiceSettings.modelId()), |
41 | 39 | originalModelServiceSettings.rateLimitSettings() |
42 | 40 | ); |
43 | 41 |
|
44 | | - return new ElasticInferenceServiceCompletionModel( |
45 | | - model.getInferenceEntityId(), |
46 | | - model.getTaskType(), |
47 | | - model.getConfigurations().getService(), |
48 | | - overriddenServiceSettings, |
49 | | - model.getTaskSettings(), |
50 | | - model.getSecretSettings() |
51 | | - ); |
| 42 | + return new ElasticInferenceServiceCompletionModel(model, overriddenServiceSettings); |
52 | 43 | } |
53 | 44 |
|
54 | 45 | private final URI uri; |
@@ -76,7 +67,7 @@ public ElasticInferenceServiceCompletionModel( |
76 | 67 |
|
77 | 68 | public ElasticInferenceServiceCompletionModel( |
78 | 69 | ElasticInferenceServiceCompletionModel model, |
79 | | - ElasticInferenceServiceSparseEmbeddingsServiceSettings serviceSettings |
| 70 | + ElasticInferenceServiceCompletionServiceSettings serviceSettings |
80 | 71 | ) { |
81 | 72 | super(model, serviceSettings); |
82 | 73 |
|
@@ -121,18 +112,17 @@ public URI uri() { |
121 | 112 |
|
122 | 113 | private URI createUri() throws URISyntaxException { |
123 | 114 | String modelId = getServiceSettings().modelId(); |
124 | | -// String modelIdUriPath; |
125 | | -// |
126 | | -// switch (modelId) { |
127 | | -// case ElserModels.ELSER_V2_MODEL -> modelIdUriPath = "ELSERv2"; |
128 | | -// default -> throw new IllegalArgumentException( |
129 | | -// String.format(Locale.ROOT, "Unsupported model for %s [%s]", ELASTIC_INFERENCE_SERVICE_IDENTIFIER, modelId) |
130 | | -// ); |
131 | | -// } |
| 115 | + // String modelIdUriPath; |
| 116 | + // |
| 117 | + // switch (modelId) { |
| 118 | + // case ElserModels.ELSER_V2_MODEL -> modelIdUriPath = "ELSERv2"; |
| 119 | + // default -> throw new IllegalArgumentException( |
| 120 | + // String.format(Locale.ROOT, "Unsupported model for %s [%s]", ELASTIC_INFERENCE_SERVICE_IDENTIFIER, modelId) |
| 121 | + // ); |
| 122 | + // } |
132 | 123 |
|
133 | 124 | // TODO what is the url? |
134 | | -// return new URI(elasticInferenceServiceComponents().elasticInferenceServiceUrl() + "/api/v1/completion/" + modelIdUriPath); |
135 | | - |
136 | | - return |
| 125 | + // return new URI(elasticInferenceServiceComponents().elasticInferenceServiceUrl() + "/api/v1/completion/" + modelId); |
| 126 | + return OpenAiUnifiedChatCompletionRequest.buildDefaultUri(); |
137 | 127 | } |
138 | 128 | } |
0 commit comments