Adding Citations support in the Swift Library
Usage
let maxTokens = 1024
let prompt = "Please analyze this document"
// Load PDF data
let pdfData = // your PDF data
let base64PDF = pdfData.base64EncodedString()
// Create document source
let documentSource = try MessageParameter.Message.Content.DocumentSource.pdf(base64Data: base64PDF, citations: .init(enabled: true))
// Create message with document and prompt
let message = MessageParameter.Message(
role: .user,
content: .list([
.document(documentSource),
.text(prompt)
])
)
// Create parameters
let parameters = MessageParameter(
model: .claude35Sonnet,
messages: [message],
maxTokens: maxTokens
)
// Send request
let response = try await service.streamMessage(parameters)