Skip to content

Commit ba51490

Browse files
authored
Remove cost calculations (#718)
1 parent 12daeb2 commit ba51490

File tree

14 files changed

+19
-218
lines changed

14 files changed

+19
-218
lines changed

app/models/conversation.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ def self.grouped_by_increasing_time_interval_for_user(user, query = nil)
6565
.delete_if { |_, v| v.empty? }
6666
end
6767

68-
def total_cost
69-
input_token_total_cost + output_token_total_cost
70-
end
7168

7269
def generate_shareable_url(request)
7370
ensure_share_token!

app/models/language_model/export.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ module LanguageModel::Export
99
supports_images
1010
supports_tools
1111
supports_system_message
12-
input_token_cost_cents
13-
output_token_cost_cents
1412
]
1513

1614
DEFAULT_MODEL_FILE = "models.yml"

app/models/message.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Message < ApplicationRecord
2525
after_create :start_assistant_reply, if: :user?
2626
after_create :set_last_assistant_message, if: :assistant?
2727
after_save :update_assistant_on_conversation, if: -> { assistant.present? && conversation.present? }
28-
before_save :update_input_token_cost, if: :input_token_count_changed?
29-
before_save :update_output_token_cost, if: :output_token_count_changed?
3028

3129
scope :ordered, -> { latest_version_for_conversation }
3230

@@ -78,13 +76,5 @@ def update_assistant_on_conversation
7876
conversation.update!(assistant:)
7977
end
8078

81-
def update_input_token_cost
82-
return if assistant.language_model.input_token_cost_cents.blank?
83-
self.input_token_cost = assistant.language_model.input_token_cost_cents * input_token_count
84-
end
8579

86-
def update_output_token_cost
87-
return if assistant.language_model.output_token_cost_cents.blank?
88-
self.output_token_cost = assistant.language_model.output_token_cost_cents * output_token_count
89-
end
9080
end

app/models/message/billable.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ module Message::Billable
44
rollup_cache :input_token_total_count, sum: :input_token_count, belongs_to: :conversation
55
rollup_cache :output_token_total_count, sum: :output_token_count, belongs_to: :conversation
66

7-
rollup_cache :input_token_total_cost, sum: :input_token_cost, belongs_to: :conversation
8-
rollup_cache :output_token_total_cost, sum: :output_token_cost, belongs_to: :conversation
97
end
108
end

app/views/conversations/_conversation.html.erb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,20 @@
7979
</li>
8080
<footer class="py-3 px-4 mt-1 border-t-2 border-gray-100 dark:border-gray-600 gap-2 flex flex-col">
8181
<table class="w-full text-left">
82-
<tr>
83-
<td class="pb-2 whitespace-nowrap"><%= t('app.conversations.cost_summary.conversation_approx') %></td>
84-
<td class="pb-2"><%= to_dollars(conversation.total_cost)%></td>
85-
</tr>
8682
<tr>
8783
<td class="pb-2 font-bold" colspan="2"><%= t('app.conversations.cost_summary.input') %></td>
8884
</tr>
8985
<tr>
9086
<td class="pb-2"><%= t('app.conversations.cost_summary.tokens') %></td>
9187
<td class="pb-2"><%= conversation.input_token_total_count %></td>
9288
</tr>
93-
<tr>
94-
<td class="pb-2"><%= t('app.conversations.cost_summary.cost') %></td>
95-
<td class="pb-2"><%= to_dollars(conversation.input_token_total_cost, precision: 5) %></td>
96-
</tr>
9789
<tr>
9890
<td class="pb-2 font-bold" colspan="2"><%= t('app.conversations.cost_summary.output') %></td>
9991
</tr>
10092
<tr>
10193
<td><%= t('app.conversations.cost_summary.tokens') %></td>
10294
<td><%= conversation.output_token_total_count %></td>
10395
</tr>
104-
<tr>
105-
<td><%= t('app.conversations.cost_summary.cost') %></td>
106-
<td><%= to_dollars(conversation.output_token_total_cost, precision: 5) %></td>
107-
</tr>
10896
</table>
10997
</footer>
11098
</menu>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class RemoveTokenCostColumnsFromLanguageModels < ActiveRecord::Migration[8.0]
2+
def change
3+
remove_column :language_models, :input_token_cost_cents, :decimal
4+
remove_column :language_models, :output_token_cost_cents, :decimal
5+
end
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class RemoveCostColumnsFromConversations < ActiveRecord::Migration[8.0]
2+
def change
3+
remove_column :conversations, :input_token_total_cost, :decimal
4+
remove_column :conversations, :output_token_total_cost, :decimal
5+
end
6+
end

db/schema.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2025_09_14_143833) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_09_30_104155) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616

@@ -118,8 +118,6 @@
118118
t.datetime "updated_at", null: false
119119
t.bigint "last_assistant_message_id"
120120
t.text "external_id", comment: "The Backend AI system (e.g OpenAI) Thread Id"
121-
t.decimal "input_token_total_cost", precision: 30, scale: 15, default: "0.0", null: false
122-
t.decimal "output_token_total_cost", precision: 30, scale: 15, default: "0.0", null: false
123121
t.integer "input_token_total_count", default: 0, null: false
124122
t.integer "output_token_total_count", default: 0, null: false
125123
t.string "share_token"
@@ -174,8 +172,6 @@
174172
t.bigint "user_id", null: false
175173
t.bigint "api_service_id"
176174
t.boolean "supports_tools", default: false
177-
t.decimal "input_token_cost_cents", precision: 30, scale: 15
178-
t.decimal "output_token_cost_cents", precision: 30, scale: 15
179175
t.boolean "best", default: false
180176
t.boolean "supports_system_message", default: false
181177
t.boolean "supports_pdf", default: false, null: false

0 commit comments

Comments
 (0)