Skip to content

Commit 35db736

Browse files
authored
Merge branch 'robch:master' into update-boxer
2 parents dc421b4 + 8831479 commit 35db736

File tree

7 files changed

+131
-4
lines changed

7 files changed

+131
-4
lines changed

src/common/CommandLine/CommandLineOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,15 @@ protected bool TryParseGlobalCommandLineOptions(string[] args, ref int i, string
355355
{
356356
this.Quiet = true;
357357
}
358-
else if (arg == "--save-alias" || arg == "--save-local-alias")
358+
else if (arg == "--save-local-alias")
359359
{
360360
var max1Arg = GetInputOptionArgs(i + 1, args, max: 1);
361361
var aliasName = max1Arg.FirstOrDefault() ?? throw new CommandLineException("Missing alias name for --save-alias");
362362
this.SaveAliasName = aliasName;
363363
this.SaveAliasScope = ConfigFileScope.Local;
364364
i += max1Arg.Count();
365365
}
366-
else if (arg == "--save-user-alias")
366+
else if (arg == "--save-alias" || arg == "--save-user-alias")
367367
{
368368
var max1Arg = GetInputOptionArgs(i + 1, args, max: 1);
369369
var aliasName = max1Arg.FirstOrDefault() ?? throw new CommandLineException("Missing alias name for --save-user-alias");

src/common/Configuration/KnownSettings.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public static class KnownSettings
1313
// Anthropic settings
1414
public const string AnthropicApiKey = "Anthropic.ApiKey";
1515
public const string AnthropicModelName = "Anthropic.ModelName";
16+
17+
// AWS Bedrock settings
18+
public const string AWSBedrockAccessKey = "AWS.Bedrock.AccessKey";
19+
public const string AWSBedrockSecretKey = "AWS.Bedrock.SecretKey";
20+
public const string AWSBedrockRegion = "AWS.Bedrock.Region";
21+
public const string AWSBedrockModelId = "AWS.Bedrock.ModelId";
1622

1723
// Azure OpenAI settings
1824
public const string AzureOpenAIApiKey = "Azure.OpenAI.ApiKey";
@@ -57,6 +63,10 @@ public static class KnownSettings
5763
// Anthropic secrets
5864
AnthropicApiKey,
5965

66+
// AWS Bedrock secrets
67+
AWSBedrockAccessKey,
68+
AWSBedrockSecretKey,
69+
6070
// Azure OpenAI secrets
6171
AzureOpenAIApiKey,
6272

@@ -79,6 +89,12 @@ public static class KnownSettings
7989
// Anthropic mappings
8090
{ AnthropicApiKey, "ANTHROPIC_API_KEY" },
8191
{ AnthropicModelName, "ANTHROPIC_MODEL_NAME" },
92+
93+
// AWS Bedrock mappings
94+
{ AWSBedrockAccessKey, "AWS_BEDROCK_ACCESS_KEY" },
95+
{ AWSBedrockSecretKey, "AWS_BEDROCK_SECRET_KEY" },
96+
{ AWSBedrockRegion, "AWS_BEDROCK_REGION" },
97+
{ AWSBedrockModelId, "AWS_BEDROCK_MODEL_ID" },
8298

8399
// Azure OpenAI mappings
84100
{ AzureOpenAIApiKey, "AZURE_OPENAI_API_KEY" },
@@ -120,6 +136,12 @@ public static class KnownSettings
120136
// Anthropic mappings
121137
{ AnthropicApiKey, "--anthropic-api-key" },
122138
{ AnthropicModelName, "--anthropic-model-name" },
139+
140+
// AWS Bedrock mappings
141+
{ AWSBedrockAccessKey, "--aws-bedrock-access-key" },
142+
{ AWSBedrockSecretKey, "--aws-bedrock-secret-key" },
143+
{ AWSBedrockRegion, "--aws-bedrock-region" },
144+
{ AWSBedrockModelId, "--aws-bedrock-model-id" },
123145

124146
// Azure OpenAI mappings
125147
{ AzureOpenAIApiKey, "--azure-openai-api-key" },
@@ -183,6 +205,17 @@ public static class KnownSettings
183205
AnthropicModelName
184206
};
185207

208+
/// <summary>
209+
/// Collection of settings for AWS Bedrock integration.
210+
/// </summary>
211+
public static readonly HashSet<string> AWSBedrockSettings = new(StringComparer.OrdinalIgnoreCase)
212+
{
213+
AWSBedrockAccessKey,
214+
AWSBedrockSecretKey,
215+
AWSBedrockRegion,
216+
AWSBedrockModelId
217+
};
218+
186219
/// <summary>
187220
/// Collection of settings for Azure OpenAI integration.
188221
/// </summary>

src/cycod/ChatClient/ChatClientFactory.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Anthropic.SDK;
22
using Anthropic.SDK.Messaging;
3+
using Amazon;
4+
using Amazon.BedrockRuntime;
35
using Azure;
46
using Azure.AI.OpenAI;
57
using Microsoft.Extensions.AI;
@@ -54,6 +56,28 @@ public static IChatClient CreateOpenAIChatClientWithApiKey()
5456
return chatClient.AsIChatClient();
5557
}
5658

59+
public static IChatClient? CreateAWSBedrockChatClient(out ChatOptions? options)
60+
{
61+
var accessKey = EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_ACCESS_KEY") ?? throw new EnvVarSettingException("AWS_BEDROCK_ACCESS_KEY is not set.");
62+
var secretKey = EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_SECRET_KEY") ?? throw new EnvVarSettingException("AWS_BEDROCK_SECRET_KEY is not set.");
63+
var region = EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_REGION") ?? "us-east-1";
64+
var modelId = EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_MODEL_ID") ?? "anthropic.claude-3-7-sonnet-20250219-v1:0";
65+
66+
var regionEndpoint = RegionEndpoint.GetBySystemName(region);
67+
var runtime = new AmazonBedrockRuntimeClient(accessKey, secretKey, regionEndpoint);
68+
var chatClient = runtime.AsIChatClient();
69+
70+
options = new ChatOptions
71+
{
72+
ModelId = modelId,
73+
ToolMode = ChatToolMode.Auto,
74+
MaxOutputTokens = 4000
75+
};
76+
77+
ConsoleHelpers.WriteDebugLine("Using AWS Bedrock API credentials for authentication");
78+
return chatClient;
79+
}
80+
5781
public static IChatClient CreateCopilotChatClientWithGitHubToken()
5882
{
5983
var model = EnvironmentHelpers.FindEnvVar("COPILOT_MODEL_NAME") ?? "claude-3.7-sonnet";
@@ -114,6 +138,12 @@ public static IChatClient CreateCopilotChatClientWithGitHubToken()
114138
{
115139
return CreateAnthropicChatClientWithApiKey(out options);
116140
}
141+
else if ((preferredProvider == "aws" || preferredProvider == "bedrock" || preferredProvider == "aws-bedrock") &&
142+
!string.IsNullOrEmpty(EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_ACCESS_KEY")) &&
143+
!string.IsNullOrEmpty(EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_SECRET_KEY")))
144+
{
145+
return CreateAWSBedrockChatClient(out options);
146+
}
117147
else if ((preferredProvider == "azure-openai" || preferredProvider == "azure") && !string.IsNullOrEmpty(EnvironmentHelpers.FindEnvVar("AZURE_OPENAI_API_KEY")))
118148
{
119149
return CreateAzureOpenAIChatClientWithApiKey();
@@ -146,6 +176,12 @@ public static IChatClient CreateCopilotChatClientWithGitHubToken()
146176
return CreateAnthropicChatClientWithApiKey(out options);
147177
}
148178

179+
if (!string.IsNullOrEmpty(EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_ACCESS_KEY")) &&
180+
!string.IsNullOrEmpty(EnvironmentHelpers.FindEnvVar("AWS_BEDROCK_SECRET_KEY")))
181+
{
182+
return CreateAWSBedrockChatClient(out options);
183+
}
184+
149185
if (!string.IsNullOrEmpty(EnvironmentHelpers.FindEnvVar("AZURE_OPENAI_API_KEY")))
150186
{
151187
return CreateAzureOpenAIChatClientWithApiKey();
@@ -178,6 +214,12 @@ public static IChatClient CreateChatClient(out ChatOptions? options)
178214
- ANTHROPIC_API_KEY
179215
- ANTHROPIC_MODEL_NAME (optional)
180216
217+
To use AWS Bedrock, please set:
218+
- AWS_BEDROCK_ACCESS_KEY
219+
- AWS_BEDROCK_SECRET_KEY
220+
- AWS_BEDROCK_REGION (optional, default: us-east-1)
221+
- AWS_BEDROCK_MODEL_ID (optional, default: anthropic.claude-3-7-sonnet-20250219-v1:0)
222+
181223
To use Azure OpenAI, please set:
182224
- AZURE_OPENAI_API_KEY
183225
- AZURE_OPENAI_ENDPOINT

src/cycod/CommandLine/CycoDevCommandLineOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ private bool TryParseChatCommandOptions(ChatCommand? command, string[] args, ref
570570
{
571571
ConfigStore.Instance.SetFromCommandLine(KnownSettings.AppPreferredProvider, "anthropic");
572572
}
573+
else if (arg == "--use-aws" || arg == "--use-bedrock" || arg == "--use-aws-bedrock")
574+
{
575+
ConfigStore.Instance.SetFromCommandLine(KnownSettings.AppPreferredProvider, "aws-bedrock");
576+
}
573577
else if (arg == "--use-azure-openai" || arg == "--use-azure")
574578
{
575579
ConfigStore.Instance.SetFromCommandLine(KnownSettings.AppPreferredProvider, "azure-openai");

src/cycod/assets/help/options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ USAGE: cycod [...]
6969
--profile NAME Load a specific profile's configuration from .cycod/profiles/NAME.yaml
7070

7171
ALIASES (see: cycod help aliases)
72-
--save-alias ALIAS Same as --save-local-alias
72+
--save-alias ALIAS Same as --save-user-alias
7373
--save-local-alias ALIAS Save current options as an alias in local scope
7474
--save-user-alias ALIAS Save current options as an alias in user scope
7575
--save-global-alias ALIAS Save current options as an alias in global scope
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
USE BEDROCK
2+
3+
AUTHENTICATION
4+
5+
EXAMPLE 1: Set AWS Bedrock credentials via config
6+
7+
cycod config set AWS.Bedrock.AccessKey ACCESS_KEY
8+
cycod config set AWS.Bedrock.AccessKey ACCESS_KEY --local
9+
cycod config set AWS.Bedrock.AccessKey ACCESS_KEY --user
10+
cycod config set AWS.Bedrock.AccessKey ACCESS_KEY --global
11+
12+
cycod config set AWS.Bedrock.SecretKey SECRET_KEY
13+
cycod config set AWS.Bedrock.SecretKey SECRET_KEY --local
14+
cycod config set AWS.Bedrock.SecretKey SECRET_KEY --user
15+
cycod config set AWS.Bedrock.SecretKey SECRET_KEY --global
16+
17+
cycod config set AWS.Bedrock.Region REGION_NAME
18+
cycod config set AWS.Bedrock.Region REGION_NAME --local
19+
cycod config set AWS.Bedrock.Region REGION_NAME --user
20+
cycod config set AWS.Bedrock.Region REGION_NAME --global
21+
22+
EXAMPLE 2: Set AWS Bedrock credentials via environment variables
23+
24+
Set AWS_BEDROCK_ACCESS_KEY environment variable
25+
Set AWS_BEDROCK_SECRET_KEY environment variable
26+
Set AWS_BEDROCK_REGION environment variable (default: us-east-1)
27+
28+
EXAMPLE 3: Supply AWS Bedrock credentials via command line
29+
30+
cycod chat --aws-bedrock-access-key ACCESS_KEY --aws-bedrock-secret-key SECRET_KEY --aws-bedrock-region REGION_NAME
31+
32+
MODEL SELECTION
33+
34+
EXAMPLE 1: Set AWS Bedrock model via config
35+
36+
cycod config set AWS.Bedrock.ModelId MODEL_ID
37+
cycod config set AWS.Bedrock.ModelId MODEL_ID --local
38+
cycod config set AWS.Bedrock.ModelId MODEL_ID --user
39+
cycod config set AWS.Bedrock.ModelId MODEL_ID --global
40+
41+
EXAMPLE 2: Set AWS Bedrock model via environment variable
42+
43+
Set AWS_BEDROCK_MODEL_ID environment variable
44+
45+
EXAMPLE 3: Supply AWS Bedrock model via command line
46+
47+
cycod chat --aws-bedrock-model-id MODEL_ID

src/cycod/cycod.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageId>CycoD</PackageId>
2020
<Authors>Rob Chambers</Authors>
2121
<Description>AI-powered CLI application for chat-based interaction with AI assistants</Description>
22-
<PackageTags>cli;ai;chat;openai;azure;github-copilot</PackageTags>
22+
<PackageTags>cli;ai;chat;openai;azure;github-copilot;aws;bedrock</PackageTags>
2323
<PackageProjectUrl>https://github.com/robch/cycod</PackageProjectUrl>
2424
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2525
<PackageReadmeFile>README.md</PackageReadmeFile>
@@ -32,6 +32,7 @@
3232

3333
<ItemGroup>
3434
<PackageReference Include="Anthropic.SDK" Version="5.4.1" />
35+
<PackageReference Include="AWSSDK.Extensions.Bedrock.MEAI" Version="4.0.1.1" />
3536
<PackageReference Include="Azure.Identity" Version="1.14.0" />
3637
<PackageReference Include="Azure.AI.OpenAI" Version="2.2.0-beta.4" />
3738
<PackageReference Include="Microsoft.Extensions.AI" Version="9.5.0" />

0 commit comments

Comments
 (0)