Skip to content

Commit

Permalink
models.yaml has models nested under models: key
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Nov 6, 2024
1 parent f798598 commit 3e3f195
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
10 changes: 7 additions & 3 deletions app/models/language_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,20 @@ def supports_tools?

def self.export_to_file(path:, models:, only: %i[api_name name api_service_name supports_images supports_tools input_token_cost_cents output_token_cost_cents])
path = path.to_s
storage = {
"models" => models.as_json(only:)
}
if path.ends_with?(".json")
File.write(path, models.to_json(only: only))
File.write(path, storage.to_json)
else
File.write(path, models.as_json(only: only).to_yaml)
File.write(path, storage.to_yaml)
end
end

def self.import_from_file(path:, users: User.all)
users = Array.wrap(users)
models = YAML.load_file(path)
storage = YAML.load_file(path)
models = storage["models"]
models.each do |model|
model = model.with_indifferent_access
users.each do |user|
Expand Down
32 changes: 32 additions & 0 deletions models.yaml
Original file line number Diff line number Diff line change
@@ -1,187 +1,219 @@
---
models:
- api_name: gpt-best
name: Best OpenAI Model
supports_images: true
supports_tools: true
input_token_cost_cents: '0.00025'
output_token_cost_cents: '0.001'
api_service_name: OpenAI
- api_name: claude-best
name: Best Anthropic Model
supports_images: true
supports_tools: true
input_token_cost_cents: '0.0003'
output_token_cost_cents: '0.0015'
api_service_name: Anthropic
- api_name: groq-best
name: Best Open-Source Model
supports_images: true
supports_tools: true
input_token_cost_cents: '0.000059'
output_token_cost_cents: '0.000079'
api_service_name: Groq
- api_name: gpt-4o
name: GPT-4o (latest)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.00025'
output_token_cost_cents: '0.001'
api_service_name: OpenAI
- api_name: gpt-4o-2024-05-13
name: GPT-4o Omni Multimodal (2024-05-13)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.0005'
output_token_cost_cents: '0.0015'
api_service_name: OpenAI
- api_name: gpt-4-turbo
name: GPT-4 Turbo with Vision (latest)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4-turbo-2024-04-09
name: GPT-4 Turbo with Vision (2024-04-09)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4-turbo-preview
name: GPT-4 Turbo Preview
supports_images: false
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4-0125-preview
name: GPT-4 Turbo Preview (2024-01-25)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4-1106-preview
name: GPT-4 Turbo Preview (2023-11-06)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4-vision-preview
name: GPT-4 Turbo with Vision Preview (2023-11-06)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4-1106-vision-preview
name: GPT-4 Turbo with Vision Preview (2023-11-06)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-4
name: GPT-4 (latest)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.003'
output_token_cost_cents: '0.006'
api_service_name: OpenAI
- api_name: gpt-4-0613
name: GPT-4 Snapshot improved function calling (2023-06-13)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.001'
output_token_cost_cents: '0.003'
api_service_name: OpenAI
- api_name: gpt-3.5-turbo
name: GPT-3.5 Turbo (latest)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.0003'
output_token_cost_cents: '0.0006'
api_service_name: OpenAI
- api_name: gpt-3.5-turbo-0125
name: GPT-3.5 Turbo (2022-01-25)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.00005'
output_token_cost_cents: '0.00015'
api_service_name: OpenAI
- api_name: gpt-3.5-turbo-1106
name: GPT-3.5 Turbo (2022-11-06)
supports_images: false
supports_tools: true
input_token_cost_cents: '0.0001'
output_token_cost_cents: '0.0002'
api_service_name: OpenAI
- api_name: claude-3-5-sonnet-20240620
name: Claude 3.5 Sonnet (2024-06-20)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.0003'
output_token_cost_cents: '0.0015'
api_service_name: Anthropic
- api_name: claude-3-opus-20240229
name: Claude 3 Opus (2024-02-29)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.0015'
output_token_cost_cents: '0.0075'
api_service_name: Anthropic
- api_name: claude-3-sonnet-20240229
name: Claude 3 Sonnet (2024-02-29)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.0003'
output_token_cost_cents: '0.0015'
api_service_name: Anthropic
- api_name: claude-3-haiku-20240307
name: Claude 3 Haiku (2024-03-07)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.000025'
output_token_cost_cents: '0.000125'
api_service_name: Anthropic
- api_name: claude-2.1
name: Claude 2.1
supports_images: false
supports_tools: true
input_token_cost_cents: '0.0008'
output_token_cost_cents: '0.0024'
api_service_name: Anthropic
- api_name: claude-2.0
name: Claude 2.0
supports_images: false
supports_tools: true
input_token_cost_cents: '0.0008'
output_token_cost_cents: '0.0024'
api_service_name: Anthropic
- api_name: claude-instant-1.2
name: Claude Instant 1.2
supports_images: false
supports_tools: true
input_token_cost_cents: '0.00008'
output_token_cost_cents: '0.00024'
api_service_name: Anthropic
- api_name: llama3-70b-8192
name: Meta Llama 3 70b
supports_images: false
supports_tools: true
input_token_cost_cents: '0.000059'
output_token_cost_cents: '0.000079'
api_service_name: Groq
- api_name: llama3-8b-8192
name: Meta Llama 3 8b
supports_images: false
supports_tools: true
input_token_cost_cents: '0.000005'
output_token_cost_cents: '0.000008'
api_service_name: Groq
- api_name: mixtral-8x7b-32768
name: Mistral 8 7b
supports_images: false
supports_tools: true
input_token_cost_cents: '0.000024'
output_token_cost_cents: '0.000024'
api_service_name: Groq
- api_name: gemma-7b-it
name: Google Gemma 7b
supports_images: false
supports_tools: true
input_token_cost_cents: '0.000007'
output_token_cost_cents: '0.000007'
api_service_name: Groq
- api_name: gpt-3.5-turbo-instruct
name: GPT-3.5 Turbo Instruct
supports_images: false
supports_tools: false
input_token_cost_cents: '0.00015'
output_token_cost_cents: '0.0002'
api_service_name: OpenAI
- api_name: gpt-3.5-turbo-16k-0613
name: GPT-3.5 Turbo (2022-06-13)
supports_images: false
supports_tools: false
input_token_cost_cents: '0.0003'
output_token_cost_cents: '0.0004'
api_service_name: OpenAI
- api_name: gpt-4o-2024-08-06
name: GPT-4o Omni Multimodal (2024-08-06)
supports_images: true
supports_tools: true
input_token_cost_cents: '0.00025'
output_token_cost_cents: '0.001'
api_service_name: OpenAI
20 changes: 14 additions & 6 deletions test/models/language_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,18 @@ class LanguageModelTest < ActiveSupport::TestCase
path = Rails.root.join("tmp/models.json")
LanguageModel.export_to_file(path:, models: users(:rob).language_models.not_deleted)
assert File.exist?(path)
json = JSON.load_file(path)
assert_equal json.first.keys, %w[api_name name supports_images supports_tools input_token_cost_cents output_token_cost_cents api_service_name]
storage = JSON.load_file(path)
models = storage["models"]
assert_equal models.first.keys, %w[api_name name supports_images supports_tools input_token_cost_cents output_token_cost_cents api_service_name]
end

test "export_to_file yaml" do
path = Rails.root.join("tmp/models.yaml")
LanguageModel.export_to_file(path:, models: users(:rob).language_models.not_deleted)
assert File.exist?(path)
yaml = YAML.load_file(path)
assert_equal yaml.first.keys, %w[api_name name supports_images supports_tools input_token_cost_cents output_token_cost_cents api_service_name]
storage = YAML.load_file(path)
models = storage["models"]
assert_equal models.first.keys, %w[api_name name supports_images supports_tools input_token_cost_cents output_token_cost_cents api_service_name]
end

test "import_from_file with only new models" do
Expand All @@ -127,8 +129,11 @@ class LanguageModelTest < ActiveSupport::TestCase
input_token_cost_cents: 1,
output_token_cost_cents: 1
}]
storage = {
"models" => models
}
path = Rails.root.join("tmp/newmodels.yaml")
File.write(path, models.to_yaml)
File.write(path, storage.to_yaml)
assert_difference "LanguageModel.count", 1 do
LanguageModel.import_from_file(path:, users: users(:rob))
end
Expand All @@ -145,8 +150,11 @@ class LanguageModelTest < ActiveSupport::TestCase
input_token_cost_cents: 0.0001,
output_token_cost_cents: 0.0001
}]
storage = {
"models" => models
}
path = Rails.root.join("tmp/newmodels.yaml")
File.write(path, models.to_yaml)
File.write(path, storage.to_yaml)
assert_no_difference "LanguageModel.count" do
LanguageModel.import_from_file(path:, users: users(:rob))
end
Expand Down

0 comments on commit 3e3f195

Please sign in to comment.