Skip to content

SwiftAnthropic v2.1.0

Latest
Compare
Choose a tag to compare
@jamesrochabrun jamesrochabrun released this 23 Jan 23:18
2bfd7ca

Adding Citations support in the Swift Library

Screenshot 2025-01-23 at 3 17 12 PM

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)