6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/controllers/raif/admin/stats_controller.rb', line 6
def index
@selected_period = params[:period] || "day"
@time_range = get_time_range(@selected_period)
cost_events = Raif::InferenceCostEvent.where(incurred_at: @time_range)
@model_completion_count = Raif::ModelCompletion.where(created_at: @time_range).count
@model_completion_total_cost = cost_events.sum(:total_cost)
@model_completion_input_token_cost = cost_events.sum(:prompt_token_cost)
@model_completion_output_token_cost = cost_events.sum(:output_token_cost)
@task_count = Raif::Task.where(created_at: @time_range).count
task_events = cost_events.where(source_type: "Raif::Task")
@task_total_cost = task_events.sum(:total_cost)
@task_input_token_cost = task_events.sum(:prompt_token_cost)
@task_output_token_cost = task_events.sum(:output_token_cost)
@conversation_count = Raif::Conversation.where(created_at: @time_range).count
@conversation_entry_count = Raif::ConversationEntry.where(created_at: @time_range).count
conversation_entry_events = cost_events.where(source_type: "Raif::ConversationEntry")
@conversation_entry_total_cost = conversation_entry_events.sum(:total_cost)
@conversation_entry_input_token_cost = conversation_entry_events.sum(:prompt_token_cost)
@conversation_entry_output_token_cost = conversation_entry_events.sum(:output_token_cost)
@agent_count = Raif::Agent.where(created_at: @time_range).count
agent_events = cost_events.where(source_type: "Raif::Agent")
@agent_total_cost = agent_events.sum(:total_cost)
@agent_input_token_cost = agent_events.sum(:prompt_token_cost)
@agent_output_token_cost = agent_events.sum(:output_token_cost)
@model_tool_invocation_count = Raif::ModelToolInvocation.where(created_at: @time_range).count
end
|