AnthropicUtils
parse_message_param
Name | Type | Description |
---|---|---|
message | Iterable[MessageParam] | Iterable of Anthropic message parameters |
override_role
Optional[str] - Optional role to override the message role. If provided, all messages will use this role instead of their original role.
Name | Description |
---|---|
List[[GenerationRequestMessage](/sdk/python/references/logger/components/generation)] | List of parsed messages in Maxim format, |
- String messages are treated as user messages by default
- Dict messages should have ‘role’ and ‘content’ keys
- Content blocks are flattened into text content
- Complex content structures are converted to string representation
get_model_params
Name | Type | Description |
---|---|---|
max_tokens | int | Maximum number of tokens to generate. |
**kwargs | Any | Additional keyword arguments that may contain |
- Only non-None parameters are included in the result
- System, metadata, temperature, top_p, and top_k are handled explicitly
- Additional parameters from kwargs are included if they have values
parse_message_stream
Name | Type | Description |
---|---|---|
stream | List[MessageStreamEvent] | List of stream events from |
- id: Unique identifier for the response
- created: Unix timestamp of creation
- choices: List with single choice containing message and finish_reason
- usage: Token usage statistics (prompt, completion, total)
ValueError
- If the stream list is empty.
- Text content is extracted from content_block_delta events
- Token usage is extracted from message_start events
- The response format mimics OpenAI’s API for compatibility
- Finish reason is set to “stop” by default (Anthropic doesn’t provide this directly)
parse_message
Name | Type | Description |
---|---|---|
message | Any | Anthropic Message object containing the API response |
- id: Message ID from Anthropic
- created: Unix timestamp of parsing time
- choices: List with single choice containing message and finish_reason
- usage: Token usage statistics (input, output, total tokens)
- Content blocks are flattened into a single text string
- Both structured content blocks and dict-based content are supported
- Token usage is extracted from the message’s usage attribute
- Stop reason is mapped from Anthropic’s stop_reason or defaults to “stop”
- The response format mimics OpenAI’s API for cross-provider compatibility