Skip to content

Commit 5a53266

Browse files
6utt3rflycopybara-github
authored andcommitted
Copybara import of the project:
-- 2720367 by Shelly (6utt3rfly) <[email protected]>: fix: aggregate text & functionCall(s) correctly content parts should have either text or functionCall set, but never both. When aggregating, combine the text (as before), but add functionCall(s) as new parts. Then when done, if the text from part[0] is empty, that part can be removed. fixes #494 -- b8eed9f by Shelly (6utt3rfly) <[email protected]>: fix: aggregate text & functionCall(s) correctly don't delete the text part, because it could just be added back again when working with multiple responses (and the end up as `"undefined\n"` for example). Leave the text part, and always push functions as new parts. fixes #494 -- a4fc31e by Shelly (6utt3rfly) <[email protected]>: fix: aggregate text & functionCall(s) correctly the AI API gives an error for empty text, so the empty text has to be deleted after aggregating all responses fixes #494 -- 5ada9d4 by Shelly (6utt3rfly) <[email protected]>: chore: fix style using script COPYBARA_INTEGRATE_REVIEW=#497 from 6utt3rfly:main 5ada9d4 PiperOrigin-RevId: 746045519
1 parent 0075baa commit 5a53266

File tree

3 files changed

+0
-57
lines changed

3 files changed

+0
-57
lines changed

src/functions/generate_content.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export async function generateContent(
7777
safetySettings: request.safetySettings ?? safetySettings,
7878
tools: request.tools ?? tools,
7979
toolConfig: request.toolConfig ?? toolConfig,
80-
labels: request.labels,
8180
};
8281
const response: Response | undefined = await postRequest({
8382
region: location,
@@ -133,7 +132,6 @@ export async function generateContentStream(
133132
safetySettings: request.safetySettings ?? safetySettings,
134133
tools: request.tools ?? tools,
135134
toolConfig: request.toolConfig ?? toolConfig,
136-
labels: request.labels,
137135
};
138136
const response = await postRequest({
139137
region: location,

src/functions/test/functions_test.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ const TEST_TOOLS_WITH_RAG: Tool[] = [
226226
},
227227
];
228228

229-
const TEST_LABELS: Record<string, string> = {
230-
test_key: 'test_value',
231-
};
232-
233229
const fetchResponseObj = {
234230
status: 200,
235231
statusText: 'OK',
@@ -652,26 +648,6 @@ describe('generateContent', () => {
652648
const vertexEndpoint = fetchSpy.calls.allArgs()[0][0];
653649
expect(vertexEndpoint).toContain('/v1beta1/');
654650
});
655-
656-
it('provides labels to the vertex endpoint', async () => {
657-
const request: GenerateContentRequest = {
658-
contents: CONTENTS,
659-
labels: TEST_LABELS,
660-
};
661-
fetchSpy.and.resolveTo(buildFetchResponse(TEST_MODEL_RESPONSE));
662-
663-
await generateContent(
664-
TEST_LOCATION,
665-
TEST_RESOURCE_PATH,
666-
TEST_TOKEN_PROMISE,
667-
request,
668-
TEST_API_ENDPOINT
669-
);
670-
671-
const httpRequest = fetchSpy.calls.allArgs()[0][1];
672-
const body = JSON.parse(httpRequest.body);
673-
expect(body.labels).toEqual(TEST_LABELS);
674-
});
675651
});
676652

677653
describe('generateContentStream', () => {
@@ -854,29 +830,4 @@ describe('generateContentStream', () => {
854830
)
855831
).toHaveSize(0);
856832
});
857-
858-
it('provides labels to the vertex endpoint', async () => {
859-
const request: GenerateContentRequest = {
860-
contents: CONTENTS,
861-
labels: TEST_LABELS,
862-
};
863-
const expectedStreamResult: StreamGenerateContentResult = {
864-
response: Promise.resolve(TEST_MODEL_RESPONSE_WITH_INVALID_DATA),
865-
stream: testGenerator(),
866-
};
867-
fetchSpy = spyOn(global, 'fetch').and.resolveTo(fetchResult);
868-
spyOn(StreamFunctions, 'processStream').and.resolveTo(expectedStreamResult);
869-
870-
await generateContentStream(
871-
TEST_LOCATION,
872-
TEST_RESOURCE_PATH,
873-
TEST_TOKEN_PROMISE,
874-
request,
875-
TEST_API_ENDPOINT
876-
);
877-
878-
const httpRequest = fetchSpy.calls.allArgs()[0][1];
879-
const body = JSON.parse(httpRequest.body);
880-
expect(body.labels).toEqual(TEST_LABELS);
881-
});
882833
});

src/types/content.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ export declare interface GenerateContentRequest extends BaseModelParams {
6868
* This is the name of a `CachedContent` and not the cache object itself.
6969
*/
7070
cachedContent?: string;
71-
72-
/**
73-
* Optional. Custom metadata labels for organizing API calls and managing costs at scale. See
74-
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
75-
*/
76-
labels?: Record<string, string>;
7771
}
7872

7973
/**

0 commit comments

Comments
 (0)