puter icon indicating copy to clipboard operation
puter copied to clipboard

Add example of function call with streaming mode

Open reynaldichernando opened this issue 10 months ago • 4 comments

Right now in our docs, the example for function call uses non streaming mode https://docs.puter.com/AI/chat/#function-calling

We would like to add example to use it in streaming mode

this should be possible given all the providers behind the scenes we use also support it

reference of function call with streaming

  • https://openrouter.ai/docs/guides/features/tool-calling#streaming-with-tool-calls
  • https://platform.openai.com/docs/guides/function-calling#streaming
  • https://platform.claude.com/docs/en/build-with-claude/streaming#streaming-request-with-tool-use

reynaldichernando avatar Jan 28 '26 05:01 reynaldichernando

@reynaldichernando Hi! I'd like to work on this issue. I've reviewed the provided references for OpenRouter, OpenAI, and Claude. I can help create a clear example for Puter's documentation on how to handle function calling in streaming mode.

Could you please assign this to me?

AryaXDG avatar Jan 28 '26 07:01 AryaXDG

assigned! @AryaXDG

reynaldichernando avatar Jan 28 '26 08:01 reynaldichernando

@reynaldichernando I have submitted a PR to address this: https://github.com/HeyPuter/puter/pull/2365#issuecomment-3809945940

I added a new example to src/docs/src/AI/chat.md that demonstrates how to handle Function Calling with Streaming.

Implementation Note: After checking the backend source (Streaming.js), I confirmed that Puter buffers the partial JSON chunks internally. Therefore, the new example shows how to simply listen for the tool_use event type (which delivers the fully parsed arguments) without needing manual string accumulation on the client side.

Let me know if any changes are needed!

AryaXDG avatar Jan 28 '26 09:01 AryaXDG

i left some comments on the actual PR, but everything looks good, thank you!

reynaldichernando avatar Jan 28 '26 11:01 reynaldichernando