Skip to content

Commit da55903

Browse files
Add unit tests for LlamaEmbeddingsRequestEntity to validate XContent serialization
1 parent 1573d53 commit da55903

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.services.llama.request.embeddings;
9+
10+
import org.elasticsearch.common.Strings;
11+
import org.elasticsearch.common.xcontent.XContentHelper;
12+
import org.elasticsearch.test.ESTestCase;
13+
import org.elasticsearch.xcontent.XContentBuilder;
14+
import org.elasticsearch.xcontent.XContentFactory;
15+
import org.elasticsearch.xcontent.XContentType;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
20+
import static org.hamcrest.CoreMatchers.is;
21+
22+
public class LlamaEmbeddingsRequestEntityTests extends ESTestCase {
23+
24+
public void testXContent_Success() throws IOException {
25+
var entity = new LlamaEmbeddingsRequestEntity("llama-embed", List.of("ABDC"));
26+
27+
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
28+
entity.toXContent(builder, null);
29+
String xContentResult = Strings.toString(builder);
30+
31+
assertThat(xContentResult, is(XContentHelper.stripWhitespace("""
32+
{
33+
"model_id": "llama-embed",
34+
"contents": ["ABDC"]
35+
}
36+
""")));
37+
}
38+
}

0 commit comments

Comments
 (0)