You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds the Foundation Models 26 APIs that AnyLanguageModel was missing:
@Generable(description:representNilExplicitlyInGeneratedContent:), GenerationSchema.init(type:description:representNilExplicitlyInGeneratedContent:properties:), and DynamicGenerationSchema.init(name:description:representNilExplicitlyInGeneratedContent:properties:)
DynamicGenerationSchema.null
logFeedbackAttachment(sentiment:issues:desiredResponseText:) and logFeedbackAttachment(sentiment:issues:desiredResponseContent:)
SystemLanguageModel.supportedLanguages, supportsLocale(_:), and the five tokenCount(for:) overloads (OS 26.4)
To match Foundation Models, a @Generable type's generated content now leaves out optional properties whose value is nil, instead of writing null. Pass representNilExplicitlyInGeneratedContent: true to keep the null values. With that flag, a session also fills in null for optional properties that a model's structured response leaves out, as Foundation Models does.
This PR also fixes SystemLanguageModel.logFeedbackAttachment and PrivateCloudComputeLanguageModel.logFeedbackAttachment, which dropped desiredOutput instead of passing it to Foundation Models.
For the schema-based overloads, Content is GeneratedContent, so this keeps response.content in its original form while rawContent gains the explicit null properties. Callers reading the primary content value therefore see different data from rawContent; use the transformed value when it can be cast to Content.
Both new convenience overloads ultimately rely on each model's desiredOutput forwarding. PrivateCloudComputeLanguageModel.logFeedbackAttachment still hard-codes desiredOutput: nil (Sources/AnyLanguageModel/Models/PrivateCloudComputeLanguageModel.swift:137), even though it creates the same Foundation Models session, so these APIs silently discard the requested text/content for PCC. Convert and forward the entry there as this PR now does for SystemLanguageModel.
Nested anyOf schemas are never considered a match. For example, an outer union containing a referenced inner [ExplicitNilObject, .null] resolves that reference to .anyOf; this switch rejects it, so traversal stops and omitted optionals in the explicit object are not filled with null. Recurse into nested union variants when matching the content shape.
Any valid Boolean expression other than a bare literal—such as a static constant or even a parenthesized true—is silently interpreted as false, so the generated content contradicts the value supplied to the public macro. Preserve the argument expression in generated code, or emit a macro diagnostic requiring a Boolean literal rather than changing its meaning.
rawContent cannot be cast to a typed Content.PartiallyGenerated, so the synthetic final snapshot pairs normalized raw content with the previous, unnormalized partial value. Consumers iterating the stream can therefore see omitted keys through snapshot.content.generatedContent even though snapshot.rawContent contains explicit nulls. Initialize the partial value from the normalized content instead.
This newly created Foundation Models session does not contain session.transcript, so it has no most recent PCC response to which the feedback and desired output can be attached. Rehydrate it from the converted transcript before calling logFeedbackAttachment, matching the generation path.
Feedback logs against a fresh session without the response transcript
The Foundation Models session is created only from tools and instructions, so it has none of session.transcript—including the response this feedback is supposed to describe. Passing desiredOutput therefore still logs against a fresh session rather than the actual exchange. Initialize the Foundation Models session from the converted transcript, as the response paths do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the Foundation Models 26 APIs that AnyLanguageModel was missing:
@Generable(description:representNilExplicitlyInGeneratedContent:),GenerationSchema.init(type:description:representNilExplicitlyInGeneratedContent:properties:), andDynamicGenerationSchema.init(name:description:representNilExplicitlyInGeneratedContent:properties:)DynamicGenerationSchema.nulllogFeedbackAttachment(sentiment:issues:desiredResponseText:)andlogFeedbackAttachment(sentiment:issues:desiredResponseContent:)SystemLanguageModel.supportedLanguages,supportsLocale(_:), and the fivetokenCount(for:)overloads (OS 26.4)To match Foundation Models, a
@Generabletype's generated content now leaves out optional properties whose value isnil, instead of writingnull. PassrepresentNilExplicitlyInGeneratedContent: trueto keep thenullvalues. With that flag, a session also fills innullfor optional properties that a model's structured response leaves out, as Foundation Models does.This PR also fixes
SystemLanguageModel.logFeedbackAttachmentandPrivateCloudComputeLanguageModel.logFeedbackAttachment, which droppeddesiredOutputinstead of passing it to Foundation Models.