Example iOS app that seeds a task management SQLite database and renders SwiftDBAI's DataChatView. Ships with a mock LLM for offline use and an OllamaWithSystemPrompt wrapper that fixes AnyLanguageModel's Ollama adapter dropping system instructions. Tested successfully with: - DemoLanguageModel (mock, pattern-matched SQL) - Ollama qwen3-coder-30b (local, real SQL generation) - OpenAI gpt-4o-mini (JOINs, GROUP BY, multi-turn) - Anthropic claude-haiku-4.5 (complex aggregations) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.6 KiB
Swift
49 lines
1.6 KiB
Swift
// SwiftDBAIDemoApp.swift
|
|
// SwiftDBAIDemo
|
|
//
|
|
// A minimal demo app showing DataChatView with a seeded SQLite database.
|
|
|
|
import SwiftUI
|
|
import SwiftDBAI
|
|
|
|
@main
|
|
struct SwiftDBAIDemoApp: App {
|
|
@State private var databasePath: String?
|
|
@State private var setupError: String?
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
Group {
|
|
if let path = databasePath {
|
|
DataChatView(
|
|
databasePath: path,
|
|
model: DemoLanguageModel(),
|
|
allowlist: .readOnly,
|
|
additionalContext: """
|
|
This is a task management database with projects, tasks, tags, \
|
|
and a task_tags junction table. Tasks have priority (1=low, 2=medium, \
|
|
3=high) and status ('todo', 'in_progress', 'done').
|
|
"""
|
|
)
|
|
} else if let error = setupError {
|
|
ContentUnavailableView(
|
|
"Database Setup Failed",
|
|
systemImage: "exclamationmark.triangle",
|
|
description: Text(error)
|
|
)
|
|
} else {
|
|
ProgressView("Setting up database...")
|
|
}
|
|
}
|
|
.task {
|
|
do {
|
|
let path = try DatabaseSeeder.seedIfNeeded()
|
|
databasePath = path
|
|
} catch {
|
|
setupError = error.localizedDescription
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|