1
1
import SwiftUI
2
- import AnthropicSwiftSDK_VertexAI
3
2
import AnthropicSwiftSDK
4
- import AWSBedrockRuntime
5
- import AnthropicSwiftSDK_Bedrock
6
3
7
4
struct ContentView : View {
8
5
// MARK: Properties for Claude
9
6
@State private var claudeAPIKey = " "
10
- @State private var isStreamClaude : Bool = false
11
-
12
- // MARK: Properties for Bedrock
13
- @State private var bedrockRegion = " "
14
- @State private var isStreamBedrock : Bool = false
15
-
16
- // MARK: Properties for Vertex
17
- @State private var vertexProjectID = " "
18
- @State private var vertexAuthToken = " "
19
- @State private var isStreamVertex : Bool = false
20
7
21
8
var body : some View {
22
9
TabView {
23
- // MARK: Claude
10
+ // MARK: Claude Messages API
24
11
NavigationStack {
25
12
VStack {
26
13
Spacer ( )
@@ -29,20 +16,10 @@ struct ContentView: View {
29
16
. padding ( )
30
17
. textFieldStyle ( . roundedBorder)
31
18
32
- Toggle ( isOn: $isStreamClaude) {
33
- Text ( " Enable Stream API " )
34
- }
35
- . padding ( )
36
-
37
19
NavigationLink {
38
20
let claude = Anthropic ( apiKey: claudeAPIKey)
39
- if isStreamClaude {
40
- let observable = StreamViewModel ( messageHandler: claude. messages, title: " Stream \\ w Claude " )
41
- StreamView ( observable: observable)
42
- } else {
43
- let observable = SendViewModel ( messageHandler: claude. messages, title: " Message \\ w Claude " )
44
- SendView ( observable: observable)
45
- }
21
+ let observable = SendViewModel ( messageHandler: claude. messages, title: " Message \\ w Claude " )
22
+ SendView ( observable: observable)
46
23
} label: {
47
24
Text ( " Continue " )
48
25
. frame ( maxWidth: . infinity, minHeight: 48 )
@@ -59,108 +36,83 @@ struct ContentView: View {
59
36
60
37
Spacer ( )
61
38
}
62
- . navigationTitle ( " Claude Demo " )
39
+ . navigationTitle ( " Claude Send Message Demo " )
63
40
}
64
41
. tabItem {
65
42
Image ( systemName: " pencil.and.scribble " )
66
- Text ( " Claude " )
43
+ Text ( " Send Message " )
67
44
}
68
-
69
- // MARK: Bedrock
45
+
46
+ // MARK: Claude Stream Messages API
70
47
NavigationStack {
71
48
VStack {
72
49
Spacer ( )
73
50
74
- TextField ( " Enter Region Code " , text: $bedrockRegion )
51
+ TextField ( " Enter API Key " , text: $claudeAPIKey )
75
52
. padding ( )
76
53
. textFieldStyle ( . roundedBorder)
77
54
78
- Toggle ( isOn: $isStreamBedrock) {
79
- Text ( " Enable Stream API " )
80
- }
81
- . padding ( )
82
-
83
55
NavigationLink {
84
- let bedrockClient = try ! BedrockRuntimeClient ( region: bedrockRegion)
85
- let claude = bedrockClient. useAnthropic ( )
86
- if isStreamBedrock {
87
- let observable = StreamViewModel ( messageHandler: claude. messages, title: " Stream \\ w Bedrock " , model: . claude_3_Opus)
88
- StreamView ( observable: observable)
89
- } else {
90
- let observable = SendViewModel ( messageHandler: claude. messages, title: " Message \\ w Bedrock " , model: . claude_3_Opus)
91
- SendView ( observable: observable)
92
- }
56
+ let claude = Anthropic ( apiKey: claudeAPIKey)
57
+ let observable = StreamViewModel ( messageHandler: claude. messages, title: " Stream \\ w Claude " )
58
+ StreamView ( observable: observable)
93
59
} label: {
94
60
Text ( " Continue " )
95
61
. frame ( maxWidth: . infinity, minHeight: 48 )
96
62
. foregroundColor ( . white)
97
63
. background (
98
64
Capsule ( )
99
65
. foregroundColor (
100
- bedrockRegion . isEmpty ? . gray. opacity ( 0.2 ) : . blue
66
+ claudeAPIKey . isEmpty ? . gray. opacity ( 0.2 ) : . blue
101
67
)
102
68
)
103
69
}
104
70
. padding ( )
105
- . disabled ( bedrockRegion . isEmpty)
71
+ . disabled ( claudeAPIKey . isEmpty)
106
72
107
73
Spacer ( )
108
74
}
109
- . navigationTitle ( " Bedrock Demo" )
75
+ . navigationTitle ( " Claude Stream Message Demo" )
110
76
}
111
77
. tabItem {
112
- Image ( systemName: " globe.americas.fill " )
113
- Text ( " Bedrock " )
78
+ Image ( systemName: " pencil.and.scribble " )
79
+ Text ( " Stream Message " )
114
80
}
115
81
116
- // MARK: Vertex
82
+ // MARK: Claude Send Message Batches API
117
83
NavigationStack {
118
84
VStack {
119
85
Spacer ( )
120
86
121
- TextField ( " Enter Project ID " , text: $vertexProjectID)
122
- . padding ( )
123
- . textFieldStyle ( . roundedBorder)
124
-
125
- TextField ( " Enter Auth Token " , text: $vertexAuthToken)
87
+ TextField ( " Enter API Key " , text: $claudeAPIKey)
126
88
. padding ( )
127
89
. textFieldStyle ( . roundedBorder)
128
90
129
- Toggle ( isOn: $isStreamVertex) {
130
- Text ( " Enable Stream API " )
131
- }
132
- . padding ( )
133
-
134
91
NavigationLink {
135
- let claude = AnthropicVertexAIClient ( projectId: vertexProjectID, accessToken: vertexAuthToken, region: . europeWest1)
136
- if isStreamVertex {
137
- let observable = StreamViewModel ( messageHandler: claude. messages, title: " Stream \\ w Vertex " )
138
- StreamView ( observable: observable)
139
- } else {
140
- let observable = SendViewModel ( messageHandler: claude. messages, title: " Message \\ w Vertex " )
141
- SendView ( observable: observable)
142
- }
92
+ let claude = Anthropic ( apiKey: claudeAPIKey)
93
+ let observable = SendMessageBatchesViewModel ( messageHandler: claude. messageBatches, title: " Batch \\ w Claude " )
94
+ SendMessageBatchView ( observable: observable)
143
95
} label: {
144
96
Text ( " Continue " )
145
97
. frame ( maxWidth: . infinity, minHeight: 48 )
146
98
. foregroundColor ( . white)
147
99
. background (
148
100
Capsule ( )
149
101
. foregroundColor (
150
- vertexProjectID . isEmpty || vertexAuthToken . isEmpty ? . gray. opacity ( 0.2 ) : . blue
102
+ claudeAPIKey . isEmpty ? . gray. opacity ( 0.2 ) : . blue
151
103
)
152
104
)
153
105
}
154
106
. padding ( )
155
- . disabled ( vertexProjectID . isEmpty || vertexAuthToken . isEmpty)
107
+ . disabled ( claudeAPIKey . isEmpty)
156
108
157
109
Spacer ( )
158
110
}
159
- . navigationTitle ( " VertexAI Demo" )
111
+ . navigationTitle ( " Claude Batch Message Demo" )
160
112
}
161
113
. tabItem {
162
- Image ( systemName: " mountain.2.fill " )
163
- Text ( " Vertex " )
114
+ Image ( systemName: " pencil.and.scribble " )
115
+ Text ( " Batch Message " )
164
116
}
165
117
166
118
}
0 commit comments