Skip to content

Commit ed5543f

Browse files
committed
accept updates
1 parent d4ff8ad commit ed5543f

File tree

4 files changed

+72
-31
lines changed

4 files changed

+72
-31
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let package = Package(
2626
name: "FunctionCalling-FirebaseVertexAI",
2727
dependencies: [
2828
.product(name: "FunctionCalling", package: "FunctionCalling"),
29-
.product(name: "FirebaseVertexAI-Preview", package: "firebase-ios-sdk")
29+
.product(name: "FirebaseVertexAI", package: "firebase-ios-sdk")
3030
]
3131
),
3232
.testTarget(

Sources/FunctionCalling-FirebaseVertexAI/Extension/InputSchema+Extension.swift

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,68 @@ import FirebaseVertexAI
1010

1111
extension FunctionCalling.InputSchema {
1212
var toSchema: FirebaseVertexAI.Schema {
13-
Schema(
14-
type: type.toDataType,
15-
format: format,
16-
description: description,
17-
nullable: nullable,
18-
enumValues: enumValues,
19-
items: items?.toSchema,
20-
properties: properties?.mapValues { $0.toSchema },
21-
requiredProperties: requiredProperties
22-
)
23-
}
24-
}
25-
26-
extension FunctionCalling.InputSchema.DataType {
27-
var toDataType: FirebaseVertexAI.DataType {
28-
switch self {
13+
switch type {
2914
case .string:
30-
return .string
15+
return .string(
16+
description: description,
17+
nullable: nullable ?? false,
18+
format: format.toStringFormat
19+
)
3120
case .number:
32-
return .number
21+
return .double(
22+
description: description,
23+
nullable: nullable ?? false
24+
)
3325
case .integer:
34-
return .integer
26+
return .integer(
27+
description: description,
28+
nullable: nullable ?? false,
29+
format: format.toIntegerFormat
30+
)
3531
case .boolean:
36-
return .boolean
32+
return .boolean(
33+
description: description,
34+
nullable: nullable ?? false
35+
)
3736
case .array:
38-
return .array
37+
guard let items else {
38+
fatalError("array is set but items are not found")
39+
}
40+
41+
return .array(
42+
items: items.toSchema,
43+
description: description,
44+
nullable: nullable ?? false
45+
)
3946
case .object:
40-
return .object
47+
guard let properties else {
48+
fatalError("object is set but properties are note found")
49+
}
50+
51+
return .object(
52+
properties: properties.mapValues { $0.toSchema },
53+
optionalProperties: [],
54+
description: description,
55+
nullable: nullable ?? false
56+
)
57+
}
58+
}
59+
}
60+
61+
extension Optional<String> {
62+
var toStringFormat: FirebaseVertexAI.Schema.StringFormat? {
63+
guard let format = self else {
64+
return nil
4165
}
66+
67+
return .custom(format)
68+
}
69+
70+
var toIntegerFormat: FirebaseVertexAI.Schema.IntegerFormat? {
71+
guard let format = self else {
72+
return nil
73+
}
74+
75+
return .custom(format)
4276
}
4377
}

Sources/FunctionCalling-FirebaseVertexAI/Extension/Tool+Extension.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ import FirebaseVertexAI
1010

1111
extension FunctionCalling.Tool {
1212
var toFunctionDeclaration: FirebaseVertexAI.FunctionDeclaration {
13-
FunctionDeclaration(
13+
let parameters: [String: FirebaseVertexAI.Schema] = {
14+
guard let properties = inputSchema.properties else {
15+
return [:]
16+
}
17+
18+
return properties.mapValues { $0.toSchema }
19+
}()
20+
21+
return FunctionDeclaration(
1422
name: name,
1523
description: description,
16-
parameters: inputSchema.properties?.mapValues { $0.toSchema },
17-
requiredParameters: inputSchema.requiredProperties
24+
parameters: parameters
1825
)
1926
}
2027
}

Sources/FunctionCalling-FirebaseVertexAI/FunctionCalling_FirebaseVertexAI.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import Foundation
1111

1212
extension ToolContainer {
1313
public var firebaseVertexAITools: [FirebaseVertexAI.Tool] {
14-
[
15-
FirebaseVertexAI.Tool(
16-
functionDeclarations: allTools?.compactMap { $0.toFunctionDeclaration }
17-
)
18-
]
14+
guard let declarations = allTools?.compactMap({ $0.toFunctionDeclaration }) else {
15+
return [.functionDeclarations([])]
16+
}
17+
18+
return [FirebaseVertexAI.Tool.functionDeclarations(declarations)]
1919
}
2020
}

0 commit comments

Comments
 (0)