Handle anthropic beta messages and refactor#1774
Merged
alexmojaki merged 10 commits intomainfrom Mar 11, 2026
Merged
Conversation
…arsing Apply equivalent changes from OpenAI refactoring PR #1769: - Add _convert_content_part_or_parts for str/list content handling - Add make_tool_call_part helper for standardized tool-call creation - Update _convert_content_part to accept object, handle non-dict inputs - Replace dict literals with ChatMessage/OutputMessage constructors - Remove cast('Role', ...) in favor of direct attribute access
Deploying logfire-docs with
|
| Latest commit: |
5203520
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6d5a4f63.logfire-docs.pages.dev |
| Branch Preview URL: | https://alex-anthropic-beta.logfire-docs.pages.dev |
The falsy check inside _convert_content_part_or_parts already handles None.
BetaMessage content uses BetaTextBlock/BetaToolUseBlock which are separate classes from TextBlock/ToolUseBlock. Add them to isinstance tuples in convert_response_to_semconv and content_from_messages so beta responses are handled correctly.
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.
Part of #1737
Summary by cubic
Adds support for
anthropicbeta messages (including streaming) and refactors content/tool-call parsing for more reliable semconv output. Adds tests for beta async and streaming flows.New Features
anthropicbetaMessage(BetaMessage) in span updates and semconv output, includingBetaTextBlock,BetaToolUseBlock, andBetaTextDeltain parsing and streaming events./v1/messages?beta=trueas a messages endpoint.Refactors
_convert_content_part_or_parts;_convert_content_partnow accepts any object.make_tool_call_partto standardize tool-call creation and parse JSON string arguments.ChatMessage/OutputMessageconstructors; accessroledirectly; buildinput_messagesvia list comprehension.content is not Nonecheck; falsy handling in_convert_content_part_or_partscovers it.ANTHROPIC_API_KEYin test env.Written for commit 5203520. Summary will update on new commits.