Skip to content

Commit 3c485cc

Browse files
authored
feat: AWS Bedrock support (#44)
* feat: AWS Bedrock support Signed-off-by: Danny Kopping <danny@coder.com> * tests & refactoring Signed-off-by: Danny Kopping <danny@coder.com> * validation Signed-off-by: Danny Kopping <danny@coder.com> --------- Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 70248cc commit 3c485cc

10 files changed

+505
-46
lines changed

anthropic_internal_test.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aibridge
22

33
import (
4+
"context"
45
"encoding/json"
56
"testing"
67

@@ -184,6 +185,114 @@ func TestShouldConvertContentField(t *testing.T) {
184185
}
185186
}
186187

188+
func TestAWSBedrockValidation(t *testing.T) {
189+
t.Parallel()
190+
191+
tests := []struct {
192+
name string
193+
cfg *AWSBedrockConfig
194+
expectError bool
195+
errorMsg string
196+
}{
197+
{
198+
name: "valid",
199+
cfg: &AWSBedrockConfig{
200+
Region: "us-east-1",
201+
AccessKey: "test-key",
202+
AccessKeySecret: "test-secret",
203+
Model: "test-model",
204+
SmallFastModel: "test-small-model",
205+
},
206+
},
207+
{
208+
name: "missing region",
209+
cfg: &AWSBedrockConfig{
210+
Region: "",
211+
AccessKey: "test-key",
212+
AccessKeySecret: "test-secret",
213+
Model: "test-model",
214+
SmallFastModel: "test-small-model",
215+
},
216+
expectError: true,
217+
errorMsg: "region required",
218+
},
219+
{
220+
name: "missing access key",
221+
cfg: &AWSBedrockConfig{
222+
Region: "us-east-1",
223+
AccessKey: "",
224+
AccessKeySecret: "test-secret",
225+
Model: "test-model",
226+
SmallFastModel: "test-small-model",
227+
},
228+
expectError: true,
229+
errorMsg: "access key required",
230+
},
231+
{
232+
name: "missing access key secret",
233+
cfg: &AWSBedrockConfig{
234+
Region: "us-east-1",
235+
AccessKey: "test-key",
236+
AccessKeySecret: "",
237+
Model: "test-model",
238+
SmallFastModel: "test-small-model",
239+
},
240+
expectError: true,
241+
errorMsg: "access key secret required",
242+
},
243+
{
244+
name: "missing model",
245+
cfg: &AWSBedrockConfig{
246+
Region: "us-east-1",
247+
AccessKey: "test-key",
248+
AccessKeySecret: "test-secret",
249+
Model: "",
250+
SmallFastModel: "test-small-model",
251+
},
252+
expectError: true,
253+
errorMsg: "model required",
254+
},
255+
{
256+
name: "missing small fast model",
257+
cfg: &AWSBedrockConfig{
258+
Region: "us-east-1",
259+
AccessKey: "test-key",
260+
AccessKeySecret: "test-secret",
261+
Model: "test-model",
262+
SmallFastModel: "",
263+
},
264+
expectError: true,
265+
errorMsg: "small fast model required",
266+
},
267+
{
268+
name: "all fields empty",
269+
cfg: &AWSBedrockConfig{},
270+
expectError: true,
271+
errorMsg: "region required",
272+
},
273+
{
274+
name: "nil config",
275+
cfg: nil,
276+
expectError: true,
277+
errorMsg: "nil config given",
278+
},
279+
}
280+
281+
for _, tt := range tests {
282+
t.Run(tt.name, func(t *testing.T) {
283+
base := &AnthropicMessagesInterceptionBase{}
284+
_, err := base.withAWSBedrock(context.Background(), tt.cfg)
285+
286+
if tt.expectError {
287+
require.Error(t, err)
288+
require.Contains(t, err.Error(), tt.errorMsg)
289+
} else {
290+
require.NoError(t, err)
291+
}
292+
})
293+
}
294+
}
295+
187296
func TestAccumulateUsage(t *testing.T) {
188297
t.Run("Usage to Usage", func(t *testing.T) {
189298
dest := &anthropic.Usage{

0 commit comments

Comments
 (0)