googleapis / googleapis/nodejs-agentplatform
GenerateContentStream in function call scenario cannot stream read
- Dominant language
- TypeScript
- Stars
- 182
- Forks
- 69
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 10
Description
I encountered this bug where I cannot stream read when using generateContentStream with a function call.
#### Environment details
- Programming language: node.js
- OS: macos 14.6
- Language runtime version: v22.12.0
- Package version: 1.9.2
#### Steps to reproduce
This example should help you reproduce the issue.
```
const requestContent = {
contents: [
{
role: 'user',
parts: [
{
text: '\n' +
' Translate the mindmap into Chinese based on the requirements below:\n' +
' 1) Translate the entire mind map into Chinese\n' +
' \n' +
" My mindmap(json format): '''\n" +
' {"id":"cd45435c-9e53-4b54-a417-7f08293ecb3d","title":"Missouri Public Water Systems: New Bacteriological Testing Procedures","children":[{"id":"c2bf65f1-4cc5-4799-b77e-b43f4de017c7","title":"New Sample Bottles and Collection Forms","children":[{"id":"67e42942-77f0-4bf4-860c-1c42d5795d8e","title":"Changes to Sample Bottles","children":[{"id":"daadb31f-c458-407e-aecd-36c6492bec31","title":"New sample bottles with a shrink wrap seal and two fill lines indicate proper sample water volume (100-120 mL).","children":[]},{"id":"a2ecb7c0-6559-4b6f-831d-52d8a102767c","title":"Old bottles must be discarded.","children":[]},{"id":"263e7205-8acf-46ff-b274-affc0e0f30df","title":"Instructions on how to use new bottles are attached.","children":[]}]},{"id":"1d7bf51f-1aec-42a2-b310-9d0b52bb746c","title":"Changes to Sample Collection Forms","children":[{"id":"a981f931-d722-47a1-a63e-1be3f5979e12","title":"Forms are reduced to a single 8.5” x 11” sheet of paper.","children":[]},{"id":"77458640-1c7c-45a8-9aae-25725c3c6cc9","title":"Forms are pre-populated with some information.","children":[]},{"id":"18313d21-0829-46a6-9c7e-6f829ef2a7f3","title":"Blank forms will be available for MDNR regional staff use.","children":[]},{"id":"5fbe5618-f69d-499b-96b5-47549fd8628a","title":"The form requires sample point ID and location.","children":[]},{"id":"562bcb5c-36a5-4bbc-9827-577b62e583f7","title":"A collector signature line has been added.","children":[]}]},{"id":"c1b60092-96d4-4380-b774-dbfa981b65a4","title":"Implementation of New Forms","children":[{"id":"20b4cfe0-ba2d-4220-9c28-f2682ad8c346","title":"New forms will begin shipping in late November or early December 2015.","children":[]},{"id":"c8711180-65fa-4bb8-9b71-4c5e1169e134","title":"Discard all old forms.","children":[]},{"id":"feb0460e-2b6d-436e-a2f7-bef5a6a7fa41","title":"Sample instructions have been revised to include changes to the bottle and sampling form.","children":[]}]}]},{"id":"354e4515-6411-4233-99da-dd84b0687e42","title":"New Web Portal for Results Reports","children":[{"id":"69415724-8bb3-4968-93ff-2dbd4605d844","title":"Accessing Test Results","children":[{"id":"747f047c-9bd2-4cc9-876e-59142337db42","title":"The new OE LIMS provides a web portal that may be used by systems to view and print their test results.","children":[]},{"id":"adf5320d-60ad-4fd4-aa43-d9ec9a0a9716","title":"Reports check status of samples, download reports by information into Excel, and receive automated email when samples are received at the laboratory, and when samples are ready to be viewed.","children":[]},{"id":"c6e06a45-cce7-4ddf-9523-605aab2a0b64","title":"Contact Shondra Johnson, LIMS Administrator at Shondra.Johnson@health.mo.gov or at 573-751-3334.","children":[]}]}]},{"id":"e4b3f02f-0d20-4c7a-9ea9-8e8bc6450258","title":"Implementation Dates","children":[{"id":"670d7f67-2ebd-4059-8d7a-bb893a0ab7af","title":"Timeline for System Transition","children":[{"id":"cad867bc-3038-4cc3-8000-07301dc26ccf","title":"The MSPHL intends to implement the OpenELIMS on December 1, 2015.","children":[]},{"id":"04373a99-e067-4948-a806-69222e679270","title":"There will be a two week testing period in which laboratory staff will run the new LIMS in conjunction with our current manual, paper-based system to ensure the OE-LIMS is operating properly.","children":[]},{"id":"b7f6a99b-b57c-44e1-8292-175a70ec2239","title":"You may continue to submit samples as you currently do, using the old sample forms with the new OE LIMS sample submission.","children":[]},{"id":"037d1510-7ea2-4b1e-85ad-a9ea038e6458","title":"After that date results web portal will be available to those systems that have been granted access.","children":[]}]}]},{"id":"ee0f868d-e7aa-46d1-9ea8-895019be8e0f","title":"Additional Information and Contact","children":[{"id":"bb1a6638-24b8-4661-83cc-30cadafe8280","title":"Contact Information and Further Assistance","children":[{"id":"9b9d2cd8-befa-44d8-a017-9a610c09a3a8","title":"Contact the MSPHL Environmental Bacteriology Unit at 573-751-3334.","children":[]},{"id":"ce049872-f1dc-4bf0-8b1c-17856ea93aa0","title":"Contact your MDNR Regional Office for additional information on sample collection.","children":[]},{"id":"c90bd48c-8e2e-4b9a-afb0-4b4dbf3fe62d","title":"The MSPHL and MDNR understand that there will be a lot of changes to a system that has been in place for many years. The MSPHL is excited about the added benefits from this new system, and we ask for your patience as we implement the OpenELIMS LIMS at the Missouri State Public Health Laboratory.","children":[]}]}]}]}\n' +
" '''\n" +
' \n' +
' '
},
]
},
],
systemInstruction: undefined
}
const makeTransate_FC = () => ({
name: 'translate_nodes',
description: 'Translate mindmap nodes into user specified language.The translation must be done according to the requirements presented by the user.',
parameters: {
type: "object",
properties: {
translated_nodes: {
type: "array",
items: {
type: "object",
properties: {
node_id: {
type: "string",
description: "The node id. The \"node_id\" must be extracted from the JSON data of user's mind map."
},
content: {
type: "string",
description: "The translated content for corresponding node"
}
},
required: [
"node_id",
"content"
]
}
}
},
required: [
"translated_nodes"
]
},
})
const functionCallingConfig = {
mode: FunctionCallingMode.ANY,
allowedFunctionNames: ['translate_nodes'],
}
const toolConfig = { functionCallingConfig }
const gemini = vertex.getGenerativeModel({
model: 'gemini-2.0-flash-001',
tools: makeTransate_FC ? [{ makeTransate_FC }] : undefined,
toolConfig: toolConfig ,
})
const resp = await gemini.generateContentStream(request)
for await (const item of resp.stream) {
const { candidates } = item || {}
const text = candidates?.[0].content.parts[0].text
const functionCall = candidates?.[0].content.parts[0].functionCall
if (functionCall) {
console.log(functionCall)
} else if (text) {
console.log(text)
}
}
```
If this is not a bug, please let me know what other methods I can use to stream output in a function call scenario.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.