fix: models hub should show latest data only (#5925)
* fix: models hub should show latest data only * test: correct expected result
This commit is contained in:
parent
4d4cf896af
commit
0c53ad0e16
@ -98,7 +98,7 @@ describe('useModelSources', () => {
|
|||||||
expect(result.current.sources).toEqual([])
|
expect(result.current.sources).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should merge new sources with existing ones', async () => {
|
it('should not merge new sources with existing ones', async () => {
|
||||||
const existingSources: CatalogModel[] = [
|
const existingSources: CatalogModel[] = [
|
||||||
{
|
{
|
||||||
model_name: 'existing-model',
|
model_name: 'existing-model',
|
||||||
@ -132,7 +132,7 @@ describe('useModelSources', () => {
|
|||||||
await result.current.fetchSources()
|
await result.current.fetchSources()
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.current.sources).toEqual([...newSources, ...existingSources])
|
expect(result.current.sources).toEqual(newSources)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not duplicate models with same model_name', async () => {
|
it('should not duplicate models with same model_name', async () => {
|
||||||
@ -175,15 +175,7 @@ describe('useModelSources', () => {
|
|||||||
await result.current.fetchSources()
|
await result.current.fetchSources()
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.current.sources).toEqual([
|
expect(result.current.sources).toEqual(newSources)
|
||||||
...newSources,
|
|
||||||
{
|
|
||||||
model_name: 'unique-model',
|
|
||||||
provider: 'provider',
|
|
||||||
description: 'Unique model',
|
|
||||||
version: '1.0.0',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle empty sources response', async () => {
|
it('should handle empty sources response', async () => {
|
||||||
@ -475,7 +467,7 @@ describe('useModelSources', () => {
|
|||||||
await result.current.fetchSources()
|
await result.current.fetchSources()
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.current.sources).toEqual([...sources2, ...sources1])
|
expect(result.current.sources).toEqual(sources2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle fetch after error', async () => {
|
it('should handle fetch after error', async () => {
|
||||||
|
|||||||
@ -31,15 +31,9 @@ export const useModelSources = create<ModelSourcesState>()(
|
|||||||
set({ loading: true, error: null })
|
set({ loading: true, error: null })
|
||||||
try {
|
try {
|
||||||
const newSources = await fetchModelCatalog()
|
const newSources = await fetchModelCatalog()
|
||||||
const currentSources = get().sources
|
|
||||||
|
|
||||||
set({
|
set({
|
||||||
sources: [
|
sources: newSources.length ? newSources : get().sources,
|
||||||
...newSources,
|
|
||||||
...currentSources.filter(
|
|
||||||
(e) => !newSources.some((s) => s.model_name === e.model_name)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
loading: false,
|
loading: false,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -145,8 +145,12 @@ function Hub() {
|
|||||||
const repoInfo = await fetchHuggingFaceRepo(search.repo)
|
const repoInfo = await fetchHuggingFaceRepo(search.repo)
|
||||||
if (repoInfo) {
|
if (repoInfo) {
|
||||||
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
|
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
|
||||||
setHuggingFaceRepo(catalogModel)
|
if (
|
||||||
addSource(catalogModel)
|
!sources.some((s) => s.model_name === catalogModel.model_name)
|
||||||
|
) {
|
||||||
|
setHuggingFaceRepo(catalogModel)
|
||||||
|
addSource(catalogModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchSources()
|
await fetchSources()
|
||||||
@ -157,7 +161,7 @@ function Hub() {
|
|||||||
}
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
}, [convertHfRepoToCatalogModel, fetchSources, addSource, search])
|
}, [convertHfRepoToCatalogModel, fetchSources, addSource, search, sources])
|
||||||
|
|
||||||
// Sorting functionality
|
// Sorting functionality
|
||||||
const sortedModels = useMemo(() => {
|
const sortedModels = useMemo(() => {
|
||||||
@ -247,8 +251,12 @@ function Hub() {
|
|||||||
const repoInfo = await fetchHuggingFaceRepo(e.target.value)
|
const repoInfo = await fetchHuggingFaceRepo(e.target.value)
|
||||||
if (repoInfo) {
|
if (repoInfo) {
|
||||||
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
|
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
|
||||||
setHuggingFaceRepo(catalogModel)
|
if (
|
||||||
addSource(catalogModel)
|
!sources.some((s) => s.model_name === catalogModel.model_name)
|
||||||
|
) {
|
||||||
|
setHuggingFaceRepo(catalogModel)
|
||||||
|
addSource(catalogModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Original addSource logic (if needed)
|
// Original addSource logic (if needed)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user