Files
sure/app/controllers/settings/llm_usages_controller.rb
soky srm bb364fab38 LLM cost estimation (#223)
* Password reset back button also after confirmation

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>

* Implement a filter for category (#215)

- Also implement an is empty/is null condition.

* Implement an LLM cost estimation page

Track costs across all the cost categories: auto categorization, auto merchant detection and chat.
Show warning with estimated cost when running a rule that contains AI.

* Update pricing

* Add google pricing

and fix inferred model everywhere.

* Update app/models/llm_usage.rb

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: soky srm <sokysrm@gmail.com>

* FIX address review

* Linter

* Address review

- Lowered log level
- extracted the duplicated record_usage method into a shared concern

* Update app/controllers/settings/llm_usages_controller.rb

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: soky srm <sokysrm@gmail.com>

* Moved attr_reader out of private

---------

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Signed-off-by: soky srm <sokysrm@gmail.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-10-24 00:08:59 +02:00

36 lines
1016 B
Ruby

class Settings::LlmUsagesController < ApplicationController
layout "settings"
def show
@breadcrumbs = [
[ "Home", root_path ],
[ "LLM Usage", nil ]
]
@family = Current.family
# Get date range from params or default to last 30 days
def safe_parse_date(s)
Date.iso8601(s)
rescue ArgumentError, TypeError
nil
end
private
@end_date = safe_parse_date(params[:end_date]) || Date.today
@start_date = safe_parse_date(params[:start_date]) || (@end_date - 30.days)
if @start_date > @end_date
@start_date, @end_date = @end_date - 30.days, @end_date
end
# Get usage data
@llm_usages = @family.llm_usages
.for_date_range(@start_date.beginning_of_day, @end_date.end_of_day)
.recent
.limit(100)
# Get statistics
@statistics = LlmUsage.statistics_for_family(@family, start_date: @start_date.beginning_of_day, end_date: @end_date.end_of_day)
end
end