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

OpenAI: log errors #614

Merged
merged 4 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

* Implement ENV["OPENAI_LOG_ERRORS"] to display OpenAI http log_errors [#614](https://github.com/glebm/i18n-tasks/pull/614)
* Uses AST-parser for all ERB-files, not just `.html.erb`
* [Fixed regex in `PatternScanner`] (https://github.com/glebm/i18n-tasks/issues/572)
* Adds contextual parser to support more Rails-translations
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def translation_config # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComp
conf[:deepl_version] = ENV['DEEPL_VERSION'] if ENV.key?('DEEPL_VERSION')
conf[:openai_api_key] = ENV['OPENAI_API_KEY'] if ENV.key?('OPENAI_API_KEY')
conf[:openai_model] = ENV['OPENAI_MODEL'] if ENV.key?('OPENAI_MODEL')
conf[:openai_log_errors] = ENV['OPENAI_LOG_ERRORS'] if ENV.key?('OPENAI_LOG_ERRORS')
conf[:watsonx_api_key] = ENV['WATSONX_API_KEY'] if ENV.key?('WATSONX_API_KEY')
conf[:watsonx_project_id] = ENV['WATSONX_PROJECT_ID'] if ENV.key?('WATSONX_PROJECT_ID')
conf[:watsonx_model] = ENV['WATSONX_MODEL'] if ENV.key?('WATSONX_MODEL')
Expand Down
9 changes: 8 additions & 1 deletion lib/i18n/tasks/translators/openai_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@
private

def translator
@translator ||= OpenAI::Client.new(access_token: api_key)
@translator ||=
if @i18n_tasks.translation_config[:openai_log_errors]
OpenAI::Client.new(access_token: api_key, log_errors: @i18n_tasks.translation_config[:openai_log_errors]) do |f|

Check failure on line 57 in lib/i18n/tasks/translators/openai_translator.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Layout/LineLength: Line is too long. [122/120]
f.response :logger, Logger.new($stdout), bodies: true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Errors should be logged to STDERR
  2. I think we can always log the errors, no need for the environment variable

end
else
OpenAI::Client.new(access_token: api_key)
end
end

def api_key
Expand Down
Loading