@@ -196,26 +196,26 @@ public ChatResponse internalCall(Prompt prompt, ChatResponse previousChatRespons
196
196
return new ChatResponse (List .of ());
197
197
}
198
198
199
- List <Generation > generations = choices .stream ().map (choice -> {
200
199
// @formatter:off
200
+ List <Generation > generations = choices .stream ().map (choice -> {
201
201
Map <String , Object > metadata = Map .of (
202
202
"id" , chatCompletion .id () != null ? chatCompletion .id () : "" ,
203
203
"role" , choice .message ().role () != null ? choice .message ().role ().name () : "" ,
204
204
"index" , choice .index (),
205
205
"finishReason" , choice .finishReason () != null ? choice .finishReason ().name () : "" ,
206
206
"refusal" , StringUtils .hasText (choice .message ().refusal ()) ? choice .message ().refusal () : "" );
207
- // @formatter:on
208
207
return buildGeneration (choice , metadata , request );
209
208
}).toList ();
209
+ // @formatter:on
210
210
211
211
RateLimit rateLimit = OpenAiResponseHeaderExtractor .extractAiResponseHeaders (completionEntity );
212
212
213
213
// Current usage
214
- OpenAiApi .Usage usage = completionEntity . getBody () .usage ();
214
+ OpenAiApi .Usage usage = chatCompletion .usage ();
215
215
Usage currentChatResponseUsage = usage != null ? getDefaultUsage (usage ) : new EmptyUsage ();
216
216
Usage accumulatedUsage = UsageUtils .getCumulativeUsage (currentChatResponseUsage , previousChatResponse );
217
217
ChatResponse chatResponse = new ChatResponse (generations ,
218
- from (completionEntity . getBody () , rateLimit , accumulatedUsage ));
218
+ from (chatCompletion , rateLimit , accumulatedUsage ));
219
219
220
220
observationContext .setResponse (chatResponse );
221
221
0 commit comments