Skip to content

Commit 46447ca

Browse files
authored
Merge branch 'main' into feature/lint
2 parents 93a586f + b510b88 commit 46447ca

5 files changed

Lines changed: 79 additions & 19 deletions

File tree

Package.resolved

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ let package = Package(
1717
)
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/FunctionCalling/FunctionCalling", from: "0.3.0"),
21-
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.77.1")
20+
.package(url: "https://github.com/FunctionCalling/FunctionCalling", from: "0.5.0"),
21+
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.36")
2222
],
2323
targets: [
2424
// Targets are the basic building blocks of a package, defining a module or a test suite.

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
# FunctionCalling-AWSBedrock
2-
Easy to use your Swift native functions for function calling with [AWSBedrock](https://github.com/awslabs/aws-sdk-swift/tree/main).
2+
3+
This library simplifies the integration of the [FunctionCalling](https://github.com/fumito-ito/FunctionCalling) macro into [AWSBedrock](https://github.com/awslabs/aws-sdk-swift). By using this library, you can directly generate `Tool` objects from Swift native functions, which can then be specified as FunctionCalling when invoking Bedrock.
4+
5+
## Usage
6+
7+
```swift
8+
9+
import FunctionCalling
10+
import FunctionCalling_AWSBedrock
11+
import AWSBedrockRuntime
12+
13+
// MARK: Declare the container and functions for the tools to be called from FunctionCalling.
14+
15+
@FunctionCalling(service: .claude)
16+
struct MyFunctionTools {
17+
@CallableFunction
18+
/// Get the current stock price for a given ticker symbol
19+
///
20+
/// - Parameter: The stock ticker symbol, e.g. AMZN for Google Inc.
21+
func getStockPrice(ticker: String) async throws -> String {
22+
// code to return stock price of passed ticker
23+
}
24+
}
25+
26+
// MARK: You can directly pass the tools generated from objects to the model in Bedrock.
27+
28+
let client = try BedrockRuntimeClient(region: "us-east-1")
29+
let input = ConverseInput(toolConfig: .init(tools: MyFunctionTools().bedrockAllTools))
30+
try await client.converse(input: input)
31+
```
32+
33+
## Installation
34+
35+
### Swift Package Manager
36+
37+
```
38+
let package = Package(
39+
name: "MyPackage",
40+
products: [...],
41+
targets: [
42+
.target(
43+
"YouAppModule",
44+
dependencies: [
45+
.product(name: "FunctionCalling-AWSBedrock", package: "FunctionCalling-AWSBedrock")
46+
]
47+
)
48+
],
49+
dependencies: [
50+
.package(url: "https://github.com/FunctionCalling/FunctionCalling-AWSBedrock", from: "0.1.0")
51+
]
52+
)
53+
```
54+
55+
## Contributing
56+
57+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.Please make sure to update tests as appropriate.
58+
59+
## License
60+
61+
The MIT License

Sources/FunctionCalling-AWSBedrock/FunctionCalling-AWSBedrock.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ import FunctionCalling
55
import AWSBedrockRuntime
66
import Foundation
77

8-
let decoder: JSONDecoder = {
9-
let decoder = JSONDecoder()
10-
decoder.keyDecodingStrategy = .convertFromSnakeCase
11-
12-
return decoder
13-
}()
14-
158
extension ToolContainer {
169
typealias FunctionCallingTool = FunctionCalling.Tool
1710

1811
public var bedrockAllTools: [BedrockRuntimeClientTypes.Tool] {
1912
get throws {
20-
let data = allTools.replacingOccurrences(of: "\n", with: "").data(using: .utf8)!
21-
let functionCallingTools = try decoder.decode([FunctionCallingTool].self, from: data)
13+
guard let functionCallingTools = allTools else {
14+
return []
15+
}
16+
2217
return try functionCallingTools.map { try $0.toBedrockTool }
2318
}
2419
}

renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:recommended"
5+
]
6+
}

0 commit comments

Comments
 (0)