Auto-translate with OpenAI in Optimizely CMS
Before introducing new features in a product, it is common to run a beta test to identify any errors and check if the features are worth investing in. Optimizely has some packages under the namespace Episerver.Labs
that can be seen as such beta tests. Some products are eventually incorporated into the core product, while others quietly disappear.
A few exceptions have a long and prosperous life as Episerver.Labs
packages, and Episerver.Labs.LanguageManager
is a good example. This package has made it easier for editors to work with websites in multiple languages since 2015.
In 2019, my colleague Henning wrote a blog post on how this package can be used to translate entire pages from one language to another using Azure Cognitive Services. Since then, LanguageManager has been upgraded to support the latest version of Optimizely CMS, namely CMS 12, but otherwise it functions exactly as before.
In recent months, there has been a lot happening in the field of AI and large language models. I began to wonder if it is possible to let LanguageManager use services other than Azure Cognitive Services for translation. Maybe we can use GPT-4?
I found no documentation that explained how LanguageManager could be extended, but that did not stop me from trying. A quick look with the decompiler DotPeek revealed an interesting interface IMachineTranslatorProvider
.
From a newly discovered interface to a new add-on on Optimizely's NuGet feed, it took just a couple of hours.
New add-on for the LanguageManager add-on
Gulla.Episerver.Labs.LanguageManager.OpenAi
is the catchy name of my new add-on, and it adds a new IMachineTranslatorProvider
that allows you to use OpenAI to auto-translate content with LanguageManager.
After first installing the NuGet package and adding your own API key to the configuration, you can choose the OpenAI Translator Provider from Optimizely admin mode.
Afterwards, translations work as before, but now it is OpenAI that does the job when auto-translating your content to new languages.
If you want to use a different model, adjust the temperature (creative or predictable and boring), or give the translator specific instructions like tone of voice or specific words and concepts to use, you can do all of that with configuration.
If what I have created is not a perfect match for you, feel free to use it as a starting point to create your own Translator Provider!
Good luck!