Download Sources/PromptGarageCore/Import/CodexHistoryParser.swift from smlflg/PromtGarageMac: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/smlflg/PromtGarageMac/resolve/main/Sources/PromptGarageCore/Import/CodexHistoryParser.swift
- Command line
-
hf download hf://smlflg/PromtGarageMac/Sources/PromptGarageCore/Import/CodexHistoryParser.swift
-
curl -L -o CodexHistoryParser.swift https://huggingface.co/smlflg/PromtGarageMac/resolve/main/Sources/PromptGarageCore/Import/CodexHistoryParser.swift
1.53 kB
| import Foundation | |
| struct CodexHistoryParser: ImportParser { | |
| func parse(sourceURL: URL, dedupIndex: DedupIndex) throws -> ImportParseResult { | |
| let files = try ImportFiles.immediateFiles( | |
| at: sourceURL, | |
| expected: "eine Codex history.jsonl oder den zugehörigen Konfigurationsordner", | |
| directFileMatches: { $0.pathExtension.lowercased() == "jsonl" }, | |
| directoryFileMatches: { $0.lastPathComponent == "history.jsonl" } | |
| ) | |
| var accumulator = ImportAccumulator( | |
| minimumLength: 20, | |
| maximumLength: 10_000, | |
| dedupIndex: dedupIndex | |
| ) | |
| for fileURL in files { | |
| for line in try ImportFiles.lines(from: fileURL) { | |
| let root: Any | |
| do { | |
| root = try ImportJSON.object(fromLine: line) | |
| } catch { | |
| accumulator.skipMalformed() | |
| continue | |
| } | |
| guard | |
| let object = root as? [String: Any], | |
| let text = object["text"] as? String | |
| else { | |
| accumulator.skipMalformed() | |
| continue | |
| } | |
| accumulator.accept( | |
| text, | |
| sourcePrefix: "codex-raw", | |
| tags: "codex", | |
| promptedAt: ImportTimestamp.normalize(object["ts"]) | |
| ) | |
| } | |
| } | |
| return accumulator.result() | |
| } | |
| } | |