fix error parsing

This commit is contained in:
Brian Hackett 2025-03-06 08:28:08 -08:00
parent 72fa945dc2
commit f3f1cc12c8

View File

@ -58,14 +58,19 @@ export interface AnthropicCall {
} }
function maybeParseAnthropicErrorPromptTooLong(e: any) { function maybeParseAnthropicErrorPromptTooLong(e: any) {
if (e?.error?.type === "invalid_request_error") { try {
const match = /prompt is too long: (\d+) tokens > (\d+) maximum/.exec(e?.error?.message); const { type, message } = e.error.error;
if (type === "invalid_request_error") {
const match = /prompt is too long: (\d+) tokens > (\d+) maximum/.exec(message);
if (match) { if (match) {
const tokens = +match[1]; const tokens = +match[1];
const maximum = +match[2]; const maximum = +match[2];
return { tokens, maximum }; return { tokens, maximum };
} }
} }
} catch (e) {
console.log("AnthropicParseError", e);
}
return undefined; return undefined;
} }