-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting on models page by Last Modified is reflecting changes in versions as well #3597
base: main
Are you sure you want to change the base?
Changes from 6 commits
537f7c2
52a8b05
4583fc8
7277c59
72d36df
3df03c7
82c76d0
0105b6f
db0a896
c01978e
419ab6d
bb185fd
1d7aba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from 'react'; | ||
import { CreateModelVersionData, ModelVersion, ModelState } from '~/concepts/modelRegistry/types'; | ||
import { useModelRegistryAPI } from '~/concepts/modelRegistry/context/ModelRegistryContext'; | ||
|
||
export const useModelVersionCreation = (): { | ||
YuliaKrimerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createVersionWithTimestampUpdate: ( | ||
registeredModelId: string, | ||
data: CreateModelVersionData, | ||
opts?: Record<string, unknown>, | ||
) => Promise<ModelVersion>; | ||
apiAvailable: boolean; | ||
} => { | ||
const { api, apiAvailable } = useModelRegistryAPI(); | ||
|
||
const createVersionWithTimestampUpdate = React.useCallback( | ||
async ( | ||
registeredModelId: string, | ||
data: CreateModelVersionData, | ||
opts: Record<string, unknown> = {}, | ||
): Promise<ModelVersion> => { | ||
const newVersion = await api.createModelVersionForRegisteredModel( | ||
opts, | ||
registeredModelId, | ||
data, | ||
); | ||
await api.patchRegisteredModel(opts, { state: ModelState.LIVE }, registeredModelId); | ||
|
||
return newVersion; | ||
}, | ||
[api], | ||
); | ||
|
||
return { | ||
createVersionWithTimestampUpdate, | ||
apiAvailable, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { ContextResourceData, CustomWatchK8sResult } from '~/types'; | |
import { TemplateKind } from '~/k8sTypes'; | ||
import { DEFAULT_CONTEXT_DATA, DEFAULT_LIST_WATCH_RESULT } from '~/utilities/const'; | ||
import useTemplateDisablement from '~/pages/modelServing/customServingRuntimes/useTemplateDisablement'; | ||
import { ModelVersion, RegisteredModel } from '~/concepts/modelRegistry/types'; | ||
import useModelRegistryAPIState, { ModelRegistryAPIState } from './useModelRegistryAPIState'; | ||
|
||
export type ModelRegistryContextType = { | ||
|
@@ -67,6 +68,11 @@ export const ModelRegistryContextProvider = conditionalArea<ModelRegistryContext | |
|
||
type UseModelRegistryAPI = ModelRegistryAPIState & { | ||
refreshAllAPI: () => void; | ||
patchModelVersion: (modelVersionId: string, updates: Partial<ModelVersion>) => Promise<void>; | ||
patchRegisteredModel: ( | ||
registeredModelId: string, | ||
updates: Partial<RegisteredModel>, | ||
) => Promise<void>; | ||
}; | ||
|
||
export const useModelRegistryAPI = (): UseModelRegistryAPI => { | ||
|
@@ -75,5 +81,9 @@ export const useModelRegistryAPI = (): UseModelRegistryAPI => { | |
return { | ||
refreshAllAPI, | ||
...apiState, | ||
patchModelVersion: (modelVersionId: string, updates: Partial<ModelVersion>) => | ||
apiState.api.patchModelVersion({}, updates, modelVersionId).then(() => undefined), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand the purpose of the changes in this file. Why add these patch functions to the root of the returned object when they're already returned under |
||
patchRegisteredModel: (registeredModelId: string, updates: Partial<RegisteredModel>) => | ||
apiState.api.patchRegisteredModel({}, updates, registeredModelId).then(() => undefined), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
ModelRegistryAPIs, | ||
ModelState, | ||
ModelRegistryMetadataType, | ||
} from '~/concepts/modelRegistry/types'; | ||
|
||
type MinimalModelRegistryAPI = Pick<ModelRegistryAPIs, 'patchRegisteredModel'>; | ||
|
||
export const bumpModelVersionTimestamp = async ( | ||
api: ModelRegistryAPIs, | ||
modelVersionId: string, | ||
): Promise<void> => { | ||
if (!modelVersionId) { | ||
throw new Error('Model version ID is required'); | ||
} | ||
|
||
try { | ||
await api.patchModelVersion({}, { state: ModelState.LIVE }, modelVersionId); | ||
} catch (error) { | ||
throw new Error( | ||
`Failed to update model version timestamp: ${ | ||
error instanceof Error ? error.message : String(error) | ||
}`, | ||
); | ||
} | ||
}; | ||
|
||
export const bumpRegisteredModelTimestamp = async ( | ||
api: MinimalModelRegistryAPI, | ||
registeredModelId: string, | ||
): Promise<void> => { | ||
if (!registeredModelId) { | ||
throw new Error('Registered model ID is required'); | ||
} | ||
|
||
try { | ||
const currentTime = new Date().toISOString(); | ||
await api.patchRegisteredModel( | ||
{}, | ||
{ | ||
state: ModelState.LIVE, | ||
customProperties: { | ||
_lastModified: { | ||
metadataType: ModelRegistryMetadataType.STRING, | ||
// eslint-disable-next-line camelcase | ||
string_value: currentTime, | ||
}, | ||
}, | ||
Comment on lines
+42
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's up with this customProperties piece? I don't think it should be necessary, and it'll show up in the properties table in the UI I think all we need is the Also... and this part is more annoying... I wonder if it's ok to just pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking more - if the |
||
}, | ||
registeredModelId, | ||
); | ||
} catch (error) { | ||
throw new Error( | ||
`Failed to update registered model timestamp: ${ | ||
error instanceof Error ? error.message : String(error) | ||
}`, | ||
); | ||
} | ||
}; | ||
|
||
export const bumpBothTimestamps = async ( | ||
api: ModelRegistryAPIs, | ||
modelVersionId: string, | ||
registeredModelId: string, | ||
): Promise<void> => { | ||
await Promise.all([ | ||
bumpModelVersionTimestamp(api, modelVersionId), | ||
bumpRegisteredModelTimestamp(api, registeredModelId), | ||
]); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to just use the
patchRegisteredModel
exported from this same file below (already in scope inside this function), it returns the same function you're writing here.