diff --git a/Modules/Sources/WordPressShared/Intelligence/IntelligenceService.swift b/Modules/Sources/WordPressShared/Intelligence/IntelligenceService.swift index 66f386c49c9e..9a2a3383aaed 100644 --- a/Modules/Sources/WordPressShared/Intelligence/IntelligenceService.swift +++ b/Modules/Sources/WordPressShared/Intelligence/IntelligenceService.swift @@ -45,7 +45,7 @@ public actor IntelligenceService { // - `useCase: .contentTagging` is not recommended for arbitraty hashtags let instructions = """ - You are helping a WordPress user add tags to a post or a page. + \(makeLocaleInstructions())You are helping a WordPress user add tags to a post or a page. **Parameters** - POST_CONTENT: contents of the post (HTML or plain text) @@ -54,9 +54,12 @@ public actor IntelligenceService { **Steps** - 1. Identify the specific formatting pattern used (e.g., lowercase with underscores, capitalized words with spaces, etc) - - 2. Generate a list of ten most relevant suggested tags based on POST_CONTENT and SITE_TAGS relevant to the content. + - 2. Identify the language used in SITE_TAGS and POST_CONTENT + - 3. Generate a list of ten most relevant suggested tags based on POST_CONTENT and SITE_TAGS relevant to the content. **Requirements** + - You MUST generate tags in the same language as SITE_TAGS and POST_CONTENT + - Tags MUST match the formatting pattern and language of existing tags - Do not include any tags from EXISTING_POST_TAGS - If there are no relevant suggestions, returns an empty list - Do not produce any output other than the final list of tag @@ -101,9 +104,10 @@ public actor IntelligenceService { let content = extractRelevantText(from: content, ratio: 0.8) let instructions = """ - You are helping a WordPress user understand the content of a post. + \(makeLocaleInstructions())You are helping a WordPress user understand the content of a post. Generate a concise summary that captures the main points and key information. The summary should be clear, informative, and written in a neutral tone. + You MUST generate the summary in the same language as the post content. Do not include anything other than the summary in the response. """ @@ -124,10 +128,11 @@ public actor IntelligenceService { public func summarizeSupportTicket(content: String) async throws -> String { let instructions = """ - You are helping a user by summarizing their support request down to a single sentence + \(makeLocaleInstructions())You are helping a user by summarizing their support request down to a single sentence with fewer than 10 words. The summary should be clear, informative, and written in a neutral tone. + You MUST generate the summary in the same language as the support request. Do not include anything other than the summary in the response. """ @@ -155,6 +160,19 @@ public actor IntelligenceService { let postSizeLimit = Double(IntelligenceService.contextSizeLimit) * ratio return String((extract ?? post).prefix(Int(postSizeLimit))) } + + /// Generates locale-specific instructions for the language model. + /// + /// Following Apple's recommended approach for multilingual support: + /// https://developer.apple.com/documentation/foundationmodels/support-languages-and-locales-with-foundation-models + private nonisolated func makeLocaleInstructions(for locale: Locale = .current) -> String { + // Skip the locale phrase for U.S. English (Apple's recommendation) + if Locale.Language(identifier: "en_US").isEquivalent(to: locale.language) { + return "" + } + // Use the exact phrase format recommended by Apple to reduce hallucinations + return "The person's locale is \(locale.identifier).\n" + } } private extension Array where Element: Hashable { diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 1eb9adfb1ca9..cef50b8bdb9f 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,6 +1,6 @@ 26.6 ----- - +* [**] [Intelligence] Expand AI-based features to more locales [#25034] 26.5 ----- diff --git a/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift b/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift index 9f344b213e5f..16055bf9c4fc 100644 --- a/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift +++ b/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift @@ -1,5 +1,6 @@ import BuildSettingsKit import Foundation +import FoundationModels /// FeatureFlag exposes a series of features to be conditionally enabled on /// different builds. @@ -80,8 +81,10 @@ public enum FeatureFlag: Int, CaseIterable { case .newStats: return false case .intelligence: - let languageCode = Locale.current.language.languageCode?.identifier - return (languageCode ?? "en").hasPrefix("en") + guard #available(iOS 26, *) else { + return false + } + return SystemLanguageModel.default.supportsLocale() case .newSupport: return false case .nativeBlockInserter: