new features
This commit is contained in:
+67
-1
@@ -52,6 +52,7 @@ enum Delta: Equatable, Sendable {
|
||||
case answer(String)
|
||||
case thinking(String)
|
||||
case backend(String)
|
||||
case metrics(ProviderMetrics)
|
||||
case committed
|
||||
}
|
||||
|
||||
@@ -109,7 +110,7 @@ enum Router {
|
||||
case .answer(let text), .thinking(let text):
|
||||
committed = committed || !text.isEmpty
|
||||
case .committed: committed = true
|
||||
case .backend: break
|
||||
case .backend, .metrics: break
|
||||
}
|
||||
continuation.yield(delta)
|
||||
}
|
||||
@@ -132,3 +133,68 @@ enum Router {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ProviderMetrics: Equatable, Sendable {
|
||||
let tokens: Int
|
||||
let seconds: Double
|
||||
|
||||
var tokensPerSecond: Double? {
|
||||
guard tokens >= 0, seconds > 0, seconds.isFinite else { return nil }
|
||||
let rate = Double(tokens) / seconds
|
||||
return rate.isFinite ? rate : nil
|
||||
}
|
||||
}
|
||||
|
||||
struct GenerationMeasurement: Identifiable {
|
||||
let id = UUID()
|
||||
let backend: String
|
||||
let firstOutput: Double?
|
||||
let seconds: Double
|
||||
let characters: Int
|
||||
let provider: ProviderMetrics?
|
||||
let outcome: String
|
||||
}
|
||||
|
||||
enum PromptMode: String, CaseIterable, Identifiable {
|
||||
case standard = "Default"
|
||||
case concise = "Concise"
|
||||
case code = "Coding"
|
||||
case study = "Study"
|
||||
case creative = "Creative"
|
||||
case custom = "Custom"
|
||||
|
||||
var id: Self { self }
|
||||
|
||||
func instructions(custom text: String) -> String {
|
||||
switch self {
|
||||
case .standard: ""
|
||||
case .concise: "Answer directly and concisely. Include details required for accuracy."
|
||||
case .code: "Act as a software engineering assistant. Explain assumptions, provide runnable examples where appropriate, and suggest ways to verify changes."
|
||||
case .study: "Teach step by step. Use a worked example and offer a short practice question where appropriate."
|
||||
case .creative: "Explore varied ideas. Preserve the requested voice and constraints, and develop the strongest ideas with concrete details."
|
||||
case .custom: String(text.trimmingCharacters(in: .whitespacesAndNewlines).prefix(12000))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PromptDraft {
|
||||
var role = ""
|
||||
var task = ""
|
||||
var context = ""
|
||||
var audience = ""
|
||||
var constraints = ""
|
||||
var format = ""
|
||||
var examples = ""
|
||||
var success = ""
|
||||
|
||||
var rendered: String {
|
||||
[
|
||||
("Role", role), ("Task", task), ("Context", context), ("Audience", audience),
|
||||
("Requirements and constraints", constraints), ("Output format", format),
|
||||
("Examples", examples), ("Success criteria", success)
|
||||
].compactMap { label, value in
|
||||
let content = value.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return content.isEmpty ? nil : "## \(label)\n\(content)"
|
||||
}.joined(separator: "\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user