Class: RubyLLM::Instructor::Adapters::RubyLlmSchemaAdapter
- Inherits:
-
Object
- Object
- RubyLLM::Instructor::Adapters::RubyLlmSchemaAdapter
- Defined in:
- lib/ruby_llm/instructor/adapters/ruby_llm_schema.rb
Instance Method Summary collapse
- #build_schema ⇒ Object
-
#initialize(model_klass) ⇒ RubyLlmSchemaAdapter
constructor
A new instance of RubyLlmSchemaAdapter.
Constructor Details
#initialize(model_klass) ⇒ RubyLlmSchemaAdapter
Returns a new instance of RubyLlmSchemaAdapter.
5 6 7 |
# File 'lib/ruby_llm/instructor/adapters/ruby_llm_schema.rb', line 5 def initialize(model_klass) @klass = model_klass end |
Instance Method Details
#build_schema ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_llm/instructor/adapters/ruby_llm_schema.rb', line 9 def build_schema return build_dry_contract_schema if dry_contract? return @klass.to_json_schema if @klass.respond_to?(:to_json_schema) return @klass.new.to_json_schema if @klass.method_defined?(:to_json_schema) attrs = attribute_definitions RubyLLM::Schema.create do attrs.each do |name, type, required| opts = { required: required, description: "Extracted value for #{name}" } case type when :integer then integer name, **opts when :number then number name, **opts when :boolean then boolean name, **opts else string name, **opts end end end end |