-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from fumito-ito/feature/examples-for-bedrock-a…
…nd-vertex add example UI for VertexAI and AWS Bedrock
- Loading branch information
Showing
16 changed files
with
792 additions
and
143 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
Example.swiftpm/.swiftpm/xcode/xcshareddata/xcschemes/Example.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1540" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Example" | ||
BuildableName = "Example" | ||
BlueprintName = "Example" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Example" | ||
BuildableName = "Example" | ||
BlueprintName = "Example" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<EnvironmentVariables> | ||
<EnvironmentVariable | ||
key = "AWS_ACCESS_KEY_ID" | ||
value = "" | ||
isEnabled = "YES"> | ||
</EnvironmentVariable> | ||
<EnvironmentVariable | ||
key = "AWS_SECRET_ACCESS_KEY" | ||
value = "" | ||
isEnabled = "YES"> | ||
</EnvironmentVariable> | ||
</EnvironmentVariables> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Example" | ||
BuildableName = "Example" | ||
BlueprintName = "Example" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,168 @@ | ||
import SwiftUI | ||
import AnthropicSwiftSDK_VertexAI | ||
import AnthropicSwiftSDK | ||
import AWSBedrockRuntime | ||
import AnthropicSwiftSDK_Bedrock | ||
|
||
struct ContentView: View { | ||
@State private var apiKey = "" | ||
// 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 { | ||
NavigationStack { | ||
VStack { | ||
Spacer() | ||
TextField("Enter API Key", text: $apiKey) | ||
.padding() | ||
.textFieldStyle(.roundedBorder) | ||
NavigationLink(destination: DemoView(observable: MessageSubject(apiKey: apiKey))) { | ||
Text("Continue") | ||
TabView { | ||
// MARK: Claude | ||
NavigationStack { | ||
VStack { | ||
Spacer() | ||
|
||
TextField("Enter API Key", text: $claudeAPIKey) | ||
.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) | ||
} | ||
} label: { | ||
Text("Continue") | ||
.frame(maxWidth: .infinity, minHeight: 48) | ||
.foregroundColor(.white) | ||
.background( | ||
Capsule() | ||
.foregroundColor(apiKey.isEmpty ? .gray.opacity(0.2) : .blue)) | ||
.foregroundColor( | ||
claudeAPIKey.isEmpty ? .gray.opacity(0.2) : .blue | ||
) | ||
) | ||
} | ||
.padding() | ||
.disabled(claudeAPIKey.isEmpty) | ||
|
||
Spacer() | ||
} | ||
.padding() | ||
.disabled(apiKey.isEmpty) | ||
Spacer() | ||
.navigationTitle("Claude Demo") | ||
} | ||
.tabItem { | ||
Image(systemName: "pencil.and.scribble") | ||
Text("Claude") | ||
} | ||
.padding() | ||
.navigationTitle("API KEY registration") | ||
|
||
// MARK: Bedrock | ||
NavigationStack { | ||
VStack { | ||
Spacer() | ||
|
||
TextField("Enter Region Code", text: $bedrockRegion) | ||
.padding() | ||
.textFieldStyle(.roundedBorder) | ||
|
||
Toggle(isOn: $isStreamBedrock) { | ||
Text("Enable Stream API") | ||
} | ||
.padding() | ||
|
||
NavigationLink { | ||
let bedrockClient = try! BedrockRuntimeClient(region: bedrockRegion) | ||
let claude = BedrockRuntimeClient.useAnthropic(bedrockClient, model: .claude_3_Opus) | ||
if isStreamBedrock { | ||
let observable = StreamViewModel(messageHandler: claude.messages, title: "Stream \\w Bedrock") | ||
StreamView(observable: observable) | ||
} else { | ||
let observable = SendViewModel(messageHandler: claude.messages, title: "Message \\w Bedrock") | ||
SendView(observable: observable) | ||
} | ||
} label: { | ||
Text("Continue") | ||
.frame(maxWidth: .infinity, minHeight: 48) | ||
.foregroundColor(.white) | ||
.background( | ||
Capsule() | ||
.foregroundColor( | ||
bedrockRegion.isEmpty ? .gray.opacity(0.2) : .blue | ||
) | ||
) | ||
} | ||
.padding() | ||
.disabled(bedrockRegion.isEmpty) | ||
|
||
Spacer() | ||
} | ||
.navigationTitle("Bedrock Demo") | ||
} | ||
.tabItem { | ||
Image(systemName: "globe.americas.fill") | ||
Text("Bedrock") | ||
} | ||
|
||
// MARK: Vertex | ||
NavigationStack { | ||
VStack { | ||
Spacer() | ||
|
||
TextField("Enter Project ID", text: $vertexProjectID) | ||
.padding() | ||
.textFieldStyle(.roundedBorder) | ||
|
||
TextField("Enter Auth Token", text: $vertexAuthToken) | ||
.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) | ||
} | ||
} label: { | ||
Text("Continue") | ||
.frame(maxWidth: .infinity, minHeight: 48) | ||
.foregroundColor(.white) | ||
.background( | ||
Capsule() | ||
.foregroundColor( | ||
vertexProjectID.isEmpty || vertexAuthToken.isEmpty ? .gray.opacity(0.2) : .blue | ||
) | ||
) | ||
} | ||
.padding() | ||
.disabled(vertexProjectID.isEmpty || vertexAuthToken.isEmpty) | ||
|
||
Spacer() | ||
} | ||
.navigationTitle("VertexAI Demo") | ||
} | ||
.tabItem { | ||
Image(systemName: "mountain.2.fill") | ||
Text("Vertex") | ||
} | ||
|
||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// ChatMessage.swift | ||
// | ||
// | ||
// Created by Fumito Ito on 2024/07/05. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ChatMessage: Identifiable { | ||
let id = UUID() | ||
let user: ChatUser | ||
let text: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ChatUser.swift | ||
// | ||
// | ||
// Created by Fumito Ito on 2024/07/05. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ChatUser: String { | ||
case user | ||
case assistant | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Messages+Extension.swift | ||
// | ||
// | ||
// Created by Fumito Ito on 2024/07/04. | ||
// | ||
|
||
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 {} |
Oops, something went wrong.