diff --git a/db/migrate/20240128211815_change_column_assistant_id_on_messages.rb b/db/migrate/20240128211815_change_column_assistant_id_on_messages.rb index a5eb9294..36192eae 100644 --- a/db/migrate/20240128211815_change_column_assistant_id_on_messages.rb +++ b/db/migrate/20240128211815_change_column_assistant_id_on_messages.rb @@ -1,6 +1,6 @@ class ChangeColumnAssistantIdOnMessages < ActiveRecord::Migration[7.1] def up - Message.all.each { |m| m.update!(assistant: m.conversation.assistant) } + # Message.all.each { |m| m.update!(assistant: m.conversation.assistant) } change_column :messages, :assistant_id, :bigint, null: false end diff --git a/db/migrate/20240523080700_create_language_models.rb b/db/migrate/20240523080700_create_language_models.rb index 0405c4b6..79ee59f5 100644 --- a/db/migrate/20240523080700_create_language_models.rb +++ b/db/migrate/20240523080700_create_language_models.rb @@ -75,9 +75,14 @@ def down end def create_without_validation!(attributes) - record = LanguageModel.new(attributes) - if !record.save(validate: false) - raise "Could not create LanguageModel record for #{attributes.inspect}" + LanguageModel.skip_callback(:save, :after, :update_best_language_model_for_api_service) + begin + record = LanguageModel.new(attributes) + if !record.save(validate: false) + raise "Could not create LanguageModel record for #{attributes.inspect}" + end + ensure + LanguageModel.set_callback(:save, :after, :update_best_language_model_for_api_service) end record end diff --git a/db/migrate/20240620100000_add_claude_3_5_sonnet_to_language_models.rb b/db/migrate/20240620100000_add_claude_3_5_sonnet_to_language_models.rb index dac7f479..e8e07abf 100644 --- a/db/migrate/20240620100000_add_claude_3_5_sonnet_to_language_models.rb +++ b/db/migrate/20240620100000_add_claude_3_5_sonnet_to_language_models.rb @@ -33,9 +33,14 @@ def down end def create_without_validation!(attributes) - record = LanguageModel.new(attributes) - if !record.save(validate: false) - raise "Could not create LanguageModel record for #{attributes.inspect}" + LanguageModel.skip_callback(:save, :after, :update_best_language_model_for_api_service) + begin + record = LanguageModel.new(attributes) + if !record.save(validate: false) + raise "Could not create LanguageModel record for #{attributes.inspect}" + end + ensure + LanguageModel.set_callback(:save, :after, :update_best_language_model_for_api_service) end record end diff --git a/db/migrate/20240911114059_update_existing_language_models_with_prices.rb b/db/migrate/20240911114059_update_existing_language_models_with_prices.rb index 8116e8a5..f5e9939d 100644 --- a/db/migrate/20240911114059_update_existing_language_models_with_prices.rb +++ b/db/migrate/20240911114059_update_existing_language_models_with_prices.rb @@ -1,9 +1,11 @@ class UpdateExistingLanguageModelsWithPrices < ActiveRecord::Migration[7.1] def up [ - [LanguageModel::BEST_GPT, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_GPT], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_GPT]], - [LanguageModel::BEST_CLAUDE, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_CLAUDE], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_CLAUDE]], - [LanguageModel::BEST_GROQ, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_GROQ], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_GROQ]], + # Constant was removed in a later PR + # + # [LanguageModel::BEST_GPT, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_GPT], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_GPT]], + # [LanguageModel::BEST_CLAUDE, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_CLAUDE], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_CLAUDE]], + # [LanguageModel::BEST_GROQ, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_GROQ], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_GROQ]], ["gpt-4o", 500, 1500], ["gpt-4o-2024-05-13", 500, 1500], diff --git a/db/migrate/20241022053212_update_model_prices.rb b/db/migrate/20241022053212_update_model_prices.rb index 0d2bd98b..e229bf0b 100644 --- a/db/migrate/20241022053212_update_model_prices.rb +++ b/db/migrate/20241022053212_update_model_prices.rb @@ -1,7 +1,8 @@ class UpdateModelPrices < ActiveRecord::Migration[7.1] def up [ - [LanguageModel::BEST_GPT, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_GPT], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_GPT]], + # Constant was removed in a later PR + # [LanguageModel::BEST_GPT, LanguageModel::BEST_MODEL_INPUT_PRICES[LanguageModel::BEST_GPT], LanguageModel::BEST_MODEL_OUTPUT_PRICES[LanguageModel::BEST_GPT]], ["gpt-4o", 250, 1000], ].each do |api_name, input_token_cost_per_million, output_token_cost_per_million| @@ -27,16 +28,21 @@ def up input_token_cost_cents = input_token_cost_per_million/million output_token_cost_cents = output_token_cost_per_million/million - - user.language_models.create!( - api_name: api_name, - name: name, - supports_images: supports_images, - api_service: api_service, - supports_tools: true, - input_token_cost_cents: input_token_cost_cents, - output_token_cost_cents: output_token_cost_cents, - ) + LanguageModel.skip_callback(:save, :after, :update_best_language_model_for_api_service) + + begin + user.language_models.create!( + api_name: api_name, + name: name, + supports_images: supports_images, + api_service: api_service, + supports_tools: true, + input_token_cost_cents: input_token_cost_cents, + output_token_cost_cents: output_token_cost_cents, + ) + ensure + LanguageModel.set_callback(:save, :after, :update_best_language_model_for_api_service) + end end end end