Skip to content

ai: return reasoning tokens in the streaming mode #1356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

XiaochenCui
Copy link
Contributor

fix #1323

Note that this PR is just a POC and should not merge before the ai module refactor is finished.

API request:

await puter.ai.chat('Tell me something I  might not know about chemistry.', {model: 'deepseek-reasoner', stream: true });

Here is the raw http response:

{"type":"reasoning","reasoning":""}
{"type":"reasoning","reasoning":"Okay"}
{"type":"reasoning","reasoning":","}
{"type":"reasoning","reasoning":" the"}
{"type":"reasoning","reasoning":" user"}
{"type":"reasoning","reasoning":" asked"}
...
{"type":"text","text":"Here"}
{"type":"text","text":"'s"}
{"type":"text","text":" a"}
{"type":"text","text":" fascinating"}
{"type":"text","text":" piece"}
{"type":"text","text":" of"}
{"type":"text","text":" chemistry"}

Code used in puter playground:

const reasoner_resp = await puter.ai.chat('Tell me something I  might not know about chemistry.', {model: 'deepseek-reasoner', stream: true });

for await (const part of reasoner_resp) {
  if (part?.text) {
    puter.print('<b>[Text]</b> ' + part.text.replaceAll('\n', '<br>'));
  }

  if (part?.reasoning) {
    puter.print('<b>[Reasoning]</b> ' + part.reasoning.replaceAll('\n', '<br>'));
  }
}

@XiaochenCui XiaochenCui force-pushed the ai/stream-reasoning-1323 branch from 49ba00a to ed73c95 Compare July 16, 2025 16:55
@KernelDeimos KernelDeimos added the gateway.js This will be moved to `gateway.js` label Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gateway.js This will be moved to `gateway.js`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stream reasoning in openrouter
2 participants