Skip to content

Commit e47cb9c

Browse files
Merge branch 'ml-inference-unified-api-elastic' of github.com:elastic/elasticsearch into ml-inference-unified-api-elastic
2 parents 881f162 + 00ae5ab commit e47cb9c

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/openai/OpenAiUnifiedStreamingProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ public static class ChatCompletionChunkParser {
146146
);
147147
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField(MODEL_FIELD));
148148
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField(OBJECT_FIELD));
149-
PARSER.declareObject(
149+
PARSER.declareObjectOrNull(
150150
ConstructingObjectParser.optionalConstructorArg(),
151151
(p, c) -> ChatCompletionChunkParser.UsageParser.parse(p),
152+
null,
152153
new ParseField(USAGE_FIELD)
153154
);
154155
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/openai/OpenAiUnifiedStreamingProcessorTests.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ public void testJsonLiteralCornerCases() {
131131
],
132132
"model": "example_model",
133133
"object": "chat.completion.chunk",
134-
"usage": {
135-
"completion_tokens": 50,
136-
"prompt_tokens": 20,
137-
"total_tokens": 70
138-
}
134+
"usage": null
139135
}
140136
""";
141137
// Parse the JSON
@@ -150,10 +146,7 @@ public void testJsonLiteralCornerCases() {
150146
assertEquals("example_id", chunk.getId());
151147
assertEquals("example_model", chunk.getModel());
152148
assertEquals("chat.completion.chunk", chunk.getObject());
153-
assertNotNull(chunk.getUsage());
154-
assertEquals(50, chunk.getUsage().completionTokens());
155-
assertEquals(20, chunk.getUsage().promptTokens());
156-
assertEquals(70, chunk.getUsage().totalTokens());
149+
assertNull(chunk.getUsage());
157150

158151
List<StreamingUnifiedChatCompletionResults.ChatCompletionChunk.Choice> choices = chunk.getChoices();
159152
assertEquals(2, choices.size());

0 commit comments

Comments
 (0)