Module: RubyLLM::Sequel::ModelMethods
- Defined in:
- lib/ruby_llm/sequel/model_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #batch? ⇒ Boolean
- #citations? ⇒ Boolean
- #function_calling? ⇒ Boolean
- #input_price_per_million ⇒ Object
- #output_price_per_million ⇒ Object
- #reasoning? ⇒ Boolean
- #streaming? ⇒ Boolean
- #structured_output? ⇒ Boolean
- #supports?(capability) ⇒ Boolean
- #supports_functions? ⇒ Boolean
- #supports_vision? ⇒ Boolean
- #to_llm ⇒ Object
- #type ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 6 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#batch? ⇒ Boolean
171 172 173 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 171 def batch? to_llm.batch? end |
#citations? ⇒ Boolean
179 180 181 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 179 def citations? to_llm.citations? end |
#function_calling? ⇒ Boolean
163 164 165 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 163 def function_calling? to_llm.function_calling? end |
#input_price_per_million ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 131 def input_price_per_million return nil unless pricing price_hash = pricing.is_a?(String) ? JSON.parse(pricing) : pricing if price_hash.dig('text_tokens', 'standard', 'input_per_million') price_hash.dig('text_tokens', 'standard', 'input_per_million').to_f elsif price_hash.dig('text_tokens', 'input') price_hash.dig('text_tokens', 'input').to_f elsif price_hash['input'] || price_hash[:input] (price_hash['input'] || price_hash[:input]).to_f end end |
#output_price_per_million ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 145 def output_price_per_million return nil unless pricing price_hash = pricing.is_a?(String) ? JSON.parse(pricing) : pricing if price_hash.dig('text_tokens', 'standard', 'output_per_million') price_hash.dig('text_tokens', 'standard', 'output_per_million').to_f elsif price_hash.dig('text_tokens', 'output') price_hash.dig('text_tokens', 'output').to_f elsif price_hash['output'] || price_hash[:output] (price_hash['output'] || price_hash[:output]).to_f end end |
#reasoning? ⇒ Boolean
175 176 177 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 175 def reasoning? to_llm.reasoning? end |
#streaming? ⇒ Boolean
183 184 185 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 183 def streaming? to_llm.streaming? end |
#structured_output? ⇒ Boolean
167 168 169 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 167 def structured_output? to_llm.structured_output? end |
#supports?(capability) ⇒ Boolean
115 116 117 118 119 120 121 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 115 def supports?(capability) return false unless capabilities caps_array = capabilities.is_a?(String) ? ::JSON.parse(capabilities) : capabilities caps_array.include?(capability.to_s) end |
#supports_functions? ⇒ Boolean
127 128 129 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 127 def supports_functions? supports?('function_calling') || supports?('tools') end |
#supports_vision? ⇒ Boolean
123 124 125 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 123 def supports_vision? supports?('vision') end |
#to_llm ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 78 def to_llm parse_jsonb = lambda do |value| return nil if value.nil? value.is_a?(String) ? ::JSON.parse(value) : value end deep_symbolize = lambda do |obj| case obj when Hash obj.transform_keys(&:to_sym).transform_values { |v| deep_symbolize.call(v) } when Array obj.map { |item| deep_symbolize.call(item) } else obj end end parsed_pricing = parse_jsonb.call(pricing) symbolized_pricing = parsed_pricing ? deep_symbolize.call(parsed_pricing) : nil ::RubyLLM::Model::Info.new( id: model_id, # RubyLLM::Model::Info expects 'id' not 'model_id' name: name, provider: provider, family: family, created_at: model_created_at, context_window: context_window, max_output_tokens: max_output_tokens, knowledge_cutoff: knowledge_cutoff, modalities: parse_jsonb.call(modalities), capabilities: parse_jsonb.call(capabilities), pricing: symbolized_pricing, metadata: parse_jsonb.call() ) end |
#type ⇒ Object
159 160 161 |
# File 'lib/ruby_llm/sequel/model_methods.rb', line 159 def type to_llm.type end |