File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,6 +113,11 @@ interface DeepInfraStreamChunk {
113113 index : number ;
114114 finish_reason : string | null ;
115115 } [ ] ;
116+ usage ?: {
117+ prompt_tokens : number ;
118+ completion_tokens : number ;
119+ total_tokens : number ;
120+ } ;
116121}
117122
118123export const DeepInfraChatCompleteResponseTransform : (
@@ -178,6 +183,15 @@ export const DeepInfraChatCompleteResponseTransform: (
178183export const DeepInfraChatCompleteStreamChunkTransform : (
179184 response : string
180185) => string = ( responseChunk ) => {
186+ // Matches a ping chunk `: ping - 2025-04-13 03:55:09.637341+00:00`
187+ if (
188+ responseChunk . match (
189+ / ^ : \s * p i n g \s * - \s * \d { 4 } - \d { 2 } - \d { 2 } \s \d { 2 } : \d { 2 } : \d { 2 } \. \d { 6 } \+ \d { 2 } : \d { 2 } $ /
190+ )
191+ ) {
192+ return '' ;
193+ }
194+
181195 let chunk = responseChunk . trim ( ) ;
182196 chunk = chunk . replace ( / ^ d a t a : / , '' ) ;
183197 chunk = chunk . trim ( ) ;
@@ -199,6 +213,13 @@ export const DeepInfraChatCompleteStreamChunkTransform: (
199213 finish_reason : parsedChunk . choices [ 0 ] . finish_reason ,
200214 } ,
201215 ] ,
216+ usage : parsedChunk . usage
217+ ? {
218+ prompt_tokens : parsedChunk . usage . prompt_tokens ,
219+ completion_tokens : parsedChunk . usage . completion_tokens ,
220+ total_tokens : parsedChunk . usage . total_tokens ,
221+ }
222+ : undefined ,
202223 } ) } ` + '\n\n'
203224 ) ;
204225} ;
You can’t perform that action at this time.
0 commit comments