diff --git a/app/jobs/get_next_ai_message_job.rb b/app/jobs/get_next_ai_message_job.rb index 013831249..5abc592e6 100644 --- a/app/jobs/get_next_ai_message_job.rb +++ b/app/jobs/get_next_ai_message_job.rb @@ -13,7 +13,7 @@ def ai_backend end def perform(user_id, message_id, assistant_id, attempt = 1) - puts "\n### GetNextAIMessageJob.perform(#{user_id}, #{message_id}, #{assistant_id}, #{attempt})" unless Rails.env.test? + Rails.logger.info "### GetNextAIMessageJob.perform(#{user_id}, #{message_id}, #{assistant_id}, #{attempt})" unless Rails.env.test? @user = User.find(user_id) @message = Message.find(message_id) @@ -29,7 +29,7 @@ def perform(user_id, message_id, assistant_id, attempt = 1) @message.update!(processed_at: Time.current, content_text: "") GetNextAIMessageJob.broadcast_updated_message(@message, thinking: true) # thinking shows dot, signaling to user that we're waiting now on ai_backend - puts "\n### Wait for reply" unless Rails.env.test? + Rails.logger.info "\n### Wait for reply" unless Rails.env.test? response = Current.set(user: @user, message: @message) do ai_backend.new(@conversation.user, @assistant, @conversation, @message) @@ -59,7 +59,7 @@ def perform(user_id, message_id, assistant_id, attempt = 1) return true rescue ResponseCancelled => e - puts "\n### Response cancelled in GetNextAIMessageJob(#{message_id})" unless Rails.env.test? + Rails.logger.info "\n### Response cancelled in GetNextAIMessageJob(#{message_id})" unless Rails.env.test? wrap_up_the_message return true rescue OpenAI::ConfigurationError => e @@ -90,14 +90,14 @@ def perform(user_id, message_id, assistant_id, attempt = 1) wrap_up_the_message return true rescue WaitForPrevious - puts "\n### WaitForPrevious in GetNextAIMessageJob(#{message_id})" unless Rails.env.test? + Rails.logger.info "\n### WaitForPrevious in GetNextAIMessageJob(#{message_id})" unless Rails.env.test? raise WaitForPrevious rescue => e msg = e.inspect.gsub(/(sk-)[\w\-]{40}/, '\1' + "*" * 40) unless Rails.env.test? - puts "\n### Finished GetNextAIMessageJob attempt ##{attempt} with ERROR: #{msg}" unless Rails.env.test? - puts e.backtrace.join("\n") if Rails.env.development? + Rails.logger.info "\n### Finished GetNextAIMessageJob attempt ##{attempt} with ERROR: #{msg}" unless Rails.env.test? + Rails.logger.info e.backtrace.join("\n") if Rails.env.development? if attempt < 3 GetNextAIMessageJob.broadcast_updated_message(@message, thinking: false) @@ -178,11 +178,11 @@ def wrap_up_the_message @message.save! @message.conversation.touch # updated_at change will bump it up your list + ensures it will be auto-titled - puts "\n### Finished GetNextAIMessageJob.perform(#{@user.id}, #{@message.id}, #{@message.assistant_id}, #{@attempt})" unless Rails.env.test? + Rails.logger.info "\n### Finished GetNextAIMessageJob.perform(#{@user.id}, #{@message.id}, #{@message.assistant_id}, #{@attempt})" unless Rails.env.test? end def call_tools_before_wrapping_up - puts "\n### Calling tools" unless Rails.env.test? + Rails.logger.info "\n### Calling tools" unless Rails.env.test? msgs = [] Current.set(user: @user, message: @message) do diff --git a/app/services/ai_backend/anthropic.rb b/app/services/ai_backend/anthropic.rb index 18a829fb0..f8a4d5d9d 100644 --- a/app/services/ai_backend/anthropic.rb +++ b/app/services/ai_backend/anthropic.rb @@ -71,8 +71,8 @@ def stream_handler(&chunk_handler) rescue ::Faraday::UnauthorizedError => e raise ::Anthropic::ConfigurationError rescue => e - puts "\nUnhandled error in AIBackend::Anthropic response handler: #{e.message}" - puts e.backtrace + Rails.logger.info "\nUnhandled error in AIBackend::Anthropic response handler: #{e.message}" + Rails.logger.info e.backtrace end end diff --git a/app/services/ai_backend/open_ai.rb b/app/services/ai_backend/open_ai.rb index 5f7146c80..4c65fe179 100644 --- a/app/services/ai_backend/open_ai.rb +++ b/app/services/ai_backend/open_ai.rb @@ -80,8 +80,8 @@ def stream_handler(&chunk_handler) rescue ::Faraday::UnauthorizedError => e raise OpenAI::ConfigurationError rescue => e - puts "\nUnhandled error in AIBackend::OpenAI response handler: #{e.message}" - puts e.backtrace.join("\n") + Rails.logger.info "\nUnhandled error in AIBackend::OpenAI response handler: #{e.message}" + Rails.logger.info e.backtrace.join("\n") end end diff --git a/app/services/ai_backend/tools.rb b/app/services/ai_backend/tools.rb index c654249c5..4e7e9970b 100644 --- a/app/services/ai_backend/tools.rb +++ b/app/services/ai_backend/tools.rb @@ -16,8 +16,8 @@ def get_tool_messages_by_calling(tool_calls_response) function_response = begin Toolbox.call(function_name, function_arguments) rescue => e - puts "## Handled error calling tools: #{e.message}" unless Rails.env.test? - puts e.backtrace.join("\n") unless Rails.env.test? + Rails.logger.info "## Handled error calling tools: #{e.message}" unless Rails.env.test? + Rails.logger.info e.backtrace.join("\n") unless Rails.env.test? <<~STR.gsub("\n", " ") An unexpected error occurred (#{e.message}). You were querying information to help you answer a users question. Because this information @@ -33,8 +33,8 @@ def get_tool_messages_by_calling(tool_calls_response) } end rescue => e - puts "## UNHANDLED error calling tools: #{e.message}" - puts e.backtrace.join("\n") + Rails.logger.info "## UNHANDLED error calling tools: #{e.message}" + Rails.logger.info e.backtrace.join("\n") raise ::Faraday::ParsingError end end diff --git a/app/services/fly.rb b/app/services/fly.rb index b47e96f99..b384d1e15 100644 --- a/app/services/fly.rb +++ b/app/services/fly.rb @@ -2,7 +2,7 @@ class Fly < SDK def change_db_swap(app:, swap:) app_name = app+"-db" unless swap.is_a?(Integer) || swap.to_i.to_s == swap.to_s - puts "Expected an integer for swap such as 512 but it was '#{swap}'. Aborting." + Rails.logger.info "Expected an integer for swap such as 512 but it was '#{swap}'. Aborting." return end swap = swap.to_i @@ -10,14 +10,14 @@ def change_db_swap(app:, swap:) apps = get_apps app_id = apps.find { |m| m.name == app_name }&.id if app_id.nil? - puts "Could not find the app named #{app_name}. Aborting." - puts "These are all the app names on your Fly account: #{apps.map(&:name).join(", ")}" + Rails.logger.info "Could not find the app named #{app_name}. Aborting." + Rails.logger.info "These are all the app names on your Fly account: #{apps.map(&:name).join(", ")}" return end machines = get_machines(app_name) if machines.length > 1 - puts "Expected only a single database machine under #{app_name} but found #{machines.length}. Aborting." + Rails.logger.info "Expected only a single database machine under #{app_name} but found #{machines.length}. Aborting." return end @@ -28,7 +28,7 @@ def change_db_swap(app:, swap:) updated_config = patch_machine(app_name, machine.id, config) - puts "Updated machine id #{machine.id} on #{app_name} to #{swap}mb. It make take a minute for the machine to finish booting." + Rails.logger.info "Updated machine id #{machine.id} on #{app_name} to #{swap}mb. It make take a minute for the machine to finish booting." end def get_apps diff --git a/app/services/sdk/verb.rb b/app/services/sdk/verb.rb index cf13a9423..3d657a2ab 100644 --- a/app/services/sdk/verb.rb +++ b/app/services/sdk/verb.rb @@ -131,6 +131,6 @@ def possible_test_warning(verb) return if !Rails.env.test? return if self.class.send("allow_#{verb}_#{@calling_method}") rescue false - puts "WARNING: live API call in test. USE: stub_#{verb}_response(:#{@calling_method}, status: ___, response: _______) do; ...; end" + Rails.logger.info "WARNING: live API call in test. USE: stub_#{verb}_response(:#{@calling_method}, status: ___, response: _______) do; ...; end" end end