Module: Anthropic::Models::ContentBlock

Extended by:
Internal::Type::Union
Defined in:
lib/anthropic/models/content_block.rb,
sig/anthropic/models/content_block.rbs

Defined Under Namespace

Modules: Type

Class Method Summary collapse

Methods included from Internal::Type::Union

==, ===, coerce, derefed_variants, dump, hash, inspect, to_sorbet_type

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, inspect, #inspect, meta_info, new_coerce_state, type_info

Class Method Details

.new(type:, citations:, text:) ⇒ Anthropic::TextBlock .new(type:, signature:, thinking:) ⇒ Anthropic::ThinkingBlock .new(type:, data:) ⇒ Anthropic::RedactedThinkingBlock .new(type:, id:, caller_:, input:, name:, toolset_name:) ⇒ Anthropic::ToolUseBlock .new(type:, id:, caller_:, input:, name:) ⇒ Anthropic::ServerToolUseBlock .new(type:, caller_:, content:, tool_use_id:) ⇒ Anthropic::WebSearchToolResultBlock .new(type:, caller_:, content:, tool_use_id:) ⇒ Anthropic::WebFetchToolResultBlock .new(type:, content:, tool_use_id:) ⇒ Anthropic::CodeExecutionToolResultBlock .new(type:, content:, tool_use_id:) ⇒ Anthropic::BashCodeExecutionToolResultBlock .new(type:, content:, tool_use_id:) ⇒ Anthropic::TextEditorCodeExecutionToolResultBlock .new(type:, content:, tool_use_id:) ⇒ Anthropic::ToolSearchToolResultBlock .new(type:, file_id:) ⇒ Anthropic::ContainerUploadBlock .new(type:, citations:, text:, signature:, thinking:, data:, id:, caller_:, input:, name:, toolset_name:, content:, tool_use_id:, file_id:) ⇒ Anthropic::Models::content_block

Creates a new instance of the variant class whose type matches the given value, passing the remaining arguments to its constructor.

Some parameter documentations has been truncated, see Anthropic::Models::ContentBlock for more details.

Overloads:

  • .new(type:, citations:, text:) ⇒ Anthropic::TextBlock

    Parameters:

    • type: (:text, "text")
    • citations: (::Array[Anthropic::Models::text_citation], nil)
    • text: (String)

    Returns:

  • .new(type:, signature:, thinking:) ⇒ Anthropic::ThinkingBlock

    Parameters:

    • type: (:thinking, "thinking")
    • signature: (String)
    • thinking: (String)

    Returns:

  • .new(type:, data:) ⇒ Anthropic::RedactedThinkingBlock

    Parameters:

    • type: (:redacted_thinking, "redacted_thinking")
    • data: (String)

    Returns:

  • .new(type:, id:, caller_:, input:, name:, toolset_name:) ⇒ Anthropic::ToolUseBlock

    Parameters:

    • type: (:tool_use, "tool_use")
    • id: (String)
    • caller_: (Anthropic::Models::ToolUseBlock::caller_)
    • input: (::Hash[Symbol, top])
    • name: (String)
    • toolset_name: (String, nil)

    Returns:

  • .new(type:, id:, caller_:, input:, name:) ⇒ Anthropic::ServerToolUseBlock

    Parameters:

    • type: (:server_tool_use, "server_tool_use")
    • id: (String)
    • caller_: (Anthropic::Models::ServerToolUseBlock::caller_)
    • input: (::Hash[Symbol, top])
    • name: (Anthropic::Models::ServerToolUseBlock::name_)

    Returns:

  • .new(type:, caller_:, content:, tool_use_id:) ⇒ Anthropic::WebSearchToolResultBlock

    Parameters:

    • type: (:web_search_tool_result, "web_search_tool_result")
    • caller_: (Anthropic::Models::WebSearchToolResultBlock::caller_)
    • content: (Anthropic::Models::web_search_tool_result_block_content)
    • tool_use_id: (String)

    Returns:

  • .new(type:, caller_:, content:, tool_use_id:) ⇒ Anthropic::WebFetchToolResultBlock

    Parameters:

    • type: (:web_fetch_tool_result, "web_fetch_tool_result")
    • caller_: (Anthropic::Models::WebFetchToolResultBlock::caller_)
    • content: (Anthropic::Models::WebFetchToolResultBlock::content)
    • tool_use_id: (String)

    Returns:

  • .new(type:, content:, tool_use_id:) ⇒ Anthropic::CodeExecutionToolResultBlock

    Parameters:

    • type: (:code_execution_tool_result, "code_execution_tool_result")
    • content: (Anthropic::Models::code_execution_tool_result_block_content)
    • tool_use_id: (String)

    Returns:

  • .new(type:, content:, tool_use_id:) ⇒ Anthropic::BashCodeExecutionToolResultBlock

    Parameters:

    • type: (:bash_code_execution_tool_result, "bash_code_execution_tool_result")
    • content: (Anthropic::Models::BashCodeExecutionToolResultBlock::content)
    • tool_use_id: (String)

    Returns:

  • .new(type:, content:, tool_use_id:) ⇒ Anthropic::TextEditorCodeExecutionToolResultBlock

    Parameters:

    • type: (:text_editor_code_execution_tool_result, "text_editor_code_execution_tool_result")
    • content: (Anthropic::Models::TextEditorCodeExecutionToolResultBlock::content)
    • tool_use_id: (String)

    Returns:

  • .new(type:, content:, tool_use_id:) ⇒ Anthropic::ToolSearchToolResultBlock

    Parameters:

    • type: (:tool_search_tool_result, "tool_search_tool_result")
    • content: (Anthropic::Models::ToolSearchToolResultBlock::content)
    • tool_use_id: (String)

    Returns:

  • .new(type:, file_id:) ⇒ Anthropic::ContainerUploadBlock

    Parameters:

    • type: (:container_upload, "container_upload")
    • file_id: (String)

    Returns:

  • .new(type:, citations:, text:, signature:, thinking:, data:, id:, caller_:, input:, name:, toolset_name:, content:, tool_use_id:, file_id:) ⇒ Anthropic::Models::content_block

    Parameters:

    • type: (Anthropic::Models::ContentBlock::type_, String)
    • citations: (::Array[Anthropic::Models::text_citation], nil)
    • text: (String)
    • signature: (String)
    • thinking: (String)
    • data: (String)
    • id: (String)
    • caller_: (Anthropic::Models::ToolUseBlock::caller_, Anthropic::Models::ServerToolUseBlock::caller_, Anthropic::Models::WebSearchToolResultBlock::caller_, Anthropic::Models::WebFetchToolResultBlock::caller_)
    • input: (::Hash[Symbol, top])
    • name: (String, Anthropic::Models::ServerToolUseBlock::name_)
    • toolset_name: (String, nil)
    • content: (Anthropic::Models::web_search_tool_result_block_content, Anthropic::Models::WebFetchToolResultBlock::content, Anthropic::Models::code_execution_tool_result_block_content, Anthropic::Models::BashCodeExecutionToolResultBlock::content, Anthropic::Models::TextEditorCodeExecutionToolResultBlock::content, Anthropic::Models::ToolSearchToolResultBlock::content)
    • tool_use_id: (String)
    • file_id: (String)

    Returns:

    • (Anthropic::Models::content_block)

Parameters:

  • type (Symbol, Anthropic::Models::ContentBlock::Type, String)
  • args (Hash{Symbol=>Object}) —

    Attributes for the chosen variant.

    @option args [Array<Anthropic::Models::CitationCharLocation, Anthropic::Models::CitationPageLocation, Anthropic::Models::CitationContentBlockLocation, Anthropic::Models::CitationsWebSearchResultLocation, Anthropic::Models::CitationsSearchResultLocation>, nil] :citations Citations supporting the text block.

    @option args [String] :text

    @option args [String] :signature A value used to verify that this thinking block was generated by Claude when it

    @option args [String] :thinking The text of Claude's thinking process for this block.

    @option args [String] :data The contents of this redacted thinking block, returned when portions of the mode

    @option args [String] :id

    @option args [Anthropic::Models::DirectCaller, Anthropic::Models::ServerToolCaller, Anthropic::Models::ServerToolCaller20260120] :caller_

    @option args [HashSymbol=>Object] :input

    @option args [String, Symbol, Anthropic::Models::ServerToolUseBlock::Name] :name

    @option args [String, nil] :toolset_name For a toolset member tool_use, the toolset family.

    @option args [Anthropic::Models::WebSearchToolResultErrorObject, ArrayAnthropic::Models::WebSearchResultBlock, Anthropic::Models::WebFetchToolResultErrorBlock, Anthropic::Models::WebFetchBlock, Anthropic::Models::CodeExecutionToolResultErrorObject, Anthropic::Models::CodeExecutionResultBlock, Anthropic::Models::EncryptedCodeExecutionResultBlock, Anthropic::Models::BashCodeExecutionToolResultErrorObject, Anthropic::Models::BashCodeExecutionResultBlock, Anthropic::Models::TextEditorCodeExecutionToolResultErrorObject, Anthropic::Models::TextEditorCodeExecutionViewResultBlock, Anthropic::Models::TextEditorCodeExecutionCreateResultBlock, Anthropic::Models::TextEditorCodeExecutionStrReplaceResultBlock, Anthropic::Models::ToolSearchToolResultErrorObject, Anthropic::Models::ToolSearchToolSearchResultBlock] :content

    @option args [String] :tool_use_id

    @option args [String] :file_id

Returns:

Raises:

  • (ArgumentError)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/anthropic/models/content_block.rb', line 96

def self.new(type:, **args)
  case type.to_sym
  when :text
    Anthropic::TextBlock.new(**args)
  when :thinking
    Anthropic::ThinkingBlock.new(**args)
  when :redacted_thinking
    Anthropic::RedactedThinkingBlock.new(**args)
  when :tool_use
    Anthropic::ToolUseBlock.new(**args)
  when :server_tool_use
    Anthropic::ServerToolUseBlock.new(**args)
  when :web_search_tool_result
    Anthropic::WebSearchToolResultBlock.new(**args)
  when :web_fetch_tool_result
    Anthropic::WebFetchToolResultBlock.new(**args)
  when :code_execution_tool_result
    Anthropic::CodeExecutionToolResultBlock.new(**args)
  when :bash_code_execution_tool_result
    Anthropic::BashCodeExecutionToolResultBlock.new(**args)
  when :text_editor_code_execution_tool_result
    Anthropic::TextEditorCodeExecutionToolResultBlock.new(**args)
  when :tool_search_tool_result
    Anthropic::ToolSearchToolResultBlock.new(**args)
  when :container_upload
    Anthropic::ContainerUploadBlock.new(**args)
  else
    raise ArgumentError, "unknown type: #{type}"
  end
end

.values ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)


# File 'lib/anthropic/models/content_block.rb', line 51