Skip to content

Commit 29e124c

Browse files
committed
initial commit
0 parents  commit 29e124c

6 files changed

Lines changed: 125 additions & 0 deletions

File tree

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
9+
.swiftpm

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Fumito Ito
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "FunctionCalling-AWSBedrock",
8+
platforms: [
9+
.macOS(.v13),
10+
.iOS(.v17)
11+
],
12+
products: [
13+
// Products define the executables and libraries a package produces, making them visible to other packages.
14+
.library(
15+
name: "FunctionCalling-AWSBedrock",
16+
targets: ["FunctionCalling-AWSBedrock"]),
17+
],
18+
dependencies: [
19+
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.3.0"),
20+
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.77.1"),
21+
],
22+
targets: [
23+
// Targets are the basic building blocks of a package, defining a module or a test suite.
24+
// Targets can depend on other targets in this package and products from dependencies.
25+
.target(
26+
name: "FunctionCalling-AWSBedrock",
27+
dependencies: [
28+
.product(name: "FunctionCalling", package: "FunctionCalling"),
29+
.product(name: "AWSBedrockRuntime", package: "aws-sdk-swift")
30+
]
31+
),
32+
.testTarget(
33+
name: "FunctionCalling-AWSBedrockTests",
34+
dependencies: ["FunctionCalling-AWSBedrock"]
35+
),
36+
]
37+
)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# FunctionCalling-AWSBedrock
2+
Easy to use your Swift native functions for function calling with [AWSBedrock](https://github.com/awslabs/aws-sdk-swift/tree/main).
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book
3+
4+
import FunctionCalling
5+
import AWSBedrockRuntime
6+
import Foundation
7+
import struct Smithy.Document
8+
9+
extension ToolContainer {
10+
typealias FunctionCallingTool = FunctionCalling.Tool
11+
12+
public var bedrockAllTools: [BedrockRuntimeClientTypes.Tool] {
13+
get throws {
14+
let data = allTools.data(using: .utf8)!
15+
let functionCallingTools = try JSONDecoder().decode([FunctionCallingTool].self, from: data)
16+
return try functionCallingTools.map { try $0.toBedrockTool }
17+
}
18+
}
19+
}
20+
21+
extension FunctionCalling.Tool {
22+
var toBedrockTool: BedrockRuntimeClientTypes.Tool {
23+
get throws {
24+
.toolspec(try .init(from: self))
25+
}
26+
}
27+
}
28+
29+
extension BedrockRuntimeClientTypes.ToolSpecification {
30+
init(from tool: FunctionCalling.Tool) throws {
31+
self.init(
32+
description: tool.description,
33+
inputSchema: try .init(from: tool.inputSchema),
34+
name: tool.name
35+
)
36+
}
37+
}
38+
39+
extension BedrockRuntimeClientTypes.ToolInputSchema {
40+
init(from schema: FunctionCalling.InputSchema) throws {
41+
self = .json(try .init(from: schema))
42+
}
43+
}
44+
45+
extension Smithy.Document {
46+
init(from schema: FunctionCalling.InputSchema) throws {
47+
let data = try JSONEncoder().encode(schema)
48+
self = try Self.make(from: data)
49+
}
50+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Testing
2+
@testable import MyLibrary
3+
4+
@Test func example() async throws {
5+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
6+
}

0 commit comments

Comments
 (0)