Class: RubyLLM::ModelCapabilities::OpenAI
- Defined in:
- lib/ruby_llm/model_capabilities/openai.rb
Instance Method Summary collapse
- #determine_context_window(model_id) ⇒ Object
- #determine_max_tokens(model_id) ⇒ Object
- #format_display_name(model_id) ⇒ Object
- #get_input_price(model_id) ⇒ Object
- #get_output_price(model_id) ⇒ Object
- #supports_functions?(model_id) ⇒ Boolean
- #supports_json_mode?(model_id) ⇒ Boolean
- #supports_vision?(model_id) ⇒ Boolean
Instance Method Details
#determine_context_window(model_id) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 6 def determine_context_window(model_id) case model_id when /gpt-4o/, /o1/, /gpt-4-turbo/ 128_000 when /gpt-4-0[0-9]{3}/ 8_192 when /gpt-3.5-turbo-instruct/ 4_096 when /gpt-3.5/ 16_385 else 4_096 end end |
#determine_max_tokens(model_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 21 def determine_max_tokens(model_id) case model_id when /o1-2024-12-17/ 100_000 when /o1-mini-2024-09-12/ 65_536 when /o1-preview-2024-09-12/ 32_768 when /gpt-4o/, /gpt-4-turbo/ 16_384 when /gpt-4-0[0-9]{3}/ 8_192 when /gpt-3.5-turbo/ 4_096 else 4_096 end end |
#format_display_name(model_id) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 100 def format_display_name(model_id) # First replace hyphens with spaces name = model_id.tr('-', ' ') # Capitalize each word name = name.split(' ').map(&:capitalize).join(' ') # Apply specific formatting rules name.gsub(/(\d{4}) (\d{2}) (\d{2})/, '\1\2\3') # Convert dates to YYYYMMDD .gsub(/^Gpt /, 'GPT-') .gsub(/^O1 /, 'O1-') .gsub(/^Chatgpt /, 'ChatGPT-') .gsub(/^Tts /, 'TTS-') .gsub(/^Dall E /, 'DALL-E-') .gsub(/3\.5 /, '3.5-') .gsub(/4 /, '4-') .gsub(/4o (?=Mini|Preview|Turbo)/, '4o-') .gsub(/\bHd\b/, 'HD') end |
#get_input_price(model_id) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 40 def get_input_price(model_id) case model_id when /o1-2024/ 15.0 # $15.00 per million tokens when /o1-mini/ 3.0 # $3.00 per million tokens when /gpt-4o-realtime-preview/ 5.0 # $5.00 per million tokens when /gpt-4o-mini-realtime-preview/ 0.60 # $0.60 per million tokens when /gpt-4o-mini/ 0.15 # $0.15 per million tokens when /gpt-4o/ 2.50 # $2.50 per million tokens when /gpt-4-turbo/ 10.0 # $10.00 per million tokens when /gpt-3.5/ 0.50 # $0.50 per million tokens else 0.50 # Default to GPT-3.5 pricing end end |
#get_output_price(model_id) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 63 def get_output_price(model_id) case model_id when /o1-2024/ 60.0 # $60.00 per million tokens when /o1-mini/ 12.0 # $12.00 per million tokens when /gpt-4o-realtime-preview/ 20.0 # $20.00 per million tokens when /gpt-4o-mini-realtime-preview/ 2.40 # $2.40 per million tokens when /gpt-4o-mini/ 0.60 # $0.60 per million tokens when /gpt-4o/ 10.0 # $10.00 per million tokens when /gpt-4-turbo/ 30.0 # $30.00 per million tokens when /gpt-3.5/ 1.50 # $1.50 per million tokens else 1.50 # Default to GPT-3.5 pricing end end |
#supports_functions?(model_id) ⇒ Boolean
86 87 88 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 86 def supports_functions?(model_id) !model_id.include?('instruct') end |
#supports_json_mode?(model_id) ⇒ Boolean
94 95 96 97 98 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 94 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
90 91 92 |
# File 'lib/ruby_llm/model_capabilities/openai.rb', line 90 def supports_vision?(model_id) model_id.include?('vision') || model_id.match?(/gpt-4-(?!0314|0613)/) end |