SwiftDBAI: natural language queries for any SQLite database

Drop-in SwiftUI chat view, headless ChatEngine, LLM-agnostic via
AnyLanguageModel. Read-only by default with configurable allowlists.
Robust SQL parser with 63 tests. Includes demo app with GitHub stars dataset.
This commit is contained in:
Krishna Kumar
2026-04-04 09:30:56 -05:00
commit fcd752466a
80 changed files with 18265 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
// MockLanguageModel.swift
// SwiftDBAI Tests
//
// A mock LanguageModel for unit tests that returns canned responses.
import AnyLanguageModel
import Foundation
/// A mock language model that returns a configurable canned response.
///
/// Used in tests to avoid hitting a real LLM provider.
struct MockLanguageModel: LanguageModel {
typealias UnavailableReason = Never
/// The text the mock will return from `respond(...)`.
let responseText: String
init(responseText: String = "Mock summary response.") {
self.responseText = responseText
}
func respond<Content>(
within session: LanguageModelSession,
to prompt: Prompt,
generating type: Content.Type,
includeSchemaInPrompt: Bool,
options: GenerationOptions
) async throws -> LanguageModelSession.Response<Content> where Content: Generable {
let rawContent = GeneratedContent(kind: .string(responseText))
let content = try Content(rawContent)
return LanguageModelSession.Response(
content: content,
rawContent: rawContent,
transcriptEntries: [][...]
)
}
func streamResponse<Content>(
within session: LanguageModelSession,
to prompt: Prompt,
generating type: Content.Type,
includeSchemaInPrompt: Bool,
options: GenerationOptions
) -> sending LanguageModelSession.ResponseStream<Content> where Content: Generable {
let rawContent = GeneratedContent(kind: .string(responseText))
let content = try! Content(rawContent)
return LanguageModelSession.ResponseStream(content: content, rawContent: rawContent)
}
}