Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/google-gemini/generative-ai-swift", from: "0.5.6"),
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.3.0"),
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.4.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/FunctionCalling/FunctionCalling-GoogleGenerativeAI", from: "0.0.1")
.package(url: "https://github.com/FunctionCalling/FunctionCalling-GoogleGenerativeAI", from: "0.1.0")
]
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ typealias FunctionCallingTool = FunctionCalling.Tool

extension ToolContainer {
public var googleGenerativeAITools: [GoogleGenerativeAI.Tool] {
get throws {
let data = allTools.data(using: .utf8)!
let functionCallingTools = try JSONDecoder().decode([FunctionCallingTool].self, from: data)
let googleGenerativeAITools = functionCallingTools.map { $0.toFunctionDeclaration }

return [GoogleGenerativeAI.Tool(functionDeclarations: googleGenerativeAITools)]
}
[
GoogleGenerativeAI.Tool(
functionDeclarations: allTools?.compactMap { $0.toFunctionDeclaration }
)
]
}
}
24 changes: 24 additions & 0 deletions Tests/FunctionCalling-GoogleGenerativeAITests/Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Extensions.swift
// FunctionCalling-GoogleGenerativeAI
//
// Created by 伊藤史 on 2024/09/20.
//

@testable import GoogleGenerativeAI

extension GoogleGenerativeAI.Tool {
var functions: [FunctionDeclaration]? {
self.functionDeclarations
}
}

extension GoogleGenerativeAI.FunctionDeclaration {
func getName() -> String {
self.name
}

func getDescription() -> String? {
self.description
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import XCTest
@testable import FunctionCalling_GoogleGenerativeAI
import FunctionCalling

final class FunctionCalling_GoogleGenerativeAITests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest
@FunctionCalling(service: .claude)
struct FunctionContainer {
/// 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
@CallableFunction
func getWeather(location: String) -> String {
return "Sunny"
}

// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
@CallableFunction
func getStock(args: String) -> Int {
return 0
}
}

func testConvertedResults() throws {
guard let functions = FunctionContainer().googleGenerativeAITools.first?.functions else {
XCTFail("Conainer should contain some functions")
return
}

XCTAssertEqual(functions.count, 2)

let getWeather = try XCTUnwrap(functions.first)
XCTAssertEqual(getWeather.getName(), "getWeather")
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")

let getStock = try XCTUnwrap(functions.last)
XCTAssertEqual(getStock.getName(), "getStock")
XCTAssertEqual(getStock.getDescription(), "")
}
}