mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-26 01:12:21 +00:00
fix(ui): guard team fallback model fetch against stale responses
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
ca9648171d
commit
1d984ce777
2 changed files with 29 additions and 0 deletions
|
|
@ -110,6 +110,25 @@ describe("RouterSettingsAccordion", () => {
|
|||
expect(fetchAvailableModels).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores a stale team fetch that resolves after teamId changes", async () => {
|
||||
let resolveFirst: (value: { data: { model_name: string }[] }) => void = () => {};
|
||||
const firstResponse = new Promise<{ data: { model_name: string }[] }>((resolve) => {
|
||||
resolveFirst = resolve;
|
||||
});
|
||||
vi.mocked(modelInfoCall)
|
||||
.mockReturnValueOnce(firstResponse as ReturnType<typeof modelInfoCall>)
|
||||
.mockResolvedValueOnce({ data: [{ model_name: "team-b-model" }] });
|
||||
|
||||
const { rerender } = render(<RouterSettingsAccordion accessToken="test-token" teamId="team-a" />);
|
||||
rerender(<RouterSettingsAccordion accessToken="test-token" teamId="team-b" />);
|
||||
await flushPromises();
|
||||
|
||||
resolveFirst({ data: [{ model_name: "team-a-model" }] });
|
||||
await flushPromises();
|
||||
|
||||
expect(screen.getByTestId("available-models").textContent).toBe("team-b-model");
|
||||
});
|
||||
|
||||
it("uses the global model list when no teamId is provided", async () => {
|
||||
vi.mocked(fetchAvailableModels).mockResolvedValueOnce([{ model_group: "shared-gpt" }]);
|
||||
|
||||
|
|
|
|||
|
|
@ -181,10 +181,14 @@ const RouterSettingsAccordion = forwardRef<RouterSettingsAccordionRef, RouterSet
|
|||
if (!accessToken) {
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
const loadModels = async () => {
|
||||
try {
|
||||
if (teamId) {
|
||||
const response = await modelInfoCall(accessToken, "", "", 1, 1000, undefined, undefined, teamId);
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
const teamModels: ModelGroup[] = (response?.data ?? [])
|
||||
.map((item: { model_name?: string }) => item.model_name)
|
||||
.filter((name: string | undefined): name is string => Boolean(name))
|
||||
|
|
@ -193,12 +197,18 @@ const RouterSettingsAccordion = forwardRef<RouterSettingsAccordionRef, RouterSet
|
|||
return;
|
||||
}
|
||||
const uniqueModels = await fetchAvailableModels(accessToken);
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
setModelInfo(uniqueModels);
|
||||
} catch (error) {
|
||||
console.error("Error fetching model info for fallbacks:", error);
|
||||
}
|
||||
};
|
||||
loadModels();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [accessToken, teamId]);
|
||||
|
||||
// Helper function to build router_settings from current state
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue