File tree 2 files changed +7
-40
lines changed
packages/vertexai/src/requests
2 files changed +7
-40
lines changed Original file line number Diff line number Diff line change 18
18
import {
19
19
aggregateResponses ,
20
20
getResponseStream ,
21
- processStream ,
22
- filterEmptyTextParts
21
+ processStream
23
22
} from './stream-reader' ;
24
23
import { expect , use } from 'chai' ;
25
24
import { restore } from 'sinon' ;
@@ -405,29 +404,3 @@ describe('aggregateResponses', () => {
405
404
} ) ;
406
405
} ) ;
407
406
} ) ;
408
-
409
- describe ( 'filterEmptyTextParts' , ( ) => {
410
- it ( 'Removes only empty text parts' , ( ) => {
411
- const parts = [
412
- {
413
- text : 'foo'
414
- } ,
415
- {
416
- text : ''
417
- } ,
418
- {
419
- text : 'bar'
420
- }
421
- ] ;
422
-
423
- const filteredParts = filterEmptyTextParts ( parts ) ;
424
- expect ( filteredParts ) . to . deep . equal ( [
425
- {
426
- text : 'foo'
427
- } ,
428
- {
429
- text : 'bar'
430
- }
431
- ] ) ;
432
- } ) ;
433
- } ) ;
Original file line number Diff line number Diff line change @@ -68,7 +68,9 @@ async function getResponsePromise(
68
68
if ( value . candidates && value . candidates . length > 0 ) {
69
69
value . candidates . forEach ( candidate => {
70
70
if ( candidate . content ) {
71
- candidate . content . parts = candidate . content . parts . filter ( part => part . text !== '' ) ;
71
+ candidate . content . parts = candidate . content . parts . filter (
72
+ part => part . text !== ''
73
+ ) ;
72
74
}
73
75
} ) ;
74
76
}
@@ -91,7 +93,9 @@ async function* generateResponseSequence(
91
93
if ( value . candidates && value . candidates . length > 0 ) {
92
94
value . candidates . forEach ( candidate => {
93
95
if ( candidate . content ) {
94
- candidate . content . parts = candidate . content . parts . filter ( part => part . text !== '' ) ;
96
+ candidate . content . parts = candidate . content . parts . filter (
97
+ part => part . text !== ''
98
+ ) ;
95
99
}
96
100
} ) ;
97
101
}
@@ -222,13 +226,3 @@ export function aggregateResponses(
222
226
}
223
227
return aggregatedResponse ;
224
228
}
225
-
226
- /**
227
- * The backend can send empty text parts, but if they are sent back (e.g. in a chat history) there
228
- * will be an error. To prevent this, filter out the empty text part from responses.
229
- *
230
- * @internal
231
- */
232
- export function filterEmptyTextParts ( parts : Part [ ] ) : Part [ ] {
233
- return parts ?. filter ( part => part . text !== '' ) ;
234
- }
You can’t perform that action at this time.
0 commit comments