Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fumito-ito/anthropicswiftsdk-bedrock
The Bedrock extension for AnthropicSwiftSDK a.k.a. Anthropic Claude API client for Swift.
https://github.com/fumito-ito/anthropicswiftsdk-bedrock
Last synced: 3 days ago
JSON representation
The Bedrock extension for AnthropicSwiftSDK a.k.a. Anthropic Claude API client for Swift.
- Host: GitHub
- URL: https://github.com/fumito-ito/anthropicswiftsdk-bedrock
- Owner: fumito-ito
- License: apache-2.0
- Created: 2024-10-02T03:05:19.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-12-20T21:42:16.000Z (12 days ago)
- Last Synced: 2024-12-22T03:12:30.422Z (10 days ago)
- Language: Swift
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Anthropic Swift SDK Bedrock Extension
[Anthropic API Swift SDK](https://github.com/fumito-ito/AnthropicSwiftSDK) Extension for [Amazon Web Services Bedrock](https://aws.amazon.com/bedrock/).
## Installation
### Swift Package Manager
Just add to your Package.swift under dependencies
```swift
let package = Package(
name: "MyPackage",
products: [...],
targets: [
.target(
"YouAppModule",
dependencies: [
.product(name: "AnthropicSwiftSDK", package: "AnthropicSwiftSDK"),
.product(name: "AnthropicSwiftSDK-Bedrock", package: "AnthropicSwiftSDK-Bedrock")
]
)
],
dependencies: [
.package(url: "https://github.com/fumito-ito/AnthropicSwiftSDK.git", from: "0.6.0"),
.package(url: "https://github.com/fumito-ito/AnthropicSwiftSDK-Bedrock.git", from: "0.0.1")
]
)
```## Usage
To create an `AnthropicBedrockClient` from a `BedrockRuntimeClient` with a `Model` to access Claude on Bedrock.
The API usage is the same as the normal AnthropicClient.```swift
import AnthropicSwiftSDK_Bedrock
import AnthropicSwiftSDK
import AWSBedrockRuntimelet client = try BedrockRuntimeClient(region: "us-west-2")
let anthropic = client.useAnthropic()let response = try await anthropic.messages.createMessage(Message(role: .user, content: [.text("This is test text")]), maxTokens: 1024)
for content in response.content {
switch content {
case .text(let text):
print(text)
case .image(let imageContent):
// handle base64 encoded image content
}
}
```Also `Streaming Message API` works in the same way.
```swift
import AnthropicSwiftSDK_Bedrock
import AnthropicSwiftSDK
import AWSBedrockRuntimelet client = try BedrockRuntimeClient(region: "us-west-2")
let anthropic = client.useAnthropic()let stream = try await anthropic.messages.streamMessage([Message(role: .user, content: [.text("This is test text")])], maxTokens: 1024)
for try await chunk in stream {
switch chunk.type {
case .messageStart:
// handle message start object with casting chunk into `StreamingMessageStartResponse`
}
}
```## Contributing
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.
## License
[Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/)