Skip to content

Conversation

@apascal07
Copy link
Collaborator

@apascal07 apascal07 commented Dec 7, 2025

Originally, formatters were implemented as something that modifies the model response message in place which was different from how it was implemented in JS. This was done in error as this solution was not capable of handling non-JSON formats (e.g. ModelResponse.Output() assumed that the content was JSON and since there was no formatter attached to the type, it was impossible to hook into the format-specific logic).

In this PR, we introduce a new interface called StreamingFormatHandler which, despite the name, is the general format handler interface. It implements ParseOutput(*Message) and ParseChunk(*ModelResponseChunk) which are used when the user calls ModelResponse.Output(), ModelResponseChunk.Output(), or the convenience function OutputFrom[T any]() without modifying content in place.

To make this not a breaking change, existing formats will remain and will continue to implement ParseMessage(*Message) *Message but will be marked deprecated. New formats (suffixed with v2) will be registered and implement it as a passthrough and also implement StreamingFormatHandler which will be the recommended way forward.

Checklist (if applicable):

@apascal07 apascal07 changed the title feat(go): Refactored formatters + added support for formatting streams. feat(go): refactored formatters + added support for formatting streams Dec 7, 2025
@github-actions github-actions bot added the go label Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant