Skip to content

Commit 4005a51

Browse files
authored
(UI) fix adding Vertex Models (BerriAI#8129)
* fix handleSubmit * update handleAddModelSubmit * add jest testing for ui * add step for running ui unit tests * add validate json step to add model * ui jest testing fixes * update package lock * ci/cd run again * fix antd import * run jest tests first * fix antd install * fix ui unit tests * fix unit test ui
1 parent 8a235e7 commit 4005a51

File tree

12 files changed

+6814
-120
lines changed

12 files changed

+6814
-120
lines changed

litellm-js/proxy/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@cloudflare/workers-types"
1212
],
1313
"jsx": "react-jsx",
14-
"jsxImportSource": "hono/jsx"
14+
"jsxImportSource": "hono/jsx",
15+
"skipLibCheck": true
1516
},
1617
}

tests/local_testing/test_completion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
sys.path.insert(
1313
0, os.path.abspath("../..")
14-
) # Adds the parent directory to the system-path
14+
) # Adds the parent directory to the system path
1515

1616

1717
import os
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { handleAddModelSubmit } from '../../../ui/litellm-dashboard/src/components/add_model/handle_add_model_submit';
2+
import { modelCreateCall } from '../../../ui/litellm-dashboard/src/components/networking';
3+
4+
// Mock the dependencies
5+
const mockModelCreateCall = jest.fn().mockResolvedValue({ data: 'success' });
6+
jest.mock('../../../ui/litellm-dashboard/src/components/networking', () => ({
7+
modelCreateCall: async (accessToken: string, formValues: any) => mockModelCreateCall(formValues)
8+
}));
9+
10+
// Also need to mock provider_map
11+
jest.mock('../../../ui/litellm-dashboard/src/components/provider_info_helpers', () => ({
12+
provider_map: {
13+
'openai': 'openai'
14+
}
15+
}));
16+
17+
jest.mock('antd', () => ({
18+
message: {
19+
error: jest.fn()
20+
}
21+
}));
22+
23+
describe('handleAddModelSubmit', () => {
24+
const mockForm = {
25+
resetFields: jest.fn()
26+
};
27+
const mockAccessToken = 'test-token';
28+
29+
beforeEach(() => {
30+
jest.clearAllMocks();
31+
mockModelCreateCall.mockClear();
32+
});
33+
34+
it('should not modify model name when all-wildcard is not selected', async () => {
35+
const formValues = {
36+
model: 'gpt-4',
37+
custom_llm_provider: 'openai',
38+
model_name: 'my-gpt4-deployment'
39+
};
40+
41+
await handleAddModelSubmit(formValues, mockAccessToken, mockForm);
42+
43+
console.log('Expected call:', {
44+
model_name: 'my-gpt4-deployment',
45+
litellm_params: {
46+
model: 'gpt-4',
47+
custom_llm_provider: 'openai'
48+
},
49+
model_info: {}
50+
});
51+
console.log('Actual calls:', mockModelCreateCall.mock.calls);
52+
53+
expect(mockModelCreateCall).toHaveBeenCalledWith({
54+
model_name: 'my-gpt4-deployment',
55+
litellm_params: {
56+
model: 'gpt-4',
57+
custom_llm_provider: 'openai'
58+
},
59+
model_info: {}
60+
});
61+
expect(mockForm.resetFields).toHaveBeenCalled();
62+
});
63+
64+
it('should handle all-wildcard model correctly', async () => {
65+
const formValues = {
66+
model: 'all-wildcard',
67+
custom_llm_provider: 'openai',
68+
model_name: 'my-deployment'
69+
};
70+
71+
await handleAddModelSubmit(formValues, mockAccessToken, mockForm);
72+
73+
expect(mockModelCreateCall).toHaveBeenCalledWith({
74+
model_name: 'openai/*',
75+
litellm_params: {
76+
model: 'openai/*',
77+
custom_llm_provider: 'openai'
78+
},
79+
model_info: {}
80+
});
81+
expect(mockForm.resetFields).toHaveBeenCalled();
82+
});
83+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'jsdom',
4+
moduleNameMapper: {
5+
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
6+
'\\.(jpg|jpeg|png|gif|webp|svg)$': '<rootDir>/__mocks__/fileMock.js'
7+
},
8+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
9+
testMatch: [
10+
'<rootDir>/**/*.test.tsx',
11+
'<rootDir>/**/*_test.tsx' // Added this to match your file naming
12+
],
13+
moduleDirectories: ['node_modules'],
14+
testPathIgnorePatterns: ['/node_modules/'],
15+
transform: {
16+
'^.+\\.(ts|tsx)$': 'ts-jest'
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Add any global setup here

0 commit comments

Comments
 (0)