Class: RubyLLM::Agents::RequestsController Private
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RubyLLM::Agents::RequestsController
- Includes:
- Paginatable
- Defined in:
- app/controllers/ruby_llm/agents/requests_controller.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Controller for browsing tracked request groups
Provides listing and detail views for executions grouped by request_id, as set by RubyLLM::Agents.track blocks.
Instance Method Summary collapse
-
#index ⇒ void
private
Lists all tracked requests with aggregated stats.
-
#show ⇒ void
private
Shows a single tracked request with all its executions.
Instance Method Details
#index ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Lists all tracked requests with aggregated stats
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 46 47 48 49 50 51 |
# File 'app/controllers/ruby_llm/agents/requests_controller.rb', line 17 def index @sort_column = sanitize_sort_column(params[:sort]) @sort_direction = (params[:direction] == "asc") ? "asc" : "desc" scope = Execution .where.not(request_id: [nil, ""]) .select( "request_id", "COUNT(*) AS call_count", "SUM(total_cost) AS total_cost", "SUM(total_tokens) AS total_tokens", "MIN(started_at) AS started_at", "MAX(completed_at) AS completed_at", "SUM(duration_ms) AS total_duration_ms", "GROUP_CONCAT(DISTINCT agent_type) AS agent_types_list", "GROUP_CONCAT(DISTINCT status) AS statuses_list", "MAX(created_at) AS latest_created_at" ) .group(:request_id) # Apply time filter days = params[:days].to_i scope = scope.where("created_at >= ?", days.days.ago) if days > 0 result = paginate_requests(scope) @requests = result[:records] @pagination = result[:pagination] # Stats total_scope = Execution.where.not(request_id: [nil, ""]) @stats = { total_requests: total_scope.distinct.count(:request_id), total_cost: total_scope.sum(:total_cost) || 0 } end |
#show ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Shows a single tracked request with all its executions
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/ruby_llm/agents/requests_controller.rb', line 56 def show @request_id = params[:id] @executions = Execution .where(request_id: @request_id) .order(started_at: :asc) if @executions.empty? redirect_to ruby_llm_agents.requests_path, alert: "Request not found: #{@request_id}" return end @summary = { call_count: @executions.count, total_cost: @executions.sum(:total_cost) || 0, total_tokens: @executions.sum(:total_tokens) || 0, started_at: @executions.minimum(:started_at), completed_at: @executions.maximum(:completed_at), agent_types: @executions.distinct.pluck(:agent_type), models_used: @executions.distinct.pluck(:model_id), all_successful: @executions.where.not(status: "success").count.zero?, error_count: @executions.where(status: "error").count } if @summary[:started_at] && @summary[:completed_at] @summary[:duration_ms] = ((@summary[:completed_at] - @summary[:started_at]) * 1000).to_i end end |