Class: AgentC::Schema::AnyOneOf
- Inherits:
-
Object
- Object
- AgentC::Schema::AnyOneOf
- Defined in:
- lib/agent_c/schema.rb
Instance Attribute Summary collapse
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#initialize(*schemas) ⇒ AnyOneOf
constructor
A new instance of AnyOneOf.
- #schema_jsons ⇒ Object
- #to_json_schema ⇒ Object
- #to_nested_schema ⇒ Object
Constructor Details
#initialize(*schemas) ⇒ AnyOneOf
Returns a new instance of AnyOneOf.
9 10 11 |
# File 'lib/agent_c/schema.rb', line 9 def initialize(*schemas) @schemas = schemas end |
Instance Attribute Details
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
8 9 10 |
# File 'lib/agent_c/schema.rb', line 8 def schemas @schemas end |
Instance Method Details
#schema_jsons ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/agent_c/schema.rb', line 17 def schema_jsons @schema_jsons ||= ( schemas.flat_map do |schema| if schema.is_a?(AnyOneOf) to_nested_schema elsif schema.is_a?(Hash) schema elsif schema.ancestors.include?(RubyLLM::Schema) schema.new.to_json_schema.fetch(:schema) else raise ArgumentError, "Invalid schema class: #{schema}" end end ) end |
#to_json_schema ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/agent_c/schema.rb', line 33 def to_json_schema { schema: { oneOf: schema_jsons } } end |
#to_nested_schema ⇒ Object
13 14 15 |
# File 'lib/agent_c/schema.rb', line 13 def to_nested_schema to_json_schema.fetch(:schema).fetch(:oneOf) end |