Skip to content

Commit f317d46

Browse files
committed
Remove unused filterEmptyTextParts()
1 parent ee216fc commit f317d46

File tree

2 files changed

+7
-40
lines changed

2 files changed

+7
-40
lines changed

packages/vertexai/src/requests/stream-reader.test.ts

+1-28
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import {
1919
aggregateResponses,
2020
getResponseStream,
21-
processStream,
22-
filterEmptyTextParts
21+
processStream
2322
} from './stream-reader';
2423
import { expect, use } from 'chai';
2524
import { restore } from 'sinon';
@@ -405,29 +404,3 @@ describe('aggregateResponses', () => {
405404
});
406405
});
407406
});
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-
});

packages/vertexai/src/requests/stream-reader.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ async function getResponsePromise(
6868
if (value.candidates && value.candidates.length > 0) {
6969
value.candidates.forEach(candidate => {
7070
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+
);
7274
}
7375
});
7476
}
@@ -91,7 +93,9 @@ async function* generateResponseSequence(
9193
if (value.candidates && value.candidates.length > 0) {
9294
value.candidates.forEach(candidate => {
9395
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+
);
9599
}
96100
});
97101
}
@@ -222,13 +226,3 @@ export function aggregateResponses(
222226
}
223227
return aggregatedResponse;
224228
}
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-
}

0 commit comments

Comments
 (0)