-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_decoder.swift
More file actions
40 lines (33 loc) · 1.21 KB
/
test_decoder.swift
File metadata and controls
40 lines (33 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Foundation
struct ModelConfig: Codable, Identifiable, Hashable {
let id: String
let name: String
let provider: String
let upstreamModel: String
let supportsThinking: Bool
enum CodingKeys: String, CodingKey {
case id, name, provider
case upstreamModel = "upstream_model"
case supportsThinking = "supports_thinking"
}
}
struct DiscoveredModelsContainer: Codable {
let provider: String
let models: [ModelConfig]
let lastSync: Date
}
let path = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Application Support/EllProxy/discovered_models/discovered_copilot.json")
do {
let data = try Data(contentsOf: path)
let decoder = JSONDecoder()
// decoder.keyDecodingStrategy = .convertFromSnakeCase // Simulate our current code
// We need to handle Date decoding ISO8601 as typically used
decoder.dateDecodingStrategy = .iso8601
let container = try decoder.decode(DiscoveredModelsContainer.self, from: data)
print("Success! Loaded \(container.models.count) models")
for model in container.models {
print("- \(model.name) (\(model.id))")
}
} catch {
print("Error decoding: \(error)")
}