Skip to content

Commit

Permalink
fix: catalog conversion not handling all cases (#1750)
Browse files Browse the repository at this point in the history
* fix: catalog conversion not handling all cases

Fixes #1749

Signed-off-by: Jeff MAURY <[email protected]>

* fix: add unit tests

Signed-off-by: Jeff MAURY <[email protected]>

* fix: apply suggestion from @lstocchi

Co-authored-by: Luca Stocchi <[email protected]>
Signed-off-by: Jeff MAURY <[email protected]>

---------

Signed-off-by: Jeff MAURY <[email protected]>
Co-authored-by: Luca Stocchi <[email protected]>
  • Loading branch information
jeffmaury and lstocchi authored Sep 19, 2024
1 parent 7435841 commit a376180
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/utils/catalogUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { test, expect, describe } from 'vitest';
import {
CatalogFormat,
hasCatalogWrongFormat,
isNonNullObject,
merge,
sanitize,
Expand Down Expand Up @@ -82,6 +83,7 @@ describe('sanitize', () => {
},
],
};
expect(hasCatalogWrongFormat(raw)).toBeTruthy();
const catalog = sanitize(raw);
expect(catalog.version).equals(CatalogFormat.CURRENT);
expect(catalog.models[0].backend).equals('llama-cpp');
Expand Down Expand Up @@ -123,6 +125,7 @@ describe('sanitize', () => {
],
};

expect(hasCatalogWrongFormat(raw)).toBeFalsy();
expect(() => sanitize(raw)).toThrowError('the catalog is using an invalid version');
});

Expand Down Expand Up @@ -160,6 +163,7 @@ describe('sanitize', () => {
},
],
};
expect(hasCatalogWrongFormat(raw)).toBeFalsy();
const catalog = sanitize(raw);
expect(catalog.version).equals(CatalogFormat.CURRENT);
expect(catalog.models[0].backend).toBeUndefined();
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/utils/catalogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export function sanitize(rawObject: object): ApplicationCatalog {
}

export function hasCatalogWrongFormat(raw: object): boolean {
return 'recipes' in raw && Array.isArray(raw.recipes) && !!raw.recipes.find(r => 'models' in r);
return (
!('version' in raw) || ('recipes' in raw && Array.isArray(raw.recipes) && !!raw.recipes.find(r => 'models' in r))
);
}

function adaptToCurrent(raw: object): object & { version: string } {
Expand All @@ -59,7 +61,7 @@ function adaptToCurrent(raw: object): object & { version: string } {
raw.recipes.forEach(recipe => {
recipe.backend = recipe.backend ?? 'llama-cpp';
recipe.recommended = recipe.recommended ?? recipe.models ?? []; // Copy models to recommended if not present
recipe.models = []; // Clear models to avoid duplication
delete recipe.models; // Clear models to avoid duplication
});
}

Expand Down

0 comments on commit a376180

Please sign in to comment.