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 translation context for OpenAI #1130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

phcollignon
Copy link

@phcollignon phcollignon commented Apr 23, 2024

OpenAI give more accurate translations if we describe the translation context into the prompt.

This pull request adds a text area settings for the OpenAI translation engine where you can describe the context of your application.
It is then passed to the OpenAI API prompt for a more accurate translation.

I tested it with OpenAI GPT4 API key and it works quite good :
in example "I have some shares for you" gives two different translations in french depending of the context :

  • file sharing application context : "J'ai quelques partages pour toi"
  • financial application : "J'ai quelques actions pour toi"

Regards


let generatedUserPrompt = `translate from ${sourceLang} to ${targetLang}:\n\n${options.text}`;
const contextInstruction = appContext ? `Please consider the following context for a more accurate translation:\n\nContext Information: ${appContext}\n\n` : '';
let generatedUserPrompt = `${contextInstruction}Given the above context, translate the following from ${sourceLang} to ${targetLang}:\n\n${options.text}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

in case there is no context, old prompt should be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants