Class: LlmCostTracker::CallsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/llm_cost_tracker/calls_controller.rb

Constant Summary collapse

CSV_EXPORT_LIMIT =
10_000
CSV_EXPORT_BATCH_SIZE =
500
CSV_FORMULA_PREFIXES =
["=", "+", "-", "@", "\t", "\r"].freeze
DEFAULT_ORDER =
"tracked_at DESC, id DESC"

Instance Method Summary collapse

Instance Method Details

#indexObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/llm_cost_tracker/calls_controller.rb', line 13

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)))

  respond_to do |format|
    format.html do
      @page = Dashboard::Pagination.call(params)
      @calls_count = scope.count
      @calls = ordered_scope.includes(:tag_records).limit(@page.limit).offset(@page.offset).to_a
    end
    format.csv do
      response.headers["Cache-Control"] = "no-store"
      send_data render_csv(ordered_scope),
                type: "text/csv",
                disposition: %(attachment; filename="llm_calls_#{Time.now.utc.strftime('%Y%m%d_%H%M%S')}.csv")
    end
  end
end

#showObject



34
35
36
# File 'app/controllers/llm_cost_tracker/calls_controller.rb', line 34

def show
  @call = LlmCostTracker::Call.includes(:line_items, :tag_records).find(params[:id])
end