Skip to content

Commit d092ab4

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: functionResponse should be user role
PiperOrigin-RevId: 613650762
1 parent 3b80dc8 commit d092ab4

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
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: 'model', parts: functionResponseParts}
262+
{role: 'user', 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.MODEL_ROLE, parts: []};
410+
const functionContent: Content = {role: constants.USER_ROLE, parts: []};
411411
let hasUserContent = false;
412412
let hasFunctionContent = false;
413413
for (const part of parts) {

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: 'model', parts: FUNCTION_RESPONSE_PART},
370+
{role: 'user', 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: 'model', parts: FUNCTION_RESPONSE_PART},
390+
{role: 'user', 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: 'model', parts: FUNCTION_RESPONSE_PART},
537+
{role: 'user', 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: 'model', parts: FUNCTION_RESPONSE_PART},
555+
{role: 'user', parts: FUNCTION_RESPONSE_PART},
556556
],
557557
tools: TOOLS_WITH_FUNCTION_DECLARATION,
558558
};

0 commit comments

Comments
 (0)