logFeedbackAttachment(sentiment:issues:desiredOutput:)
Logs and serializes a feedback attachment that can be submitted to Apple.
Declaration
@discardableResult final func logFeedbackAttachment(sentiment: LanguageModelFeedback.Sentiment?, issues: [LanguageModelFeedback.Issue] = [], desiredOutput: Transcript.Entry? = nil) -> DataParameters
- sentiment:
An optional sentiment rating about the model’s output (positive, negative, or neutral).
- issues:
An array of specific issues identified with the model’s response. Defaults to an empty array.
- desiredOutput:
An optional transcript entry showing what the desired output should have been.
Mentioned in
Return Value
A Data object containing the JSON-encoded feedback attachment that can be submitted to Feedback Assistant.
Discussion
This method creates a structured feedback attachment containing the session’s transcript and any provided feedback information. The attachment can be saved to a file and submitted to Apple using Feedback Assistant.
If an error occurred during a previous response, any rejected entries that were rolled back from the transcript are included in the feedback data.
let session = LanguageModelSession()
let response = try await session.respond(to: "What is the capital of France?")
// Create feedback for a helpful response
let feedbackData = session.logFeedbackAttachment(sentiment: .positive)
// Or create feedback for a problematic response
let feedbackData = session.logFeedbackAttachment(
sentiment: .negative,
issues: [
LanguageModelFeedback.Issue(
category: .incorrect,
explanation: "The model provided outdated information"
)
],
desiredOutput: Transcript.Entry.response(...)
)If your desiredOutput is a string, use Transcript.Entry.response(_:) to turn your desired output into a Transcript entry:
let text = Transcript.TextSegment(content: "The capital of France is Paris.")
let segment = Transcript.Segment.text(text)
let response = Transcript.Response(segments: [segment])
let entry = Transcript.Entry.response(response)If your desiredOutput is a Generable type, turning that into a Transcript entry is slightly different:
let customType = MyCustomType(...) // A generable type.
let structure = Transcript.StructuredSegment(schemaName: String(describing: Foo.self), content: customType.generatedContent)
let segment = Transcript.Segment.structure(structure)
let response = Transcript.Response(segments: [segment])
let entry = Transcript.Entry.response(response)Finally, if you’d like to submit the feedback to Apple, write your feedback to a .json file and include the file as an attachment to Feedback Assistant. You can include one or many feedback attachment in the same file:
let allFeedback = feedbackData + feedbackData2 + feedbackData3
let url = URL(fileURLWithPath: "path/to/save/feedback.json")
try allFeedback.write(to: url)