logFeedbackAttachment(sentiment:issues:desiredOutput:)
Logs and serializes data that includes session information that you attach when reporting feedback to Apple.
Declaration
@discardableResult final func logFeedbackAttachment(sentiment: LanguageModelFeedback.Sentiment?, issues: [LanguageModelFeedback.Issue] = [], desiredOutput: Transcript.Entry? = nil) -> DataParameters
- sentiment:
A Sentiment rating about the model’s output (positive, negative, or neutral).
- issues:
An array of specific Issue you identify with the model’s response.
- desiredOutput:
A Transcript entry showing the output you expect.
Mentioned in
Return Value
A Data object containing the JSON-encoded attachment.
Discussion
This method creates a structured attachment containing the session’s transcript and additional feedback information you provide. You can save the attachment data to a .json file and attach it when reporting feedback with Feedback Assistant.
If an error occurs during a previous response, the method includes any rejected entries that were rolled back from the transcript 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 helpfulFeedbackData = session.logFeedbackAttachment(sentiment: .positive)
// Create feedback for a problematic response.
let problematicFeedbackData = session.logFeedbackAttachment(
sentiment: .negative,
issues: [
LanguageModelFeedback.Issue(
category: .incorrect,
explanation: "The model provided outdated information"
)
],
desiredOutput: Transcript.Entry.response(...)
)If 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)To create a transcript when desiredOutput is a Generable type:
let customType = MyCustomType(...) // A generable type.
let structure = Transcript.StructuredSegment(source: 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)When you submit feedback to Apple, write your feedback to a .json file and include the file as an attachment to Feedback Assistant. You can include multiple feedback attachments in the same file:
let allFeedback = helpfulFeedbackData + problematicFeedbackData
let url = URL(fileURLWithPath: "path/to/save/feedback.jsonl")
try allFeedback.write(to: url)