Skip to content

Commit 3b80dc8

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: for function call, role should be model.
PiperOrigin-RevId: 613639813
1 parent 89568a6 commit 3b80dc8

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ async function functionCallingGenerateContentStream() {
259259
contents: [
260260
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
261261
{role: 'model', parts: [{functionCall: {name: 'get_current_weather', args: {'location': 'Boston'}}}]},
262-
{role: 'function', parts: functionResponseParts}
262+
{role: 'model', parts: functionResponseParts}
263263
],
264264
tools: functionDeclarations,
265265
};

src/models/chat_session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function assignRoleToPartsAndValidateSendMessageRequest(
407407
parts: Array<Part>
408408
): Content[] {
409409
const userContent: Content = {role: constants.USER_ROLE, parts: []};
410-
const functionContent: Content = {role: constants.FUNCTION_ROLE, parts: []};
410+
const functionContent: Content = {role: constants.MODEL_ROLE, parts: []};
411411
let hasUserContent = false;
412412
let hasFunctionContent = false;
413413
for (const part of parts) {

src/util/constants.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const GENERATE_CONTENT_METHOD = 'generateContent';
1818
export const STREAMING_GENERATE_CONTENT_METHOD = 'streamGenerateContent';
1919
export const USER_ROLE = 'user';
2020
export const MODEL_ROLE = 'model';
21-
export const FUNCTION_ROLE = 'function';
2221
const USER_AGENT_PRODUCT = 'model-builder';
2322
const CLIENT_LIBRARY_VERSION = '0.5.0'; // x-release-please-version
2423
const CLIENT_LIBRARY_LANGUAGE = `grpc-node/${CLIENT_LIBRARY_VERSION}`;

system_test/end_to_end_sample_test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ describe('generateContentStream', () => {
367367
contents: [
368368
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
369369
{role: 'model', parts: FUNCTION_CALL},
370-
{role: 'function', parts: FUNCTION_RESPONSE_PART},
370+
{role: 'model', parts: FUNCTION_RESPONSE_PART},
371371
],
372372
tools: TOOLS_WITH_FUNCTION_DECLARATION,
373373
};
@@ -387,7 +387,7 @@ describe('generateContentStream', () => {
387387
contents: [
388388
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
389389
{role: 'model', parts: FUNCTION_CALL},
390-
{role: 'function', parts: FUNCTION_RESPONSE_PART},
390+
{role: 'model', parts: FUNCTION_RESPONSE_PART},
391391
],
392392
tools: TOOLS_WITH_FUNCTION_DECLARATION,
393393
};
@@ -534,7 +534,7 @@ describe('generateContent', () => {
534534
contents: [
535535
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
536536
{role: 'model', parts: FUNCTION_CALL},
537-
{role: 'function', parts: FUNCTION_RESPONSE_PART},
537+
{role: 'model', parts: FUNCTION_RESPONSE_PART},
538538
],
539539
tools: TOOLS_WITH_FUNCTION_DECLARATION,
540540
};
@@ -552,7 +552,7 @@ describe('generateContent', () => {
552552
contents: [
553553
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
554554
{role: 'model', parts: FUNCTION_CALL},
555-
{role: 'function', parts: FUNCTION_RESPONSE_PART},
555+
{role: 'model', parts: FUNCTION_RESPONSE_PART},
556556
],
557557
tools: TOOLS_WITH_FUNCTION_DECLARATION,
558558
};

0 commit comments

Comments
 (0)