Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.prism.byescaleira.com/llms.txt

Use this file to discover all available pages before exploring further.

PrismIntelligence unifies four intelligence backends behind a single actor-based client. You can train a Core ML model from any Codable struct, run text classification or tabular regression on-device, generate text via Apple Intelligence using the FoundationModels framework, or call a remote LLM over the network—all with the same API surface.

Installation

import PrismIntelligence

PrismIntelligenceClient

PrismIntelligenceClient is the primary entry point. Create it with one of four factory methods, then call the appropriate prediction or generation method.

Factory methods

// Looks up the model in the default catalog by its identifier
let client = try await PrismIntelligenceClient.local(modelID: "sentiment")

Capabilities by backend

CapabilityLocalAppleRemote
textClassification
tabularClassification
tabularRegression
languageGeneration
Check availability before making requests:
let status = await client.status()

if status.isAvailable {
    // safe to proceed
} else {
    print(status.reason ?? "backend unavailable")
}

Running predictions

Text classification

let client = try await PrismIntelligenceClient.local(modelID: "sentiment")

let label = try await client.classify(text: "I love this product!")
// e.g. "positive"

Tabular classification

Provide a PrismIntelligenceFeatureRow—a [String: PrismIntelligenceFeatureValue] dictionary—and receive label probabilities.
let features: PrismIntelligenceFeatureRow = [
    "age":    .int(34),
    "income": .double(75_000),
    "region": .string("northeast")
]

let probabilities = try await client.classify(features: features)
// ["approved": 0.82, "declined": 0.18]

Tabular regression

let features: PrismIntelligenceFeatureRow = [
    "rooms": .int(3),
    "area":  .double(120),
    "floor": .int(4)
]

let price = try await client.regress(features: features)
// e.g. 447500.0

Language generation

let client = PrismIntelligenceClient.apple()

let summary = try await client.generate("Summarize quantum computing in one sentence.")

// With a system prompt
let answer = try await client.generate(
    "What's the capital of France?",
    systemPrompt: "You are a concise geography assistant."
)

Training models with PrismCodableTrainingData

PrismCodableTrainingData converts any array of Codable structs into training data using Mirror reflection. You point it at target and feature key paths—no CSV export required.

Tabular regressor

struct HouseData: Codable {
    var rooms: Int
    var area: Double
    var neighborhood: String
    var price: Double
}

let data = [
    HouseData(rooms: 3, area: 120, neighborhood: "Centro",   price: 450_000),
    HouseData(rooms: 2, area: 80,  neighborhood: "Zona Sul", price: 320_000),
    // … more rows
]

let training = PrismCodableTrainingData(data: data)

let result = await training.trainRegressor(
    id: "house_price",
    name: "House Price Predictor",
    target: \.price
)

Tabular classifier

let result = await training.trainClassifier(
    id: "loan_approval",
    name: "Loan Approval Classifier",
    target: \.approved
)

Text classifier

struct ReviewSample: Codable {
    var text: String
    var sentiment: String
}

let training = PrismCodableTrainingData(data: reviews)

let result = await training.trainTextClassifier(
    id: "sentiment",
    name: "Sentiment Classifier",
    text: \.text,
    label: \.sentiment
)
After training succeeds, load the saved model by its id and run predictions:
let client = try await PrismIntelligenceClient.local(modelID: "house_price")
let price = try await client.regress(features: ["rooms": .int(4), "area": .double(150)])

Feature values

PrismIntelligenceFeatureValue is the typed wrapper for individual feature inputs:
PrismIntelligenceFeatureValue.string("downtown")
PrismIntelligenceFeatureValue.int(3)
PrismIntelligenceFeatureValue.double(120.5)
PrismIntelligenceFeatureValue.bool(true)

// Infer from Any at runtime
let value = PrismIntelligenceFeatureValue(someValue)
You can also pass [String: Any] directly to classify(features:) and regress(features:)—the client converts supported types automatically.

Unified request/response API

Use execute(_:) when you want a single dispatch point for all request types:
let request = PrismIntelligenceRequest.classifyText("This is fantastic!")
let response = try await client.execute(request)

switch response {
case .textClassification(let label):
    print(label)
case .tabularRegression(let value):
    print(value)
case .language(let response):
    print(response.content)
default:
    break
}
Calling a method the backend does not support—for example, classify(text:) on a remote client—throws PrismIntelligenceError.unsupportedOperation. Check status().capabilities before dispatching requests if the backend type is not known at compile time.