Skip to content

Commit 8d2c3e2

Browse files
authored
update splitLlamaModels (opendatahub-io#5230)
* update splitLlamaModels * add unit tests
1 parent 7346725 commit 8d2c3e2

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { splitLlamaModelId } from '~/app/utilities/utils';
2+
3+
describe('splitLlamaModelId', () => {
4+
it('should split a valid model ID with provider and ID', () => {
5+
const result = splitLlamaModelId('vllm-inference-1/facebook-opt-1');
6+
expect(result).toEqual({
7+
providerId: 'vllm-inference-1',
8+
id: 'facebook-opt-1',
9+
});
10+
});
11+
12+
it('should handle model ID without slash', () => {
13+
const result = splitLlamaModelId('facebook-opt-1');
14+
expect(result).toEqual({
15+
providerId: '',
16+
id: 'facebook-opt-1',
17+
});
18+
});
19+
20+
it('should handle empty string', () => {
21+
const result = splitLlamaModelId('');
22+
expect(result).toEqual({
23+
providerId: '',
24+
id: '',
25+
});
26+
});
27+
28+
it('should handle model ID with multiple slashes (only splits on first)', () => {
29+
const result = splitLlamaModelId('vllm-inference-1/facebook/opt-1');
30+
expect(result).toEqual({
31+
providerId: 'vllm-inference-1',
32+
id: 'facebook/opt-1',
33+
});
34+
});
35+
36+
it('should handle complex provider and model names', () => {
37+
const result = splitLlamaModelId('anthropic-vertex/claude-3-opus-20240229');
38+
expect(result).toEqual({
39+
providerId: 'anthropic-vertex',
40+
id: 'claude-3-opus-20240229',
41+
});
42+
});
43+
44+
it('should handle model ID with special characters', () => {
45+
const result = splitLlamaModelId('provider-123/model_name-v2.0');
46+
expect(result).toEqual({
47+
providerId: 'provider-123',
48+
id: 'model_name-v2.0',
49+
});
50+
});
51+
});

packages/gen-ai/frontend/src/app/utilities/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export const convertAIModelToK8sResource = (model: AIModel): K8sResourceCommon =
1212
});
1313

1414
export const splitLlamaModelId = (llamaModelId: string): { providerId: string; id: string } => {
15-
const [providerId, id] = llamaModelId.split('/');
15+
const slashIndex = llamaModelId.indexOf('/');
16+
if (slashIndex === -1) {
17+
return { providerId: '', id: llamaModelId };
18+
}
19+
const providerId = llamaModelId.substring(0, slashIndex);
20+
const id = llamaModelId.substring(slashIndex + 1);
1621
if (!providerId || !id) {
1722
return { providerId: '', id: llamaModelId };
1823
}

0 commit comments

Comments
 (0)