Class: LlmCostTracker::CallsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LlmCostTracker::CallsController
- Defined in:
- app/controllers/llm_cost_tracker/calls_controller.rb
Constant Summary collapse
- SORT_ORDERS =
{ "expensive" => "total_cost DESC NULLS LAST, tracked_at DESC", "input" => "input_tokens DESC, tracked_at DESC", "output" => "output_tokens DESC, tracked_at DESC", "slow" => "latency_ms DESC NULLS LAST, tracked_at DESC", "unknown_pricing" => "tracked_at DESC, id DESC" }.freeze
- CSV_EXPORT_LIMIT =
10_000
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/llm_cost_tracker/calls_controller.rb', line 17 def index @sort = params[:sort].to_s scope = Dashboard::Filter.call(params: params) scope = scope.unknown_pricing if @sort == "unknown_pricing" ordered_scope = scope.order(Arel.sql(calls_order(@sort))) @latency_available = LlmApiCall.latency_column? respond_to do |format| format.html do @page = Pagination.call(params) @calls_count = scope.count @calls = ordered_scope.limit(@page.limit).offset(@page.offset).to_a end format.csv do send_data render_csv(ordered_scope.limit(CSV_EXPORT_LIMIT)), type: "text/csv", disposition: %(attachment; filename="llm_calls_#{Time.now.utc.strftime('%Y%m%d_%H%M%S')}.csv") end end end |
#show ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/controllers/llm_cost_tracker/calls_controller.rb', line 38 def show @call = LlmApiCall.find(params[:id]) @tags = @call. @metadata_available = @call.has_attribute?("metadata") @metadata = @call.read_attribute("metadata") if @metadata_available @latency_available = LlmApiCall.latency_column? end |