Skip to content

Commit

Permalink
Merge pull request #53 from fumito-ito/feature/batches
Browse files Browse the repository at this point in the history
Message Batches API
  • Loading branch information
fumito-ito authored Oct 26, 2024
2 parents 34fb991 + 2069387 commit 1e00305
Show file tree
Hide file tree
Showing 51 changed files with 2,136 additions and 412 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
build:

runs-on: macos-14
runs-on: macos-15

steps:
- uses: actions/checkout@v4
Expand Down
86 changes: 0 additions & 86 deletions .swiftpm/configuration/Package.resolved

This file was deleted.

100 changes: 26 additions & 74 deletions Example.swiftpm/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import SwiftUI
import AnthropicSwiftSDK_VertexAI
import AnthropicSwiftSDK
import AWSBedrockRuntime
import AnthropicSwiftSDK_Bedrock

struct ContentView: View {
// MARK: Properties for Claude
@State private var claudeAPIKey = ""
@State private var isStreamClaude: Bool = false

// MARK: Properties for Bedrock
@State private var bedrockRegion = ""
@State private var isStreamBedrock: Bool = false

// MARK: Properties for Vertex
@State private var vertexProjectID = ""
@State private var vertexAuthToken = ""
@State private var isStreamVertex: Bool = false

var body: some View {
TabView {
// MARK: Claude
// MARK: Claude Messages API
NavigationStack {
VStack {
Spacer()
Expand All @@ -29,20 +16,10 @@ struct ContentView: View {
.padding()
.textFieldStyle(.roundedBorder)

Toggle(isOn: $isStreamClaude) {
Text("Enable Stream API")
}
.padding()

NavigationLink {
let claude = Anthropic(apiKey: claudeAPIKey)
if isStreamClaude {
let observable = StreamViewModel(messageHandler: claude.messages, title: "Stream \\w Claude")
StreamView(observable: observable)
} else {
let observable = SendViewModel(messageHandler: claude.messages, title: "Message \\w Claude")
SendView(observable: observable)
}
let observable = SendViewModel(messageHandler: claude.messages, title: "Message \\w Claude")
SendView(observable: observable)
} label: {
Text("Continue")
.frame(maxWidth: .infinity, minHeight: 48)
Expand All @@ -59,108 +36,83 @@ struct ContentView: View {

Spacer()
}
.navigationTitle("Claude Demo")
.navigationTitle("Claude Send Message Demo")
}
.tabItem {
Image(systemName: "pencil.and.scribble")
Text("Claude")
Text("Send Message")
}

// MARK: Bedrock
// MARK: Claude Stream Messages API
NavigationStack {
VStack {
Spacer()

TextField("Enter Region Code", text: $bedrockRegion)
TextField("Enter API Key", text: $claudeAPIKey)
.padding()
.textFieldStyle(.roundedBorder)

Toggle(isOn: $isStreamBedrock) {
Text("Enable Stream API")
}
.padding()

NavigationLink {
let bedrockClient = try! BedrockRuntimeClient(region: bedrockRegion)
let claude = bedrockClient.useAnthropic()
if isStreamBedrock {
let observable = StreamViewModel(messageHandler: claude.messages, title: "Stream \\w Bedrock", model: .claude_3_Opus)
StreamView(observable: observable)
} else {
let observable = SendViewModel(messageHandler: claude.messages, title: "Message \\w Bedrock", model: .claude_3_Opus)
SendView(observable: observable)
}
let claude = Anthropic(apiKey: claudeAPIKey)
let observable = StreamViewModel(messageHandler: claude.messages, title: "Stream \\w Claude")
StreamView(observable: observable)
} label: {
Text("Continue")
.frame(maxWidth: .infinity, minHeight: 48)
.foregroundColor(.white)
.background(
Capsule()
.foregroundColor(
bedrockRegion.isEmpty ? .gray.opacity(0.2) : .blue
claudeAPIKey.isEmpty ? .gray.opacity(0.2) : .blue
)
)
}
.padding()
.disabled(bedrockRegion.isEmpty)
.disabled(claudeAPIKey.isEmpty)

Spacer()
}
.navigationTitle("Bedrock Demo")
.navigationTitle("Claude Stream Message Demo")
}
.tabItem {
Image(systemName: "globe.americas.fill")
Text("Bedrock")
Image(systemName: "pencil.and.scribble")
Text("Stream Message")
}

// MARK: Vertex
// MARK: Claude Send Message Batches API
NavigationStack {
VStack {
Spacer()

TextField("Enter Project ID", text: $vertexProjectID)
.padding()
.textFieldStyle(.roundedBorder)

TextField("Enter Auth Token", text: $vertexAuthToken)
TextField("Enter API Key", text: $claudeAPIKey)
.padding()
.textFieldStyle(.roundedBorder)

Toggle(isOn: $isStreamVertex) {
Text("Enable Stream API")
}
.padding()

NavigationLink {
let claude = AnthropicVertexAIClient(projectId: vertexProjectID, accessToken: vertexAuthToken, region: .europeWest1)
if isStreamVertex {
let observable = StreamViewModel(messageHandler: claude.messages, title: "Stream \\w Vertex")
StreamView(observable: observable)
} else {
let observable = SendViewModel(messageHandler: claude.messages, title: "Message \\w Vertex")
SendView(observable: observable)
}
let claude = Anthropic(apiKey: claudeAPIKey)
let observable = SendMessageBatchesViewModel(messageHandler: claude.messageBatches, title: "Batch \\w Claude")
SendMessageBatchView(observable: observable)
} label: {
Text("Continue")
.frame(maxWidth: .infinity, minHeight: 48)
.foregroundColor(.white)
.background(
Capsule()
.foregroundColor(
vertexProjectID.isEmpty || vertexAuthToken.isEmpty ? .gray.opacity(0.2) : .blue
claudeAPIKey.isEmpty ? .gray.opacity(0.2) : .blue
)
)
}
.padding()
.disabled(vertexProjectID.isEmpty || vertexAuthToken.isEmpty)
.disabled(claudeAPIKey.isEmpty)

Spacer()
}
.navigationTitle("VertexAI Demo")
.navigationTitle("Claude Batch Message Demo")
}
.tabItem {
Image(systemName: "mountain.2.fill")
Text("Vertex")
Image(systemName: "pencil.and.scribble")
Text("Batch Message")
}

}
Expand Down
7 changes: 1 addition & 6 deletions Example.swiftpm/Extension/Messages+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

import Foundation
import AnthropicSwiftSDK
import AnthropicSwiftSDK_Bedrock
import AnthropicSwiftSDK_VertexAI

extension AnthropicSwiftSDK.Messages: MessageSendable {}
extension AnthropicSwiftSDK.Messages: MessageStreamable {}
extension AnthropicSwiftSDK_Bedrock.Messages: MessageSendable {}
extension AnthropicSwiftSDK_Bedrock.Messages: MessageStreamable {}
extension AnthropicSwiftSDK_VertexAI.Messages: MessageSendable {}
extension AnthropicSwiftSDK_VertexAI.Messages: MessageStreamable {}
extension AnthropicSwiftSDK.MessageBatches: MessageBatchSendable {}
45 changes: 9 additions & 36 deletions Example.swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
{
"pins" : [
{
"identity" : "aws-crt-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-crt-swift",
"state" : {
"revision" : "7b42e0343f28b3451aab20840dc670abd12790bd",
"version" : "0.36.0"
}
},
{
"identity" : "aws-sdk-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-sdk-swift",
"state" : {
"revision" : "192bc5984cb765a88f8a59d0678aeb85a888a9f5",
"version" : "1.0.8"
}
},
{
"identity" : "documentationcomment",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -45,15 +27,6 @@
"version" : "5.0.1"
}
},
{
"identity" : "smithy-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/smithy-lang/smithy-swift",
"state" : {
"revision" : "c5242d4e06e721293ee91c7affd1d527912f596d",
"version" : "0.76.0"
}
},
{
"identity" : "swift-cmark",
"kind" : "remoteSourceControl",
Expand All @@ -63,15 +36,6 @@
"version" : "0.4.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
},
{
"identity" : "swift-markdown",
"kind" : "remoteSourceControl",
Expand All @@ -89,6 +53,15 @@
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "swiftyjsonlines",
"kind" : "remoteSourceControl",
"location" : "https://github.com/fumito-ito/SwiftyJSONLines.git",
"state" : {
"revision" : "ae30455420897b2c45621a88b3ae3f052a8b5f3d",
"version" : "0.0.2"
}
}
],
"version" : 2
Expand Down
6 changes: 2 additions & 4 deletions Example.swiftpm/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
name: "Example",
targets: ["AppModule"],
bundleIdentifier: "com.github.fumito-ito.AnthropicSwiftSDK.Example",
teamIdentifier: "L8LPZ499U7",
teamIdentifier: "K489QY5CFD",
displayVersion: "1.0",
bundleVersion: "1",
appIcon: .placeholder(icon: .clock),
Expand All @@ -44,9 +44,7 @@ let package = Package(
.executableTarget(
name: "AppModule",
dependencies: [
.product(name: "AnthropicSwiftSDK", package: "AnthropicSwiftSDK"),
.product(name: "AnthropicSwiftSDK-Bedrock", package: "AnthropicSwiftSDK"),
.product(name: "AnthropicSwiftSDK-VertexAI", package: "AnthropicSwiftSDK")
.product(name: "AnthropicSwiftSDK", package: "AnthropicSwiftSDK")
],
path: "."
)
Expand Down
Loading

0 comments on commit 1e00305

Please sign in to comment.