Module: RubyLLM::ModelCapabilities::OpenAI
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
8 9 10 11 12 13 14 15 16 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 8 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
52 53 54 55 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 52 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
30 31 32 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 30 def input_price_for(model_id) PRICES.dig(model_family(model_id), :input) || default_input_price end |
#max_tokens_for(model_id) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 18 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
34 35 36 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 34 def output_price_for(model_id) PRICES.dig(model_family(model_id), :output) || default_output_price end |
#supports_functions?(model_id) ⇒ Boolean
42 43 44 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 42 def supports_functions?(model_id) !model_id.include?('instruct') end |
#supports_json_mode?(model_id) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 46 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
38 39 40 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 38 def supports_vision?(model_id) model_id.include?('vision') || model_id.match?(/gpt-4-(?!0314|0613)/) end |