enables opus by default

This commit is contained in:
nai-degen 2024-03-04 21:11:32 -06:00
parent 6b22d17c50
commit 736803ad92
3 changed files with 27 additions and 1 deletions

View File

@ -297,6 +297,7 @@ export const config: Config = {
"gpt4-32k",
"gpt4-turbo",
"claude",
"claude-opus",
"gemini-pro",
"mistral-tiny",
"mistral-small",

View File

@ -16,6 +16,7 @@ import {
ProxyResHandlerWithBody,
createOnProxyResHandler,
} from "./middleware/response";
import { HttpError } from "../shared/errors";
const CLAUDE_3_COMPAT_MODEL =
process.env.CLAUDE_3_COMPAT_MODEL || "claude-3-sonnet-20240229";
@ -249,6 +250,7 @@ anthropicRouter.post(
anthropicRouter.post(
"/v1/claude-3/complete",
ipLimiter,
handleCompatibilityRequest,
createPreprocessorMiddleware(
{ inApi: "anthropic-text", outApi: "anthropic-chat", service: "anthropic" },
{
@ -258,6 +260,28 @@ anthropicRouter.post(
anthropicProxy
);
export function handleCompatibilityRequest(req: Request, res: any, next: any) {
const alreadyInChatFormat = Boolean(req.body.messages);
const alreadyUsingClaude3 = req.body.model?.includes("claude-3");
if (!alreadyInChatFormat && !alreadyUsingClaude3) {
next();
}
if (alreadyInChatFormat) {
throw new HttpError(
400,
"Your request is already using the new API format and does not need the compatibility endpoint. Use the /proxy/anthropic endpoint instead."
);
}
if (alreadyUsingClaude3) {
throw new HttpError(
400,
"Your request already includes the new model identifier and does not need the compatibility endpoint. Use the /proxy/anthropic endpoint instead."
);
}
}
function maybeReassignModel(req: Request) {
const model = req.body.model;
if (!model.startsWith("gpt-")) return;

View File

@ -16,7 +16,7 @@ import {
ProxyResHandlerWithBody,
createOnProxyResHandler,
} from "./middleware/response";
import { transformAnthropicChatResponseToAnthropicText } from "./anthropic";
import { handleCompatibilityRequest, transformAnthropicChatResponseToAnthropicText } from "./anthropic";
const LATEST_AWS_V2_MINOR_VERSION = "1";
const CLAUDE_3_COMPAT_MODEL = "anthropic.claude-3-sonnet-20240229-v1:0";
@ -187,6 +187,7 @@ awsRouter.post(
awsRouter.post(
"/v1/claude-3/complete",
ipLimiter,
handleCompatibilityRequest,
createPreprocessorMiddleware(
{ inApi: "anthropic-text", outApi: "anthropic-chat", service: "aws" },
{