Merge pull request #19058 from BerriAI/litellm_ui_add_model_ant

[Feature] UI - Model: Anthropic Models QOL
This commit is contained in:
yuneng-jiang
2026-01-14 13:43:57 -08:00
committed by GitHub
2 changed files with 52 additions and 1 deletions
@@ -0,0 +1,28 @@
import { render, screen } from "@testing-library/react";
import { Form } from "antd";
import { describe, expect, it } from "vitest";
import ConditionalPublicModelName from "./conditional_public_model_name";
describe("ConditionalPublicModelName", () => {
it("should render", () => {
render(
<Form
initialValues={{
model: ["gpt-4"],
model_mappings: [
{
public_name: "gpt-4",
litellm_model: "gpt-4",
},
],
}}
>
<ConditionalPublicModelName />
</Form>,
);
expect(screen.getByText("Model Mappings")).toBeInTheDocument();
expect(screen.getByText("Public Model Name")).toBeInTheDocument();
expect(screen.getByText("LiteLLM Model Name")).toBeInTheDocument();
});
});
@@ -129,8 +129,31 @@ const ConditionalPublicModelName: React.FC = () => {
<TextInput
value={text}
onChange={(e) => {
const newValue = e.target.value;
const newMappings = [...form.getFieldValue("model_mappings")];
newMappings[index].public_name = e.target.value;
// Check conditions for Anthropic -1m suffix handling
const isAnthropic = selectedProvider === Providers.Anthropic;
const endsWith1m = newValue.endsWith("-1m");
const litellmParams = form.getFieldValue("litellm_extra_params");
const isLitellmParamsEmpty = !litellmParams || litellmParams.trim() === "";
let finalPublicName = newValue;
if (isAnthropic && endsWith1m && isLitellmParamsEmpty) {
// Set litellm params with extra_headers
const litellmParamsValue = JSON.stringify(
{ extra_headers: { "anthropic-beta": "context-1m-2025-08-07" } },
null,
2,
);
form.setFieldValue("litellm_extra_params", litellmParamsValue);
// Remove -1m suffix from public_name
finalPublicName = newValue.slice(0, -3); // Remove "-1m" (3 characters)
}
newMappings[index].public_name = finalPublicName;
form.setFieldValue("model_mappings", newMappings);
}}
/>