Module: Anthropic::Models::MessageParam

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

Defined Under Namespace

Modules: Role

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(role:, content:) ⇒ Anthropic::UserMessageParam .new(role:, content:) ⇒ Anthropic::AssistantMessageParam .new(role:, content:) ⇒ Anthropic::SystemMessageParam .new(role:, content:) ⇒ Anthropic::Models::message_param

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

Overloads:

Parameters:

  • role (Symbol, Anthropic::Models::MessageParam::Role, String)
  • args (Hash{Symbol=>Object}) —

    Attributes for the chosen variant.

    @option args [String, Array<Anthropic::Models::TextBlockParam, Anthropic::Models::ImageBlockParam, Anthropic::Models::DocumentBlockParam, Anthropic::Models::SearchResultBlockParam, Anthropic::Models::ThinkingBlockParam, Anthropic::Models::RedactedThinkingBlockParam, Anthropic::Models::ToolUseBlockParam, Anthropic::Models::ToolResultBlockParam, Anthropic::Models::ServerToolUseBlockParam, Anthropic::Models::WebSearchToolResultBlockParam, Anthropic::Models::WebFetchToolResultBlockParam, Anthropic::Models::CodeExecutionToolResultBlockParam, Anthropic::Models::BashCodeExecutionToolResultBlockParam, Anthropic::Models::TextEditorCodeExecutionToolResultBlockParam, Anthropic::Models::ToolSearchToolResultBlockParam, Anthropic::Models::ContainerUploadBlockParam>, String, ArrayAnthropic::Models::TextBlockParam] :content

Returns:

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/anthropic/models/message_param.rb', line 41

def self.new(role:, **args)
  case role.to_sym
  when :user
    Anthropic::UserMessageParam.new(**args)
  when :assistant
    Anthropic::AssistantMessageParam.new(**args)
  when :system
    Anthropic::SystemMessageParam.new(**args)
  else
    raise ArgumentError, "unknown role: #{role}"
  end
end

.values ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)


# File 'lib/anthropic/models/message_param.rb', line 23

.variants ⇒ Array(Anthropic::Models::UserMessageParam, Anthropic::Models::AssistantMessageParam, Anthropic::Models::SystemMessageParam)



# File 'lib/anthropic/models/message_param.rb', line 27