Selecting an output language with Foundation Models

When using Foundation Models, is it possible to ask the model to produce output in a specific language, apart from giving an instruction like "Provide answers in <some language>." ? (I tried that and it kind of worked, but it seems fragile.)

I haven't noticed an API to do so and have a use-case where the output should be in a user-selectable language that is not the current system language.

First, check that your target language is supported by Apple Intelligence for this to work.

Next, what you'll want to do is first get the language/locale minimum identifier, of your target language, which should look something like "en-US", "fr", "en-AU", etc.

Now in the LanguageModelSession instructions, set the instructions to be "The user's locale is en-AU" (replacing en-AU with your locale code). This special phrase should work a bit more reliably than "Provide answers in <some language>" because of the way the model has been trained. This verbatim phrase should be at the start of your instructions, and you can add any custom instructions after that as you like.

I've tested The user's locale is de. as the first sentence, but this was completely ignored and the output was in English. By contrast, The output must be in German. worked.

I've filed FB18970592 to ask for an API that allows to set the output locale. I guess we're not the only ones that want an output in a different language, and avoiding prompt engineering is the exact point why @Generable exists. In the same spirit, hopefully there's going to be an API to reliably set the output language.

Apologies @eqHaisenko, and thanks for filing with Feedback Assistant!

We're investigating this issue.

Until then, a phrase like "The output must be in German" or another phrase that spells out the locale or language very explicitly is likely your best bet. For instance "The user's locale is de-DE" (the longer form of the language code) or "The user's locale is Germany. Respond in German.". The key piece is that this phrase (whichever output language phrase works for you) should in your session Instructions, preferably at the start of the Instructions text.

Selecting an output language with Foundation Models
 
 
Q