Class: Raif::Admin::StatsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/raif/admin/stats_controller.rb

Instance Method Summary collapse

Methods inherited from Raif::ApplicationController

#raif_current_user

Instance Method Details

#indexObject



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
43
44
45
# File 'app/controllers/raif/admin/stats_controller.rb', line 6

def index
  @selected_period = params[:period] || "day"
  @time_range = get_time_range(@selected_period)

  model_completions = Raif::ModelCompletion.where(created_at: @time_range)

  @model_completion_count = model_completions.count
  @model_completion_total_cost = model_completions.sum(:total_cost)
  @model_completion_input_token_cost = model_completions.sum(:prompt_token_cost)
  @model_completion_output_token_cost = model_completions.sum(:output_token_cost)

  tasks = Raif::Task.where(created_at: @time_range)
  @task_count = tasks.count
  @task_total_cost = Raif::ModelCompletion.where(source_type: "Raif::Task", created_at: @time_range).sum(:total_cost)
  @task_input_token_cost = Raif::ModelCompletion.where(source_type: "Raif::Task", created_at: @time_range).sum(:prompt_token_cost)
  @task_output_token_cost = Raif::ModelCompletion.where(source_type: "Raif::Task", created_at: @time_range).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_total_cost = Raif::ModelCompletion.where(
    source_type: "Raif::ConversationEntry",
    created_at: @time_range,
  ).sum(:total_cost)
  @conversation_entry_input_token_cost = Raif::ModelCompletion.where(
    source_type: "Raif::ConversationEntry",
    created_at: @time_range,
  ).sum(:prompt_token_cost)
  @conversation_entry_output_token_cost = Raif::ModelCompletion.where(
    source_type: "Raif::ConversationEntry",
    created_at: @time_range,
  ).sum(:output_token_cost)

  @agent_count = Raif::Agent.where(created_at: @time_range).count
  @agent_total_cost = Raif::ModelCompletion.where(source_type: "Raif::Agent", created_at: @time_range).sum(:total_cost)
  @agent_input_token_cost = Raif::ModelCompletion.where(source_type: "Raif::Agent", created_at: @time_range).sum(:prompt_token_cost)
  @agent_output_token_cost = Raif::ModelCompletion.where(source_type: "Raif::Agent", created_at: @time_range).sum(:output_token_cost)

  @model_tool_invocation_count = Raif::ModelToolInvocation.where(created_at: @time_range).count
end