-
Notifications
You must be signed in to change notification settings - Fork 16
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
ML Hub models api calls #364
Changes from 8 commits
211f1c1
94dfef8
473609f
61da3d9
0d38e8d
20e552f
c6201f6
1d2b8f9
aee8417
5c7a757
24a712c
a0566cc
7ea32e3
6fae54d
a2c8530
727693b
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,18 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const details = ( | ||
params: Models.GetModelRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModel>(() => api.getModel(params)); | ||
}; | ||
|
||
export default details; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const downloadLinks = ( | ||
params: Models.DownloadModelRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelDownload>(() => | ||
api.downloadModel(params) | ||
); | ||
}; | ||
|
||
export default downloadLinks; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { default as list } from './list'; | ||
export { default as details } from './details'; | ||
export { default as downloadLinks } from './downloadLinks'; | ||
export { default as listByAuthor } from './listByAuthor'; | ||
export { default as listByDataset } from './listByDataset'; | ||
export { default as listByLanguage } from './listByLanguage'; | ||
export { default as listByLibrary } from './listByLibrary'; | ||
export { default as listByQuery } from './listByQuery'; | ||
export { default as listByTask } from './listByTask'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const downloadLinks = ( | ||
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. Same as the comment above, this should be called something like |
||
params: Models.GetModelInferenceServerRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelServer>(() => | ||
api.getModelInferenceServer(params) | ||
); | ||
}; | ||
|
||
export default downloadLinks; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const list = (basePath: string, jwt: string) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => api.listModels()); | ||
}; | ||
|
||
export default list; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const listByAuthor = ( | ||
params: Models.ListModelsByAuthorRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => | ||
api.listModelsByAuthor(params) | ||
); | ||
}; | ||
|
||
export default listByAuthor; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const listByDataset = ( | ||
params: Models.ListModelsByDatasetRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => | ||
api.listModelsByDataset(params) | ||
); | ||
}; | ||
|
||
export default listByDataset; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const listByLanguage = ( | ||
params: Models.ListModelsByLanguageRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => | ||
api.listModelsByLanguage(params) | ||
); | ||
}; | ||
|
||
export default listByLanguage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const listByLibrary = ( | ||
params: Models.ListModelsByLibraryRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => | ||
api.listModelsByLibrary(params) | ||
); | ||
}; | ||
|
||
export default listByLibrary; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const listByQuery = ( | ||
params: Models.ListModelsByQueryRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => | ||
api.listModelsByQuery(params) | ||
); | ||
}; | ||
|
||
export default listByQuery; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const listByTask = ( | ||
params: Models.ListModelsByTaskRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Models.ModelsApi = apiGenerator<Models.ModelsApi>( | ||
Models, | ||
Models.ModelsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Models.RespModelObject>(() => | ||
api.listModelsByTask(params) | ||
); | ||
}; | ||
|
||
export default listByTask; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { default as useList } from './useList'; | ||
export { default as useDetails } from './useDetails'; | ||
export { default as useDownloadLinks } from './useDownloadLinks'; | ||
export { default as useListByAuthor } from './useListByAuthor'; | ||
export { default as useListByDataset } from './useListByDataset'; | ||
export { default as useListByLanguage } from './useListByLanguage'; | ||
export { default as useListByLibrary } from './useListByLibrary'; | ||
export { default as useListByQuery } from './useListByQuery'; | ||
export { default as useListByTask } from './useListByTask'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const basePath = 'https://hub.pods.tacc.tapis.io'; | ||
|
||
export default basePath; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const QueryKeys = { | ||
list: 'ml-hub/models/list', | ||
details: 'ml-hub/models/details', | ||
downloadLinks: 'ml-hub/models/downloadLinks', | ||
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. Perhaps |
||
listByAuthor: 'ml-hub/models/listByAuthor', | ||
listByDataset: 'ml-hub/models/listByDataset', | ||
listByLanguage: 'ml-hub/models/listByLanguage', | ||
listByLibrary: 'ml-hub/models/listByLibrary', | ||
listByQuery: 'ml-hub/models/listByQuery', | ||
listByTask: 'ml-hub/models/listByTask', | ||
}; | ||
|
||
export default QueryKeys; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery, QueryObserverOptions } from 'react-query'; | ||
import { details } from 'tapis-api/ml-hub/models'; | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import QueryKeys from './queryKeys'; | ||
import basePath from './modelsPath'; // remove if ml-hub is listed in NGINX | ||
|
||
const useDetails = ( | ||
params: Models.GetModelRequest, | ||
options: QueryObserverOptions<Models.RespModel, Error> = {} | ||
) => { | ||
// const { accessToken, basePath } = useTapisConfig(); | ||
const { accessToken } = useTapisConfig(); // remove this line and uncomment line above if ml-hub is listed in NGINX | ||
const result = useQuery<Models.RespModel, Error>( | ||
[QueryKeys.details, params, accessToken], | ||
// Default to no token. This will generate a 403 when calling the list function | ||
// which is expected behavior for not having a token | ||
() => details(params, basePath, accessToken?.access_token ?? ''), | ||
{ | ||
enabled: !!accessToken, | ||
} | ||
); | ||
return result; | ||
}; | ||
|
||
export default useDetails; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery, QueryObserverOptions } from 'react-query'; | ||
import { downloadLinks } from 'tapis-api/ml-hub/models'; | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import QueryKeys from './queryKeys'; | ||
import basePath from './modelsPath'; // remove if ml-hub is listed in NGINX | ||
|
||
const useDownloadLinks = ( | ||
params: Models.DownloadModelRequest, | ||
options: QueryObserverOptions<Models.RespModelDownload, Error> = {} | ||
) => { | ||
// const { accessToken, basePath } = useTapisConfig(); | ||
const { accessToken } = useTapisConfig(); // remove this line and uncomment line above if ml-hub is listed in NGINX | ||
const result = useQuery<Models.RespModelDownload, Error>( | ||
[QueryKeys.downloadLinks, params, accessToken], | ||
// Default to no token. This will generate a 403 when calling the list function | ||
// which is expected behavior for not having a token | ||
() => downloadLinks(params, basePath, accessToken?.access_token ?? ''), | ||
{ | ||
enabled: !!accessToken, | ||
} | ||
); | ||
return result; | ||
}; | ||
|
||
export default useDownloadLinks; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery, QueryObserverOptions } from 'react-query'; | ||
import { list } from 'tapis-api/ml-hub/models'; | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import QueryKeys from './queryKeys'; | ||
import basePath from './modelsPath'; // remove if ml-hub is listed in NGINX | ||
|
||
const useList = ( | ||
options: QueryObserverOptions<Models.RespModelObject, Error> = {} | ||
) => { | ||
// const { accessToken, basePath } = useTapisConfig(); | ||
const { accessToken } = useTapisConfig(); // remove this line and uncomment line above if ml-hub is listed in NGINX | ||
const result = useQuery<Models.RespModelObject, Error>( | ||
[QueryKeys.list, accessToken], | ||
// Default to no token. This will generate a 403 when calling the list function | ||
// which is expected behavior for not having a token | ||
() => list(basePath, accessToken?.access_token || ''), | ||
{ | ||
...options, | ||
enabled: !!accessToken, | ||
} | ||
); | ||
return result; | ||
}; | ||
|
||
export default useList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery, QueryObserverOptions } from 'react-query'; | ||
import { listByAuthor } from 'tapis-api/ml-hub/models'; | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import QueryKeys from './queryKeys'; | ||
import basePath from './modelsPath'; // remove if ml-hub is listed in NGINX | ||
|
||
const useListByAuthor = ( | ||
params: Models.ListModelsByAuthorRequest, | ||
options: QueryObserverOptions<Models.RespModelObject, Error> = {} | ||
) => { | ||
// const { accessToken, basePath } = useTapisConfig(); | ||
const { accessToken } = useTapisConfig(); // remove this line and uncomment line above if ml-hub is listed in NGINX | ||
const result = useQuery<Models.RespModelObject, Error>( | ||
[QueryKeys.listByAuthor, params, accessToken], | ||
// Default to no token. This will generate a 403 when calling the list function | ||
// which is expected behavior for not having a token | ||
() => listByAuthor(params, basePath, accessToken?.access_token ?? ''), | ||
{ | ||
enabled: !!accessToken, | ||
} | ||
); | ||
return result; | ||
}; | ||
|
||
export default useListByAuthor; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery, QueryObserverOptions } from 'react-query'; | ||
import { listByDataset } from 'tapis-api/ml-hub/models'; | ||
import { Models } from '@tapis/tapis-typescript'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import QueryKeys from './queryKeys'; | ||
import basePath from './modelsPath'; // remove if ml-hub is listed in NGINX | ||
|
||
const useListByDataset = ( | ||
params: Models.ListModelsByDatasetRequest, | ||
options: QueryObserverOptions<Models.RespModelObject, Error> = {} | ||
) => { | ||
// const { accessToken, basePath } = useTapisConfig(); | ||
const { accessToken } = useTapisConfig(); // remove this line and uncomment line above if ml-hub is listed in NGINX | ||
const result = useQuery<Models.RespModelObject, Error>( | ||
[QueryKeys.listByDataset, params, accessToken], | ||
// Default to no token. This will generate a 403 when calling the list function | ||
// which is expected behavior for not having a token | ||
() => listByDataset(params, basePath, accessToken?.access_token ?? ''), | ||
{ | ||
enabled: !!accessToken, | ||
} | ||
); | ||
return result; | ||
}; | ||
|
||
export default useListByDataset; |
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.
Can we rename this file something semantically closer to the purpose of this function ( fetching inference server details for a given model) and/or what it returns? 1.
inferenceAvailable
sounds like it should return a boolean value. 2. Knowing whether an inference server is available is secondary information that we can derive from the value of the result. I recommend something likesrc/tapis-api/models/inference-servers/details.ts