fixes bad handleCompatibilityRequest middleware fallthrough
This commit is contained in:
parent
03c5c473e1
commit
434445797a
|
@ -259,6 +259,22 @@ anthropicRouter.post(
|
||||||
}),
|
}),
|
||||||
anthropicProxy
|
anthropicProxy
|
||||||
);
|
);
|
||||||
|
// This is not a valid route but clients may attempt to use it.
|
||||||
|
anthropicRouter.post("/v1/claude-3/messages", (req, res) => {
|
||||||
|
sendErrorToClient({
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
options: {
|
||||||
|
title: "Proxy error (wrong endpoint)",
|
||||||
|
message:
|
||||||
|
"Your client is attempting to use the /anthropic/claude-3 compatibility endpoint, but it supports the new API format.\n\nUse the normal /anthropic endpoint instead.",
|
||||||
|
format: "unknown",
|
||||||
|
statusCode: 404,
|
||||||
|
reqId: req.id,
|
||||||
|
obj: { original_url: req.originalUrl, router_url: req.url },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
export function handleCompatibilityRequest(
|
export function handleCompatibilityRequest(
|
||||||
req: Request,
|
req: Request,
|
||||||
|
@ -268,7 +284,7 @@ export function handleCompatibilityRequest(
|
||||||
const alreadyInChatFormat = Boolean(req.body.messages);
|
const alreadyInChatFormat = Boolean(req.body.messages);
|
||||||
const alreadyUsingClaude3 = req.body.model?.includes("claude-3");
|
const alreadyUsingClaude3 = req.body.model?.includes("claude-3");
|
||||||
if (!alreadyInChatFormat && !alreadyUsingClaude3) {
|
if (!alreadyInChatFormat && !alreadyUsingClaude3) {
|
||||||
next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alreadyInChatFormat) {
|
if (alreadyInChatFormat) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {
|
||||||
handleCompatibilityRequest,
|
handleCompatibilityRequest,
|
||||||
transformAnthropicChatResponseToAnthropicText,
|
transformAnthropicChatResponseToAnthropicText,
|
||||||
} from "./anthropic";
|
} from "./anthropic";
|
||||||
|
import { sendErrorToClient } from "./middleware/response/error-generator";
|
||||||
|
|
||||||
const LATEST_AWS_V2_MINOR_VERSION = "1";
|
const LATEST_AWS_V2_MINOR_VERSION = "1";
|
||||||
const CLAUDE_3_COMPAT_MODEL = "anthropic.claude-3-sonnet-20240229-v1:0";
|
const CLAUDE_3_COMPAT_MODEL = "anthropic.claude-3-sonnet-20240229-v1:0";
|
||||||
|
@ -202,6 +203,22 @@ awsRouter.post(
|
||||||
),
|
),
|
||||||
awsProxy
|
awsProxy
|
||||||
);
|
);
|
||||||
|
// This is not a valid route but clients may attempt to use it.
|
||||||
|
awsRouter.post("/v1/claude-3/messages", (req, res) => {
|
||||||
|
sendErrorToClient({
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
options: {
|
||||||
|
title: "Proxy error (wrong endpoint)",
|
||||||
|
message:
|
||||||
|
"Your client is attempting to use the /anthropic/v1/claude-3 compatibility endpoint, but supports the new API format and should use the normal /anthropic/v1 endpoint instead.",
|
||||||
|
format: "unknown",
|
||||||
|
statusCode: 404,
|
||||||
|
reqId: req.id,
|
||||||
|
obj: { original_url: req.originalUrl, router_url: req.url },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
// OpenAI-to-AWS Anthropic compatibility endpoint.
|
// OpenAI-to-AWS Anthropic compatibility endpoint.
|
||||||
awsRouter.post(
|
awsRouter.post(
|
||||||
"/v1/chat/completions",
|
"/v1/chat/completions",
|
||||||
|
|
|
@ -58,8 +58,10 @@ proxyRouter.use((req, res) => {
|
||||||
reqId: req.id,
|
reqId: req.id,
|
||||||
format: "unknown",
|
format: "unknown",
|
||||||
obj: {
|
obj: {
|
||||||
proxy_note: "Your chat client is using the wrong endpoint. Please check your configuration.",
|
proxy_note:
|
||||||
requested_url: req.url,
|
"Your chat client is using the wrong endpoint. Please check your configuration.",
|
||||||
|
original_url: req.originalUrl,
|
||||||
|
router_url: req.url,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue