Class: RailsErrorDashboard::Services::LlmClient
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Services::LlmClient
- Defined in:
- lib/rails_error_dashboard/services/llm_client.rb
Defined Under Namespace
Classes: ConfigurationError, RequestError
Constant Summary collapse
- OPENAI_RESPONSES_URL =
"https://api.openai.com/v1/responses"- OPENAI_CHAT_COMPLETIONS_URL =
"https://api.openai.com/v1/chat/completions"- ANTHROPIC_MESSAGES_URL =
"https://api.anthropic.com/v1/messages"- ANTHROPIC_VERSION =
"2023-06-01"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #call(error:, question:, context:) ⇒ Object
-
#initialize(config: RailsErrorDashboard.configuration) ⇒ LlmClient
constructor
A new instance of LlmClient.
- #stream(error:, question:, context:, &block) ⇒ Object
Constructor Details
#initialize(config: RailsErrorDashboard.configuration) ⇒ LlmClient
Returns a new instance of LlmClient.
28 29 30 |
# File 'lib/rails_error_dashboard/services/llm_client.rb', line 28 def initialize(config: RailsErrorDashboard.configuration) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/rails_error_dashboard/services/llm_client.rb', line 18 def config @config end |
Class Method Details
.call(error:, question:, context:) ⇒ Object
20 21 22 |
# File 'lib/rails_error_dashboard/services/llm_client.rb', line 20 def self.call(error:, question:, context:) new.call(error: error, question: question, context: context) end |
.stream(error:, question:, context:, &block) ⇒ Object
24 25 26 |
# File 'lib/rails_error_dashboard/services/llm_client.rb', line 24 def self.stream(error:, question:, context:, &block) new.stream(error: error, question: question, context: context, &block) end |
Instance Method Details
#call(error:, question:, context:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails_error_dashboard/services/llm_client.rb', line 32 def call(error:, question:, context:) raise ConfigurationError, "AI Help is not configured" unless config.llm_configured? case config.effective_llm_provider when :openai openai_response(error: error, question: question, context: context) when :anthropic anthropic_response(error: error, question: question, context: context) else raise ConfigurationError, "Unsupported LLM provider: #{config.llm_provider.inspect}" end end |
#stream(error:, question:, context:, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rails_error_dashboard/services/llm_client.rb', line 45 def stream(error:, question:, context:, &block) raise ConfigurationError, "AI Help is not configured" unless config.llm_configured? raise ArgumentError, "block is required for streaming" unless block case config.effective_llm_provider when :openai openai_stream(error: error, question: question, context: context, &block) when :anthropic anthropic_stream(error: error, question: question, context: context, &block) else raise ConfigurationError, "Unsupported LLM provider: #{config.llm_provider.inspect}" end end |