Skip to content

fix: make streaming response fields optional in ChatResponse and GenerateResponse#281

Open
abdelhadi703 wants to merge 1 commit intoollama:mainfrom
abdelhadi703:fix/chat-response-optional-fields
Open

fix: make streaming response fields optional in ChatResponse and GenerateResponse#281
abdelhadi703 wants to merge 1 commit intoollama:mainfrom
abdelhadi703:fix/chat-response-optional-fields

Conversation

@abdelhadi703
Copy link

Summary

  • Make fields that are only present in the final streaming response (when done: true) optional in the ChatResponse and GenerateResponse interfaces
  • Fields affected: done_reason, total_duration, load_duration, prompt_eval_count, prompt_eval_duration, eval_count, eval_duration, and context (GenerateResponse only)
  • These fields are not present in intermediate streaming chunks, so declaring them as required causes TypeScript type errors when iterating over streamed responses

Fixes #262

Changes

  • src/interfaces.ts: Add ? optional modifier to completion-only fields in both ChatResponse and GenerateResponse interfaces

Test plan

  • All existing tests pass (34/34)
  • Build succeeds with unbuild
  • Type declarations correctly reflect optional fields in generated .d.ts files

🤖 Generated with Claude Code

…rateResponse

Fields like total_duration, load_duration, prompt_eval_count,
prompt_eval_duration, eval_count, eval_duration, done_reason, and
context are only present in the final streaming response when done=true.
Making them required causes TypeScript errors when consuming intermediate
streaming chunks. This makes them optional with `?` to match the actual
API behavior.

Fixes ollama#262

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatResponse TypeScript interface is declared wrong?

1 participant