如何控制 LanguageModelSession 回答所使用的语言?
Asked on 06/13/2025
1 search
To control the language used by a LanguageModelSession
, you can utilize the API to check whether the model supports a certain language. This is useful for ensuring that the user's current language is supported and for showing a disclaimer if it is not. Additionally, you can catch an unsupported language or locale error to handle cases where the language might not be supported. This approach allows you to provide a custom message in your UI if needed.
For more detailed information, you can refer to the session Deep dive into the Foundation Models framework (06:30).

Deep dive into the Foundation Models framework
Level up with the Foundation Models framework. Learn how guided generation works under the hood, and use guides, regexes, and generation schemas to get custom structured responses. We’ll show you how to use tool calling to let the model autonomously access external information and perform actions, for a personalized experience. To get the most out of this video, we recommend first watching “Meet the Foundation Models framework”.

Explore prompt design & safety for on-device foundation models
Design generative AI experiences that leverage the strengths of the Foundation Models framework. We’ll start by showing how to design prompts for the on-device large language model at the core of Apple Intelligence. Then, we’ll introduce key ideas around AI safety, and offer concrete strategies to make your generative AI features safe, reliable, and delightful.

Meet the Translation API
Discover how you can translate text across different languages in your app using the new Translation framework. We’ll show you how to quickly display translations in the system UI, and how to translate larger batches of text for your app’s UI.