Class: RogIQ::Commands::AI
Instance Method Summary collapse
Instance Method Details
#cost ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rogiq/commands/ai.rb', line 26 def cost RogIQ.load_rails! start_date = [:days].to_i.days.ago.to_date scope = ::AIUsageDaily.where("usage_date >= ?", start_date) if [:account].present? acc = RogIQ::Helpers.resolve_account([:account]) unless acc fmt.error_msg("Account not found") exit 1 end scope = scope.where(account_id: acc.id) end rows = scope.group(:provider, :model).sum(:total_cost).sort_by { |_, v| -v.to_f }.first(50) fmt.output(headers: %w[provider model total_cost], rows: rows.map { |(p, m), t| [p, m, t.to_f.round(6)] }) total = scope.sum(:total_cost) fmt.say("Total (period): #{total.to_f.round(6)}") unless [:quiet] end |
#health_check ⇒ Object
54 55 56 57 58 |
# File 'lib/rogiq/commands/ai.rb', line 54 def health_check RogIQ.load_rails! ::AiModelHealthCheckJob.perform_later fmt.success("AiModelHealthCheckJob enqueued.") end |
#models ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/rogiq/commands/ai.rb', line 62 def models RogIQ.load_rails! rows = ::AIModelConfig.order(:sort_order, :display_name).limit([:limit]).map do |m| [m.model_key, m.provider, m.display_name, m.enabled, m.available?] end fmt.output(headers: %w[model_key provider display_name enabled available], rows: rows) end |
#status ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rogiq/commands/ai.rb', line 7 def status RogIQ.load_rails! payload = { openai_key_present: ENV["OPENAI_API_KEY"].present?, anthropic_key_present: ENV["ANTHROPIC_API_KEY"].present?, ai_engine_ready: defined?(AIEngine) && AIEngine.ready?, available_providers: (defined?(AIEngine) ? AIEngine.available_providers : []) } if defined?(Rails.configuration.ai_engine) cfg = Rails.configuration.ai_engine payload[:openai_enabled] = cfg.try(:openai_enabled) payload[:anthropic_enabled] = cfg.try(:anthropic_enabled) end fmt.output(payload) end |
#sync ⇒ Object
46 47 48 49 50 |
# File 'lib/rogiq/commands/ai.rb', line 46 def sync RogIQ.load_rails! ::AiModelSyncJob.perform_later fmt.success("AiModelSyncJob enqueued.") end |