Download Sources/PromptGarageCore/Models/PromptRecord.swift from smlflg/PromtGarageMac: direct link, hf CLI and curl.
- Browser
- Download file 3.52 kB
-
https://huggingface.co/smlflg/PromtGarageMac/resolve/main/Sources/PromptGarageCore/Models/PromptRecord.swift
- Command line
-
hf download hf://smlflg/PromtGarageMac/Sources/PromptGarageCore/Models/PromptRecord.swift
-
curl -L -o PromptRecord.swift https://huggingface.co/smlflg/PromtGarageMac/resolve/main/Sources/PromptGarageCore/Models/PromptRecord.swift
3.52 kB
| import Foundation | |
| import GRDB | |
| public struct PromptRecord: Codable, FetchableRecord, Identifiable, Hashable, Sendable { | |
| public static let databaseTableName = "prompts" | |
| public let id: Int64 | |
| public var title: String | |
| public var content: String | |
| public var source: String? | |
| public var isStarred: Bool | |
| public var tags: String? | |
| public var model: String? | |
| public var rating: Int? | |
| public var useCount: Int | |
| public var createdAt: String | |
| public var updatedAt: String | |
| public var promptedAt: String? | |
| public init( | |
| id: Int64, | |
| title: String, | |
| content: String, | |
| source: String?, | |
| isStarred: Bool, | |
| tags: String?, | |
| model: String?, | |
| rating: Int?, | |
| useCount: Int, | |
| createdAt: String, | |
| updatedAt: String, | |
| promptedAt: String? = nil | |
| ) { | |
| self.id = id | |
| self.title = title | |
| self.content = content | |
| self.source = source | |
| self.isStarred = isStarred | |
| self.tags = tags | |
| self.model = model | |
| self.rating = rating | |
| self.useCount = useCount | |
| self.createdAt = createdAt | |
| self.updatedAt = updatedAt | |
| self.promptedAt = promptedAt | |
| } | |
| public var tagList: [String] { | |
| guard let tags else { return [] } | |
| return tags | |
| .split(separator: ",") | |
| .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | |
| .filter { !$0.isEmpty } | |
| } | |
| public var sourceFamily: String { | |
| guard let source, !source.isEmpty else { return "unknown" } | |
| return source.split(separator: ":", maxSplits: 1).first.map(String.init) ?? source | |
| } | |
| enum CodingKeys: String, CodingKey { | |
| case id | |
| case title | |
| case content | |
| case source | |
| case isStarred = "is_starred" | |
| case tags | |
| case model | |
| case rating | |
| case useCount = "use_count" | |
| case createdAt = "created_at" | |
| case updatedAt = "updated_at" | |
| case promptedAt = "prompted_at" | |
| } | |
| } | |
| public struct PromptDraft: Hashable, Sendable { | |
| public var title: String | |
| public var content: String | |
| public var source: String | |
| public var tags: String? | |
| public var model: String? | |
| public var rating: Int? | |
| public var isStarred: Bool | |
| public init( | |
| title: String = "", | |
| content: String = "", | |
| source: String = "manual", | |
| tags: String? = nil, | |
| model: String? = nil, | |
| rating: Int? = nil, | |
| isStarred: Bool = false | |
| ) { | |
| self.title = title | |
| self.content = content | |
| self.source = source | |
| self.tags = tags | |
| self.model = model | |
| self.rating = rating | |
| self.isStarred = isStarred | |
| } | |
| public init(prompt: PromptRecord) { | |
| title = prompt.title | |
| content = prompt.content | |
| source = prompt.source ?? "manual" | |
| tags = prompt.tags | |
| model = prompt.model | |
| rating = prompt.rating | |
| isStarred = prompt.isStarred | |
| } | |
| public var validationMessage: String? { | |
| if title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | |
| return "Der Titel darf nicht leer sein." | |
| } | |
| if content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | |
| return "Der Prompt-Inhalt darf nicht leer sein." | |
| } | |
| if let rating, !(1...5).contains(rating) { | |
| return "Die Bewertung muss zwischen 1 und 5 liegen." | |
| } | |
| return nil | |
| } | |
| } | |