Skip to content

Commit

Permalink
Hotfix: Ensure db:migrate still runs from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht committed Nov 10, 2024
1 parent 692ff03 commit 5e967ec
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 8 additions & 3 deletions db/migrate/20240523080700_create_language_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
28 changes: 17 additions & 11 deletions db/migrate/20241022053212_update_model_prices.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand All @@ -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
Expand Down

0 comments on commit 5e967ec

Please sign in to comment.