Skip to content

Commit b4a20c9

Browse files
committed
Enable FF
1 parent 6a50a4d commit b4a20c9

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Modules/Sources/WordPressShared/Intelligence/IntelligenceService.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public actor IntelligenceService {
4545
// - `useCase: .contentTagging` is not recommended for arbitraty hashtags
4646

4747
let instructions = """
48-
You are helping a WordPress user add tags to a post or a page.
48+
\(makeLocaleInstructions())You are helping a WordPress user add tags to a post or a page.
4949
5050
**Parameters**
5151
- POST_CONTENT: contents of the post (HTML or plain text)
@@ -54,9 +54,12 @@ public actor IntelligenceService {
5454
5555
**Steps**
5656
- 1. Identify the specific formatting pattern used (e.g., lowercase with underscores, capitalized words with spaces, etc)
57-
- 2. Generate a list of ten most relevant suggested tags based on POST_CONTENT and SITE_TAGS relevant to the content.
57+
- 2. Identify the language used in SITE_TAGS and POST_CONTENT
58+
- 3. Generate a list of ten most relevant suggested tags based on POST_CONTENT and SITE_TAGS relevant to the content.
5859
5960
**Requirements**
61+
- You MUST generate tags in the same language as SITE_TAGS and POST_CONTENT
62+
- Tags MUST match the formatting pattern and language of existing tags
6063
- Do not include any tags from EXISTING_POST_TAGS
6164
- If there are no relevant suggestions, returns an empty list
6265
- Do not produce any output other than the final list of tag
@@ -101,9 +104,10 @@ public actor IntelligenceService {
101104
let content = extractRelevantText(from: content, ratio: 0.8)
102105

103106
let instructions = """
104-
You are helping a WordPress user understand the content of a post.
107+
\(makeLocaleInstructions())You are helping a WordPress user understand the content of a post.
105108
Generate a concise summary that captures the main points and key information.
106109
The summary should be clear, informative, and written in a neutral tone.
110+
You MUST generate the summary in the same language as the post content.
107111
108112
Do not include anything other than the summary in the response.
109113
"""
@@ -124,10 +128,11 @@ public actor IntelligenceService {
124128

125129
public func summarizeSupportTicket(content: String) async throws -> String {
126130
let instructions = """
127-
You are helping a user by summarizing their support request down to a single sentence
131+
\(makeLocaleInstructions())You are helping a user by summarizing their support request down to a single sentence
128132
with fewer than 10 words.
129133
130134
The summary should be clear, informative, and written in a neutral tone.
135+
You MUST generate the summary in the same language as the support request.
131136
132137
Do not include anything other than the summary in the response.
133138
"""
@@ -155,6 +160,19 @@ public actor IntelligenceService {
155160
let postSizeLimit = Double(IntelligenceService.contextSizeLimit) * ratio
156161
return String((extract ?? post).prefix(Int(postSizeLimit)))
157162
}
163+
164+
/// Generates locale-specific instructions for the language model.
165+
///
166+
/// Following Apple's recommended approach for multilingual support:
167+
/// https://developer.apple.com/documentation/foundationmodels/support-languages-and-locales-with-foundation-models
168+
private nonisolated func makeLocaleInstructions(for locale: Locale = .current) -> String {
169+
// Skip the locale phrase for U.S. English (Apple's recommendation)
170+
if Locale.Language(identifier: "en_US").isEquivalent(to: locale.language) {
171+
return ""
172+
}
173+
// Use the exact phrase format recommended by Apple to reduce hallucinations
174+
return "The person's locale is \(locale.identifier).\n"
175+
}
158176
}
159177

160178
private extension Array where Element: Hashable {

WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import BuildSettingsKit
22
import Foundation
3+
import FoundationModels
34

45
/// FeatureFlag exposes a series of features to be conditionally enabled on
56
/// different builds.
@@ -80,8 +81,10 @@ public enum FeatureFlag: Int, CaseIterable {
8081
case .newStats:
8182
return false
8283
case .intelligence:
83-
let languageCode = Locale.current.language.languageCode?.identifier
84-
return (languageCode ?? "en").hasPrefix("en")
84+
guard #available(iOS 26, *) else {
85+
return false
86+
}
87+
return SystemLanguageModel.default.supportsLocale()
8588
case .newSupport:
8689
return false
8790
case .nativeBlockInserter:

0 commit comments

Comments
 (0)