Skip to content
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

Merged
merged 16 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/tapis-api/ml-hub/models/details.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/downloadLinks.ts
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;
9 changes: 9 additions & 0 deletions src/tapis-api/ml-hub/models/index.ts
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';
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/inferenceAvailable.ts
Copy link
Collaborator

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 like src/tapis-api/models/inference-servers/details.ts

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 = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment above, this should be called something like details. The name of the function should be the same as the name of the file.

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;
14 changes: 14 additions & 0 deletions src/tapis-api/ml-hub/models/list.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/listByAuthor.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/listByDataset.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/listByLanguage.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/listByLibrary.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/listByQuery.ts
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;
20 changes: 20 additions & 0 deletions src/tapis-api/ml-hub/models/listByTask.ts
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;
9 changes: 9 additions & 0 deletions src/tapis-hooks/ml-hub/models/index.ts
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';
3 changes: 3 additions & 0 deletions src/tapis-hooks/ml-hub/models/modelsPath.ts
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;
13 changes: 13 additions & 0 deletions src/tapis-hooks/ml-hub/models/queryKeys.ts
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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps inferenceServerDetails: 'ml-hub/models/inferenceServerDetails'

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;
26 changes: 26 additions & 0 deletions src/tapis-hooks/ml-hub/models/useDetails.ts
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;
26 changes: 26 additions & 0 deletions src/tapis-hooks/ml-hub/models/useDownloadLinks.ts
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;
26 changes: 26 additions & 0 deletions src/tapis-hooks/ml-hub/models/useList.ts
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;
26 changes: 26 additions & 0 deletions src/tapis-hooks/ml-hub/models/useListByAuthor.ts
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;
26 changes: 26 additions & 0 deletions src/tapis-hooks/ml-hub/models/useListByDataset.ts
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;
Loading
Loading