class Anthropic::Helpers::InputSchema::BaseModel
See {examples/input_schemas.rb} for a complete example of use
This class is specifically used when making requests with the ‘input_schema` parameter.
Represents a response from Anthropic’s API where the model’s output has been structured according to a schema predefined by the user.
def description(description) = (@doc_string = description)
-
description(String) --
Other tags:
- Api: - public
def description(description) = (@doc_string = description)
def optional(name_sym, type_info, *args)
def optional(name_sym, type_info, *args) spec = process_field_args(args) super(name_sym, type_info, spec) end
def process_field_args(args)
def process_field_args(args) accept hash format for descriptions. rep(Hash).first.to_h
def required(name_sym, type_info, *args)
def required(name_sym, type_info, *args) spec = process_field_args(args) super(name_sym, type_info, spec) end
def to_json_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(self)
-
(Hash{Symbol=>Object})-
def to_json_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(self)
def to_json_schema_inner(state:)
-
(Hash{Symbol=>Object})-
Options Hash:
(**state)-
:path(Array) -- -
:defs(Hash{Object=>String}) --
Parameters:
-
state(Hash{Symbol=>Object}) --
Other tags:
- Api: - private
def to_json_schema_inner(state:) Anthropic::Helpers::InputSchema::JsonSchemaConverter.cache_def!(state, type: self) do path = state.fetch(:path) properties = fields.to_h do |name, field| type, nilable, meta = field.fetch_values(:type, :nilable, :meta) new_state = {**state, path: [*path, ".#{name}"]} schema = case type in Anthropic::Helpers::InputSchema::JsonSchemaConverter type.to_json_schema_inner(state: new_state) else Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema_inner( type, state: new_state ) end Anthropic::Helpers::InputSchema::JsonSchemaConverter.assoc_meta!(schema, meta: meta) schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_nilable(schema) if nilable [name, schema] end { type: "object", properties: properties, required: fields.select { _2.fetch(:required) }.keys.map(&:to_s), additionalProperties: false }.tap { _1.store(:description, @doc_string) unless @doc_string.nil? } end end