@@ -9,6 +9,16 @@ export interface GroqChatCompleteResponse extends ChatCompletionResponse {}
99
1010export interface GroqErrorResponse extends ErrorResponse { }
1111
12+ export interface GroqStreamChunkUsage {
13+ queue_time : number ;
14+ prompt_tokens : number ;
15+ prompt_time : number ;
16+ completion_tokens : number ;
17+ completion_time : number ;
18+ total_tokens : number ;
19+ total_time : number ;
20+ }
21+
1222export interface GroqStreamChunk {
1323 id : string ;
1424 object : string ;
@@ -24,16 +34,9 @@ export interface GroqStreamChunk {
2434 logprobs : object | null ;
2535 } [ ] ;
2636 x_groq : {
27- usage : {
28- queue_time : number ;
29- prompt_tokens : number ;
30- prompt_time : number ;
31- completion_tokens : number ;
32- completion_time : number ;
33- total_tokens : number ;
34- total_time : number ;
35- } ;
37+ usage : GroqStreamChunkUsage ;
3638 } ;
39+ usage : GroqStreamChunkUsage ;
3740}
3841
3942export const GroqChatCompleteResponseTransform : (
@@ -115,17 +118,27 @@ export const GroqChatCompleteStreamChunkTransform: (
115118 created : parsedChunk . created ,
116119 model : parsedChunk . model ,
117120 provider : GROQ ,
118- choices : [
119- {
120- index : parsedChunk . choices [ 0 ] . index || 0 ,
121- delta : {
122- role : 'assistant' ,
123- content : parsedChunk . choices [ 0 ] . delta . content ,
124- tool_calls : parsedChunk . choices [ 0 ] . delta ?. tool_calls ,
125- } ,
126- logprobs : null ,
127- finish_reason : parsedChunk . choices [ 0 ] . finish_reason || null ,
128- } ,
129- ] ,
121+ choices :
122+ parsedChunk . choices && parsedChunk . choices . length > 0
123+ ? [
124+ {
125+ index : parsedChunk . choices [ 0 ] . index || 0 ,
126+ delta : {
127+ role : 'assistant' ,
128+ content : parsedChunk . choices [ 0 ] . delta ?. content || '' ,
129+ tool_calls : parsedChunk . choices [ 0 ] . delta ?. tool_calls || [ ] ,
130+ } ,
131+ logprobs : null ,
132+ finish_reason : parsedChunk . choices [ 0 ] . finish_reason || null ,
133+ } ,
134+ ]
135+ : [ ] ,
136+ usage : parsedChunk . usage
137+ ? {
138+ prompt_tokens : parsedChunk . usage . prompt_tokens || 0 ,
139+ completion_tokens : parsedChunk . usage . completion_tokens || 0 ,
140+ total_tokens : parsedChunk . usage . total_tokens || 0 ,
141+ }
142+ : undefined ,
130143 } ) } \n\n`;
131144} ;
0 commit comments