Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaces puts with logger now that logger works #549

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/jobs/get_next_ai_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/services/ai_backend/anthropic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/services/ai_backend/open_ai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions app/services/ai_backend/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/services/fly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ 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

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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/services/sdk/verb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading