Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
workspace,
WorkspaceFolder,
} from "vscode";
import { RequestError } from "@octokit/request-error";
import {
AbstractWebview,
WebviewPanelConfig,
Expand Down Expand Up @@ -39,7 +40,7 @@ import { createDataExtensionYaml, loadDataExtensionYaml } from "./yaml";
import { ExternalApiUsage } from "./external-api-usage";
import { ModeledMethod } from "./modeled-method";
import { ExtensionPackModelFile } from "./shared/extension-pack";
import { autoModel } from "./auto-model-api";
import { autoModel, ModelRequest, ModelResponse } from "./auto-model-api";
import {
createAutoModelRequest,
parsePredictedClassifications,
Expand Down Expand Up @@ -421,7 +422,10 @@ export class DataExtensionsEditorView extends AbstractWebview<
message: "Sending request",
});

const response = await autoModel(this.app.credentials, request);
const response = await this.callAutoModelApi(request);
if (!response) {
return;
}

await this.showProgress({
step: 2500,
Expand Down Expand Up @@ -479,4 +483,23 @@ export class DataExtensionsEditorView extends AbstractWebview<
message: "",
});
}

private async callAutoModelApi(
request: ModelRequest,
): Promise<ModelResponse | null> {
try {
return await autoModel(this.app.credentials, request);
} catch (e) {
await this.clearProgress();

if (e instanceof RequestError && e.status === 429) {
void showAndLogExceptionWithTelemetry(
redactableError(e)`Rate limit hit, please try again soon.`,
);
return null;
} else {
throw e;
}
}
}
}