Module: Bugsage::AiSupport
- Defined in:
- lib/bugsage/ai_support.rb
Overview
Shared helpers for AI provider responses.
Class Method Summary collapse
- .build_client(config = Bugsage.configuration) ⇒ Object
- .extract_json(response) ⇒ Object
- .log_failure(label, error) ⇒ Object
Class Method Details
.build_client(config = Bugsage.configuration) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bugsage/ai_support.rb', line 24 def build_client(config = Bugsage.configuration) return config.ai_client if config.ai_client case config.resolved_ai_provider when :cursor CursorClient.new(config: config) else OpenAiClient.new(config: config) end end |
.extract_json(response) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/bugsage/ai_support.rb', line 7 def extract_json(response) stripped = response.to_s.strip stripped = stripped.sub(/\A.*?```(?:json)?\s*/im, "").sub(/\s*```.*\z/m, "") if stripped.include?("```") match = stripped.match(/\{.*\}/m) match ? match[0] : stripped end |
.log_failure(label, error) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/bugsage/ai_support.rb', line 15 def log_failure(label, error) = "[BugSage] #{label}: #{error.class}: #{error.}" if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger Rails.logger.warn() else warn() end end |