Class: LlmCostTracker::CallsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LlmCostTracker::CallsController
- Defined in:
- app/controllers/llm_cost_tracker/calls_controller.rb
Constant Summary collapse
- CSV_EXPORT_LIMIT =
10_000- CSV_FORMULA_PREFIXES =
["=", "+", "-", "@", "\t", "\r"].freeze
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/llm_cost_tracker/calls_controller.rb', line 10 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
31 32 33 34 35 36 37 |
# File 'app/controllers/llm_cost_tracker/calls_controller.rb', line 31 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 |