Module: RubyLLM::ModelCapabilities::OpenAI
Overview
Determines capabilities and pricing for OpenAI models
Instance Method Summary collapse
- #context_window_for(model_id) ⇒ Object
- #format_display_name(model_id) ⇒ Object
- #input_price_for(model_id) ⇒ Object
- #max_tokens_for(model_id) ⇒ Object
- #output_price_for(model_id) ⇒ Object
- #supports_functions?(model_id) ⇒ Boolean
- #supports_json_mode?(model_id) ⇒ Boolean
- #supports_vision?(model_id) ⇒ Boolean
Instance Method Details
#context_window_for(model_id) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 9 def context_window_for(model_id) case model_id when /gpt-4o/, /o1/, /gpt-4-turbo/ then 128_000 when /gpt-4-0[0-9]{3}/ then 8_192 when /gpt-3.5-turbo-instruct/ then 4_096 when /gpt-3.5/ then 16_385 else 4_096 end end |
#format_display_name(model_id) ⇒ Object
53 54 55 56 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 53 def format_display_name(model_id) model_id.then { |id| humanize(id) } .then { |name| apply_special_formatting(name) } end |
#input_price_for(model_id) ⇒ Object
31 32 33 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 31 def input_price_for(model_id) PRICES.dig(model_family(model_id), :input) || default_input_price end |
#max_tokens_for(model_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 19 def max_tokens_for(model_id) case model_id when /o1-2024-12-17/ then 100_000 when /o1-mini-2024-09-12/ then 65_536 when /o1-preview-2024-09-12/ then 32_768 when /gpt-4o/, /gpt-4-turbo/ then 16_384 when /gpt-4-0[0-9]{3}/ then 8_192 when /gpt-3.5-turbo/ then 4_096 else 4_096 end end |
#output_price_for(model_id) ⇒ Object
35 36 37 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 35 def output_price_for(model_id) PRICES.dig(model_family(model_id), :output) || default_output_price end |
#supports_functions?(model_id) ⇒ Boolean
43 44 45 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 43 def supports_functions?(model_id) !model_id.include?('instruct') end |
#supports_json_mode?(model_id) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 47 def supports_json_mode?(model_id) model_id.match?(/gpt-4-\d{4}-preview/) || model_id.include?('turbo') || model_id.match?(/gpt-3.5-turbo-(?!0301|0613)/) end |
#supports_vision?(model_id) ⇒ Boolean
39 40 41 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 39 def supports_vision?(model_id) model_id.include?('vision') || model_id.match?(/gpt-4-(?!0314|0613)/) end |