Skip to content

Commit b5a3704

Browse files
committed
Remove TemplateInput.Kind since it is equivalent to JSONValue
1 parent 9bb9062 commit b5a3704

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed

FirebaseAI/Sources/TemplateInput.swift

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,14 @@
1515
import Foundation
1616

1717
public struct TemplateInput: Sendable {
18-
let kind: Kind
18+
let value: JSONValue
1919

2020
public init(_ input: some TemplateInputRepresentable) {
21-
self = .init(kind: input.templateInputRepresentation.kind)
21+
self = .init(value: input.templateInputRepresentation.value)
2222
}
2323

24-
init(kind: Kind) {
25-
self.kind = kind
26-
}
27-
28-
enum Kind: Encodable, Sendable {
29-
case string(String)
30-
case int(Int)
31-
case double(Double)
32-
case bool(Bool)
33-
case array([Kind])
34-
case dictionary([String: Kind])
35-
36-
func encode(to encoder: Encoder) throws {
37-
var container = encoder.singleValueContainer()
38-
switch self {
39-
case let .string(value):
40-
try container.encode(value)
41-
case let .int(value):
42-
try container.encode(value)
43-
case let .double(value):
44-
try container.encode(value)
45-
case let .bool(value):
46-
try container.encode(value)
47-
case let .array(value):
48-
try container.encode(value)
49-
case let .dictionary(value):
50-
try container.encode(value)
51-
}
52-
}
24+
init(value: JSONValue) {
25+
self.value = value
5326
}
5427
}
5528

FirebaseAI/Sources/Types/Public/TemplateInputRepresentable.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,38 @@ public protocol TemplateInputRepresentable: Encodable, Sendable {
2020
}
2121

2222
extension String: TemplateInputRepresentable {
23-
public var templateInputRepresentation: TemplateInput { TemplateInput(kind: .string(self)) }
23+
public var templateInputRepresentation: TemplateInput { TemplateInput(value: .string(self)) }
2424
}
2525

2626
extension Int: TemplateInputRepresentable {
27-
public var templateInputRepresentation: TemplateInput { TemplateInput(kind: .int(self)) }
27+
public var templateInputRepresentation: TemplateInput {
28+
TemplateInput(value: .number(Double(self)))
29+
}
2830
}
2931

3032
extension Double: TemplateInputRepresentable {
31-
public var templateInputRepresentation: TemplateInput { TemplateInput(kind: .double(self)) }
33+
public var templateInputRepresentation: TemplateInput { TemplateInput(value: .number(self)) }
3234
}
3335

3436
extension Float: TemplateInputRepresentable {
3537
public var templateInputRepresentation: TemplateInput {
36-
TemplateInput(kind: .double(Double(self)))
38+
TemplateInput(value: .number(Double(self)))
3739
}
3840
}
3941

4042
extension Bool: TemplateInputRepresentable {
41-
public var templateInputRepresentation: TemplateInput { TemplateInput(kind: .bool(self)) }
43+
public var templateInputRepresentation: TemplateInput { TemplateInput(value: .bool(self)) }
4244
}
4345

4446
extension Array: TemplateInputRepresentable where Element: TemplateInputRepresentable {
4547
public var templateInputRepresentation: TemplateInput {
46-
TemplateInput(kind: .array(map { TemplateInput($0).kind }))
48+
TemplateInput(value: .array(map { TemplateInput($0).value }))
4749
}
4850
}
4951

5052
extension Dictionary: TemplateInputRepresentable
5153
where Key == String, Value: TemplateInputRepresentable {
5254
public var templateInputRepresentation: TemplateInput {
53-
TemplateInput(kind: .dictionary(mapValues { TemplateInput($0).kind }))
55+
TemplateInput(value: .object(mapValues { TemplateInput($0).value }))
5456
}
5557
}

0 commit comments

Comments
 (0)