Skip to content

Commit 9fbf8dc

Browse files
authored
Merge pull request #1 from FunctionCalling/feature/bump-function-calling-version
bump the dependency version
2 parents bc46b2d + 0eb6967 commit 9fbf8dc

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
],
1818
dependencies: [
1919
.package(url: "https://github.com/google-gemini/generative-ai-swift", from: "0.5.6"),
20-
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.3.0"),
20+
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.4.0"),
2121
],
2222
targets: [
2323
// Targets are the basic building blocks of a package, defining a module or a test suite.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let package = Package(
4848
)
4949
],
5050
dependencies: [
51-
.package(url: "https://github.com/FunctionCalling/FunctionCalling-GoogleGenerativeAI", from: "0.0.1")
51+
.package(url: "https://github.com/FunctionCalling/FunctionCalling-GoogleGenerativeAI", from: "0.1.0")
5252
]
5353
)
5454
```

Sources/FunctionCalling-GoogleGenerativeAI/FunctionCalling_GoogleGenerativeAI.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ typealias FunctionCallingTool = FunctionCalling.Tool
99

1010
extension ToolContainer {
1111
public var googleGenerativeAITools: [GoogleGenerativeAI.Tool] {
12-
get throws {
13-
let data = allTools.data(using: .utf8)!
14-
let functionCallingTools = try JSONDecoder().decode([FunctionCallingTool].self, from: data)
15-
let googleGenerativeAITools = functionCallingTools.map { $0.toFunctionDeclaration }
16-
17-
return [GoogleGenerativeAI.Tool(functionDeclarations: googleGenerativeAITools)]
18-
}
12+
[
13+
GoogleGenerativeAI.Tool(
14+
functionDeclarations: allTools?.compactMap { $0.toFunctionDeclaration }
15+
)
16+
]
1917
}
2018
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Extensions.swift
3+
// FunctionCalling-GoogleGenerativeAI
4+
//
5+
// Created by 伊藤史 on 2024/09/20.
6+
//
7+
8+
@testable import GoogleGenerativeAI
9+
10+
extension GoogleGenerativeAI.Tool {
11+
var functions: [FunctionDeclaration]? {
12+
self.functionDeclarations
13+
}
14+
}
15+
16+
extension GoogleGenerativeAI.FunctionDeclaration {
17+
func getName() -> String {
18+
self.name
19+
}
20+
21+
func getDescription() -> String? {
22+
self.description
23+
}
24+
}
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
import XCTest
22
@testable import FunctionCalling_GoogleGenerativeAI
3+
import FunctionCalling
34

45
final class FunctionCalling_GoogleGenerativeAITests: XCTestCase {
5-
func testExample() throws {
6-
// XCTest Documentation
7-
// https://developer.apple.com/documentation/xctest
6+
@FunctionCalling(service: .claude)
7+
struct FunctionContainer {
8+
/// Return current weather of location that passed by the argument
9+
/// - Parameter location: location that I want to know how the weather
10+
/// - Returns: string of weather
11+
@CallableFunction
12+
func getWeather(location: String) -> String {
13+
return "Sunny"
14+
}
815

9-
// Defining Test Cases and Test Methods
10-
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
16+
@CallableFunction
17+
func getStock(args: String) -> Int {
18+
return 0
19+
}
20+
}
21+
22+
func testConvertedResults() throws {
23+
guard let functions = FunctionContainer().googleGenerativeAITools.first?.functions else {
24+
XCTFail("Conainer should contain some functions")
25+
return
26+
}
27+
28+
XCTAssertEqual(functions.count, 2)
29+
30+
let getWeather = try XCTUnwrap(functions.first)
31+
XCTAssertEqual(getWeather.getName(), "getWeather")
32+
XCTAssertEqual(getWeather.getDescription(), "Return current weather of location that passed by the argument- Parameter location: location that I want to know how the weather- Returns: string of weather")
33+
34+
let getStock = try XCTUnwrap(functions.last)
35+
XCTAssertEqual(getStock.getName(), "getStock")
36+
XCTAssertEqual(getStock.getDescription(), "")
1137
}
1238
}

0 commit comments

Comments
 (0)