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

Add configuration for OpenAI prompt #533

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

michaelbaudino
Copy link
Contributor

@michaelbaudino michaelbaudino commented Nov 20, 2023

The default prompt now includes instructions to never translate HTML tags (e.g. <strong>) nor Ruby I18n variables (e.g. %{count}).

This PR also makes the system prompt passed to OpenAI configurable directly from i18n-tasks.yml.

Incidentally, it also fixes a Rubocop offense.

This is a followup of #532.

@michaelbaudino michaelbaudino changed the title Add configuration for openai prompt Add configuration for OpenAI prompt Nov 20, 2023
@michaelbaudino michaelbaudino force-pushed the add-configuration-for-openai-prompt branch from 3dd43c7 to 8151b07 Compare November 20, 2023 14:59
@@ -116,6 +116,17 @@ search:
# # OpenAI
# openai_api_key: "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# # openai_model: "gpt-3.5-turbo" # see https://platform.openai.com/docs/models
# # openai_system_prompt: # may contain `%{from}` and `%{to}`, which will be replaced by source and target locale codes, respectively, using `Kernel.format`
Copy link
Owner

@glebm glebm Nov 20, 2023

Choose a reason for hiding this comment

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

The settings in this file are formatted so that uncommenting turns them into valid options.
Please move the comment above the line and add the appropriate multiline string sigil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just changed it as I think you requested 👍

I tried to make it consistent with what was done for Deepl configuration, for both mandatory configuration lines, optional (commented) configuration lines and plain old comments (with plain old English).

I used a folded style indicator (>) with a "stripping" block chomping indicator (-) to explicitly indicate the multiline field and how it will be processed (resulting in a >- marker): it seems to me it was the more logical processing method to apply, but I'm happy to change it if you prefer another one.

I hope that's what you expected.


On a side note, though, I'm pretty sure the previous implementation was still valid YAML when uncommented (despite the end-of-line comment and the lack of explicit multiline indicator 🤷):

YAML.safe_load(<<~YAML)
  openai_system_prompt: # may contain `%{from}` and `%{to}`, which will be replaced by source and target locale codes, respectively (using `Kernel.format`)
    You are a professional translator that translates content from the %{from} locale
    to the %{to} locale in an i18n locale array.
  
    The array has a structured format and contains multiple strings. Your task is to translate
    each of these strings and create a new array with the translated strings.
  
    HTML markups (enclosed in < and > characters) must not be changed under any circumstance.
    Variables (starting with %%{ and ending with }) must not be changed under any circumstance.
  
    Keep in mind the context of all the strings for a more accurate translation.
YAML
# => {"openai_system_prompt"=>
#      "You are a professional translator that translates content from the %{from} locale to the %{to} locale in an i18n locale array.\nThe array has a structured format and contains multiple strings. Your task is to translate each of these strings and create a new array with the translated strings.\nHTML markups (enclosed in < and > characters) must not be changed under any circumstance. Variables (starting with %%{ and ending with }) must not be changed under any circumstance.\nKeep in mind the context of all the strings for a more accurate translation."}

YAML is such a pain :trollface:

Copy link
Owner

Choose a reason for hiding this comment

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

Indeed, YAML is gnarly. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks to you for all the work on this gem 🙏 💜

The default prompt now includes instructions to **never** translate HTML tags (e.g. `<strong>`) nor Ruby I18n variables (e.g. `%{count}`).

This commit also makes the system prompt passed to OpenAI configurable directly from `i18n-tasks.yml`.
@michaelbaudino michaelbaudino force-pushed the add-configuration-for-openai-prompt branch from 8151b07 to c425870 Compare November 20, 2023 21:06
@glebm glebm merged commit 77e5372 into glebm:main Nov 20, 2023
6 checks passed
@michaelbaudino michaelbaudino deleted the add-configuration-for-openai-prompt branch November 20, 2023 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants