Skip to content

Commit

Permalink
Better detect and message unknown CLI region (DavidSouther#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored Jun 6, 2024
1 parent df01311 commit 32ec1d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function main() {
loaded.settings
);

const isStdOut = loaded.content.at(-1) == "/dev/stdout";
switch (true) {
case args.values["update-db"]:
await generator.updateDatabase();
Expand Down Expand Up @@ -67,7 +68,7 @@ export async function main() {
LOGGER.info(`Starting ${loaded.content.length} requests`);
generator.start();

if (loaded.content.at(-1) == "/dev/stdout") {
if (isStdOut) {
loaded.content.splice(-1, 1);
const prompt = loaded.context["/dev/stdout"];
const edit = prompt.context.edit;
Expand All @@ -93,7 +94,7 @@ export async function main() {
const errors = generator
.errors()
.filter((c) => c.content.name != "/dev/stdout");
if (errors.length > 0) {
if (errors.length > 0 && !isStdOut) {
console.error(
[
"There were errors when generating responses:",
Expand Down
7 changes: 6 additions & 1 deletion core/src/engine/bedrock/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface BedrockDebug extends EngineDebug {
};
finish?: string;
error?: Error;
region?: string;
id: string;
}

Expand Down Expand Up @@ -83,6 +84,7 @@ export const generate: EngineGenerate<BedrockDebug> = (
model,
engine: "bedrock",
};
bedrock.config.region().then((region) => (debug.region = region));
const stream = new TransformStream();
const writer = stream.writable.getWriter();
const invokeModelCommand = {
Expand Down Expand Up @@ -228,7 +230,10 @@ export function formatError(content: Content) {
try {
const { message } = content.meta!.debug!.error!;
const model = content.meta!.debug!.model!;
const region = process.env["AWS_REGION"] ?? makeClient().config.region;
const region =
process.env["AWS_REGION"] ??
(content.meta?.debug as BedrockDebug | undefined)?.region ??
"unknown region";
let base = "There was an error calling Bedrock. ";
switch (message) {
case "The security token included in the request is invalid.":
Expand Down
2 changes: 1 addition & 1 deletion extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from "vscode";
import path, { basename } from "path";
import { basename } from "path";
import { generate, type ExtensionEdit } from "./generate.js";
import { LOGGER, resetLogger } from "./settings.js";
import {
Expand Down

0 comments on commit 32ec1d4

Please sign in to comment.