Normalize finish_reason across providers#321
Open
cpsievert wants to merge 1 commit into
Open
Conversation
Maps provider-specific stop reasons to a common vocabulary: "success", "max_tokens", "content_filter", "stop_sequence", "context_window". Unknown reasons pass through as-is. Also fixes OpenAI streaming to handle `response.incomplete` events so truncated responses are returned rather than silently dropped. Mirrors tidyverse/ellmer#1015.
|
FYI, I've extended the list of standard values in tidyverse/ellmer#1039 to also include "tool_use" as it was raising unnecessary warnings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrors tidyverse/ellmer#1015.
What's now possible
turn.finish_reasonreturns a consistent vocabulary regardless of which provider you're using:"success""max_tokens""content_filter""stop_sequence""context_window"Unknown provider-specific reasons pass through as-is so callers can still inspect them.
Changes
normalize_finish_reason()function with a mapping dict keyed to the upstream API docsAssistantTurn.finish_reasonis now set by calling that function rather than storing the raw provider stringresponse.incompleteevents are now handled instream_merge_chunksso truncated streaming responses are returned rather than silently droppedfinish_reason == "stop"/"end_turn"/"STOP"assertions in provider tests updated to"success"Nonehandling