trying to figure out why it's selecting incorrect model
This commit is contained in:
@@ -41,8 +41,6 @@ export const addKey: ProxyRequestMiddleware = (proxyReq, req) => {
|
||||
// For such cases, ignore the requested model entirely.
|
||||
if (req.inboundApi === "openai" && req.outboundApi === "anthropic") {
|
||||
req.log.debug("Using an Anthropic key for an OpenAI-compatible request");
|
||||
// We don't assign the model here, that will happen when transforming the
|
||||
// request body.
|
||||
assignedKey = keyPool.get("claude-v1");
|
||||
} else {
|
||||
assignedKey = keyPool.get(req.body.model);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { OpenAIPromptMessage } from "../../../tokenization/openai";
|
||||
* The maximum number of tokens an Anthropic prompt can have before we switch to
|
||||
* the larger claude-100k context model.
|
||||
*/
|
||||
const CLAUDE_100K_THRESHOLD = 8200;
|
||||
const CLAUDE_100K_TOKEN_THRESHOLD = 8200;
|
||||
|
||||
// https://console.anthropic.com/docs/api/reference#-v1-complete
|
||||
const AnthropicV1CompleteSchema = z.object({
|
||||
@@ -127,8 +127,16 @@ function openaiToAnthropic(body: any, req: Request) {
|
||||
const CLAUDE_BIG = process.env.CLAUDE_BIG_MODEL || "claude-v1-100k";
|
||||
const CLAUDE_SMALL = process.env.CLAUDE_SMALL_MODEL || "claude-v1";
|
||||
|
||||
const contextTokens = Number(req.promptTokens ?? 0) + Number(rest.max_tokens);
|
||||
const model =
|
||||
req.promptTokens ?? 0 > CLAUDE_100K_THRESHOLD ? CLAUDE_BIG : CLAUDE_SMALL;
|
||||
contextTokens ?? 0 > CLAUDE_100K_TOKEN_THRESHOLD
|
||||
? CLAUDE_BIG
|
||||
: CLAUDE_SMALL;
|
||||
|
||||
req.log.debug(
|
||||
{ contextTokens, model, CLAUDE_100K_TOKEN_THRESHOLD },
|
||||
"Selected Claude model"
|
||||
);
|
||||
|
||||
let stops = rest.stop
|
||||
? Array.isArray(rest.stop)
|
||||
|
||||
Reference in New Issue
Block a user