Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think the prompt can be more direct here: "You MUST generate the summary in the (locale.identifier) locale.", and remove the makeLocaleInstructions() above?


Do not include anything other than the summary in the response.
"""
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
26.6
-----

* [**] [Intelligence] Expand AI-based features to more locales [#25034]

26.5
-----
Expand Down
7 changes: 5 additions & 2 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BuildSettingsKit
import Foundation
import FoundationModels

/// FeatureFlag exposes a series of features to be conditionally enabled on
/// different builds.
Expand Down Expand Up @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically redundant; just some more defensive code.

return false
}
return SystemLanguageModel.default.supportsLocale()
case .newSupport:
return false
case .nativeBlockInserter:
Expand Down