forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalSummaryDraft.swift
More file actions
160 lines (146 loc) · 4.66 KB
/
Copy pathLocalSummaryDraft.swift
File metadata and controls
160 lines (146 loc) · 4.66 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import Foundation
/// Structured output the local engine returns for one map or reduce pass.
/// Field names match the W1 wire so a well-behaved model can be stamped into
/// `OmiAPI.ClientProcessing` without a second translation layer.
struct LocalSummaryDraft: Codable, Sendable, Equatable {
var title: String
var overview: String
var emoji: String?
var category: String?
var sections: [LocalSectionDraft]
var events: [LocalEventDraft]
var actionItems: [LocalActionItemDraft]
enum CodingKeys: String, CodingKey {
case title
case overview
case emoji
case category
case sections
case events
case actionItems = "action_items"
}
init(
title: String,
overview: String = "",
emoji: String? = nil,
category: String? = "other",
sections: [LocalSectionDraft] = [],
events: [LocalEventDraft] = [],
actionItems: [LocalActionItemDraft] = []
) {
self.title = title
self.overview = overview
self.emoji = emoji
self.category = category
self.sections = sections
self.events = events
self.actionItems = actionItems
}
init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
title = try c.decodeIfPresent(String.self, forKey: .title) ?? ""
overview = try c.decodeIfPresent(String.self, forKey: .overview) ?? ""
emoji = try c.decodeIfPresent(String.self, forKey: .emoji)
category = try c.decodeIfPresent(String.self, forKey: .category)
sections = try c.decodeIfPresent([LocalSectionDraft].self, forKey: .sections) ?? []
events = try c.decodeIfPresent([LocalEventDraft].self, forKey: .events) ?? []
actionItems = try c.decodeIfPresent([LocalActionItemDraft].self, forKey: .actionItems) ?? []
}
static let jsonSchema = LocalInferenceJSONSchema(
name: "client_processing_draft",
json: Data(
"""
{
"type": "object",
"properties": {
"title": {"type": "string"},
"overview": {"type": "string"},
"emoji": {"type": "string"},
"category": {"type": "string"},
"sections": {
"type": "array",
"items": {
"type": "object",
"properties": {
"heading": {"type": "string"},
"body_markdown": {"type": "string"}
},
"required": ["heading", "body_markdown"]
}
},
"events": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"description": {"type": "string"},
"start": {"type": "string"},
"duration": {"type": "integer"}
},
"required": ["title", "start", "duration"]
}
},
"action_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"description": {"type": "string"},
"completed": {"type": "boolean"}
},
"required": ["description"]
}
}
},
"required": ["title"]
}
""".utf8)
)
}
struct LocalSectionDraft: Codable, Sendable, Equatable {
var heading: String
var bodyMarkdown: String
enum CodingKeys: String, CodingKey {
case heading
case bodyMarkdown = "body_markdown"
}
}
struct LocalEventDraft: Codable, Sendable, Equatable {
var title: String
var description: String
var start: String
var duration: Int
enum CodingKeys: String, CodingKey {
case title
case description
case start
case duration
}
init(title: String, description: String = "", start: String, duration: Int) {
self.title = title
self.description = description
self.start = start
self.duration = duration
}
init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
title = try c.decode(String.self, forKey: .title)
description = try c.decodeIfPresent(String.self, forKey: .description) ?? ""
start = try c.decode(String.self, forKey: .start)
duration = try c.decodeIfPresent(Int.self, forKey: .duration) ?? 30
}
}
struct LocalActionItemDraft: Codable, Sendable, Equatable {
var description: String
var completed: Bool
init(description: String, completed: Bool = false) {
self.description = description
self.completed = completed
}
init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
description = try c.decode(String.self, forKey: .description)
completed = try c.decodeIfPresent(Bool.self, forKey: .completed) ?? false
}
}