Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public record ElasticInferenceServiceSparseEmbeddingsRequestEntity(
) implements ToXContentObject {

private static final String INPUT_FIELD = "input";
private static final String MODEL_ID_FIELD = "model_id";
private static final String MODEL_FIELD = "model";
private static final String USAGE_CONTEXT = "usage_context";

public ElasticInferenceServiceSparseEmbeddingsRequestEntity {
Expand All @@ -42,7 +42,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

builder.endArray();

builder.field(MODEL_ID_FIELD, modelId);
builder.field(MODEL_FIELD, modelId);

// optional field
if ((usageContext == ElasticInferenceServiceUsageContext.UNSPECIFIED) == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testExecute_ReturnsSuccessfulResponse_ForElserAction() throws IOExce
assertThat(requestMap.get("input"), instanceOf(List.class));
var inputList = (List<String>) requestMap.get("input");
assertThat(inputList, contains("hello world"));
assertThat(requestMap.get("model_id"), is("my-model-id"));
assertThat(requestMap.get("model"), is("my-model-id"));
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ public void testSend_FailsFromInvalidResponseFormat_ForElserAction() throws IOEx
assertThat(requestMap.get("input"), instanceOf(List.class));
var inputList = (List<String>) requestMap.get("input");
assertThat(inputList, contains("hello world"));
assertThat(requestMap.get("model_id"), is("my-model-id"));
assertThat(requestMap.get("model"), is("my-model-id"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testToXContent_SingleInput_UnspecifiedUsageContext() throws IOExcept
assertThat(xContentString, equalToIgnoringWhitespaceInJsonString("""
{
"input": ["abc"],
"model_id": "my-model-id"
"model": "my-model-id"
}"""));
}

Expand All @@ -48,7 +48,7 @@ public void testToXContent_MultipleInputs_UnspecifiedUsageContext() throws IOExc
"abc",
"def"
],
"model_id": "my-model-id"
"model": "my-model-id"
}
"""));
}
Expand All @@ -63,7 +63,7 @@ public void testToXContent_MultipleInputs_SearchUsageContext() throws IOExceptio
assertThat(xContentString, equalToIgnoringWhitespaceInJsonString("""
{
"input": ["abc"],
"model_id": "my-model-id",
"model": "my-model-id",
"usage_context": "search"
}
"""));
Expand All @@ -79,7 +79,7 @@ public void testToXContent_MultipleInputs_IngestUsageContext() throws IOExceptio
assertThat(xContentString, equalToIgnoringWhitespaceInJsonString("""
{
"input": ["abc"],
"model_id": "my-model-id",
"model": "my-model-id",
"usage_context": "ingest"
}
"""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testCreateHttpRequest_UsageContextSearch() throws IOException {
var requestMap = entityAsMap(httpPost.getEntity().getContent());
assertThat(requestMap.size(), equalTo(3));
assertThat(requestMap.get("input"), is(List.of(input)));
assertThat(requestMap.get("model_id"), is(modelId));
assertThat(requestMap.get("model"), is(modelId));
assertThat(requestMap.get("usage_context"), equalTo("search"));
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public void testTruncate_ReducesInputTextSizeByHalf() throws IOException {
var requestMap = entityAsMap(httpPost.getEntity().getContent());
assertThat(requestMap, aMapWithSize(2));
assertThat(requestMap.get("input"), is(List.of("ab")));
assertThat(requestMap.get("model_id"), is(modelId));
assertThat(requestMap.get("model"), is(modelId));
}

public void testIsTruncated_ReturnsTrue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void testInfer_SendsEmbeddingsRequest() throws IOException {
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE), Matchers.equalTo(XContentType.JSON.mediaType()));

var requestMap = entityAsMap(request.getBody());
assertThat(requestMap, is(Map.of("input", List.of("input text"), "model_id", "my-model-id", "usage_context", "search")));
assertThat(requestMap, is(Map.of("input", List.of("input text"), "model", "my-model-id", "usage_context", "search")));
}
}

Expand Down Expand Up @@ -562,7 +562,7 @@ public void testChunkedInfer_PassesThrough() throws IOException {
);

var requestMap = entityAsMap(webServer.requests().get(0).getBody());
assertThat(requestMap, is(Map.of("input", List.of("input text"), "model_id", "my-model-id", "usage_context", "ingest")));
assertThat(requestMap, is(Map.of("input", List.of("input text"), "model", "my-model-id", "usage_context", "ingest")));
}
}

Expand Down