coinfer.js package

Classes

ClassDescription
CoinferThe coinferJS’s main class.

Functions

FunctionDescription
useCoinfer()A hook used to retrieve the Coinfer instance within CoinferContext.

Interfaces

InterfaceDescription
IExperimentSocketLogActionTypeThe data type of the log information obtained from WebSocket.
IExperimentSocketNamesActionTypeAfter establishing the connection on the backend (requiring version: ‘1.0’), the data returned once includes the Chains and all known Variable names under each Chain.
IExperimentSocketPlotDataActionTypeThe plot data obtained from the WebSocket.
ISuperLogsTypeThe logs for the super user.
IUserInfoTypeThe userInfo structure.

Variables

VariableDescription
CoinferContextCoinferjs’s Context
useCoinferActionA hook for invoking the coinferJS feature using a more convenient method.
useExperimentWebSocketYou can use this hook to access the WebSocket connection of the Experiment.
useNewCoinfer

Type Aliases

Type AliasDescription
ExperimentSocketActionTypesThe type of data obtained from the WebSocket.
FetchFunctionReturnType
FetchFunctionType

Coinfer.__VERSION property

The default backend API server version. Signature:
static __VERSION: string;

Coinfer.(constructor)

Constructs a new instance of the Coinfer class Signature:
constructor();

Coinfer.check() method

Signature:
check(taskId: any, period?: number): Promise<void>;

Parameters

ParameterTypeDescription
taskIdany
periodnumber(Optional)
Returns: Promise<void>

Coinfer.checkToken() method

Signature:
checkToken(token: string): Promise<any>;

Parameters

ParameterTypeDescription
tokenstring
Returns: Promise<any>

Coinfer.config property

Signature:
config: ICoinferConfig;

Coinfer.create() method

Signature:
create(payload: any): Promise<unknown>;

Parameters

ParameterTypeDescription
payloadany
Returns: Promise<unknown>

Coinfer.createModelFromGithubGist() method

Create a model from GitHub Gist. Signature:
createModelFromGithubGist(repo: string, modelName: string): Promise<IGithubCreatedRes>;

Parameters

ParameterTypeDescription
repostring
modelNamestring
Returns: Promise<IGithubCreatedRes>

Coinfer.createModelFromGithubRepo() method

Create a model from GitHub repository. Signature:
createModelFromGithubRepo(repo: string, branch: string, modelName: string): Promise<IGithubCreatedRes>;

Parameters

ParameterTypeDescription
repostring
branchstring
modelNamestring
Returns: Promise<IGithubCreatedRes>

Coinfer.createShared() method

Share Model or Experiment with other users. Signature:
createShared<T extends keyof CreateSharedReturnMaps>(type: T, sharedItemId: string, sharedParams: ISharedAuthParams): Promise<ICommonResWithStatus<SharedGetReturnMaps[T]> | null>;

Parameters

ParameterTypeDescription
typeT
sharedItemIdstring
sharedParamsISharedAuthParams
Returns: Promise<ICommonResWithStatus<SharedGetReturnMaps[T]> | null>

Coinfer.DefaultSettings property

The default backend URL server address. Signature:
static DefaultSettings: ICoinferConfig;

Example

https://api.coinfer.ai

Coinfer.del() method

Delete the model. Signature:
del(...shortIds: string[]): Promise<boolean>;

Parameters

ParameterTypeDescription
shortIdsstring[]
Returns: Promise<boolean>

Example 1

// delete single model
const result = await coinfer.model.del('M01DCAB');

// delete models
const result = await coinfer.model.del('M01DCAB', 'M01DCAC', 'M01DCAB', ...);
Delete the experiment.

Example 2

// delete single experiment
const result = await coinfer.experiment.del('X01DCAB');

// delete experiments
const result = await coinfer.experiment.del('X01DCAB', 'X01DCAC', 'X01DCAB', ...);
Delete the token.

Example 3

// delete the token
const result = await coinfer.experiment.del(2); // Assuming the id of this token is 2.

Coinfer.deleteAccessToken() method

delete the access token. Signature:
deleteAccessToken(): Promise<void>;
Returns: Promise<void>

Coinfer.deleteShared() method

Delete the sharing of a Model or Experiment. Signature:
deleteShared<T extends keyof DeleteSharedReturnMaps>(type: T, ids: string[]): Promise<ICommonResWithStatus<DeleteSharedReturnMaps[T]> | null>;

Parameters

ParameterTypeDescription
typeT
idsstring[]
Returns: Promise<ICommonResWithStatus<DeleteSharedReturnMaps[T]> | null>

Coinfer.experiment property

Signature:
get experiment(): this;

Coinfer.get() method

Signature:
get(props: ICoinferGetProps & CoinferAuthorizationExtraParams, extraParams?: ICoinferReqExtraParams): Promise<unknown>;

Parameters

ParameterTypeDescription
propsICoinferGetProps & CoinferAuthorizationExtraParams
extraParamsICoinferReqExtraParams(Optional)
Returns: Promise<unknown> Get the colab link of the Experiment. Signature:
getColabLink(experimentId: string): Promise<IColabURLRes>;

Parameters

ParameterTypeDescription
experimentIdstring
Returns: Promise<IColabURLRes>

Coinfer.getExperimentStatus() method

Get the status infomation of the Experiment. Signature:
getExperimentStatus(experimentId: string, params: Partial<ICoinferReqExtraParams>): Promise<any>;

Parameters

ParameterTypeDescription
experimentIdstring
paramsPartial<ICoinferReqExtraParams>
Returns: Promise<any>

Coinfer.getNotifications() method

get the notification list. Signature:
getNotifications(status: NotificationStatusType | 'all', pageConfig: IPagingParams): Promise<ICommonResWithStatus<NotificationWithPagation>>;

Parameters

ParameterTypeDescription
statusNotificationStatusType | ‘all’
pageConfigIPagingParams
Returns: Promise<ICommonResWithStatus<NotificationWithPagation>>

Coinfer.getSharedInfo() method

Get the shared information of the Model/Experiment, such as whether a password is required Signature:
getSharedInfo(type: 'model' | 'experiment', shareId: string): Promise<SharedInfoMaps | null>;

Parameters

ParameterTypeDescription
type‘model’ | ‘experiment’
shareIdstring
Returns: Promise<SharedInfoMaps | null>

Coinfer.getSharedList() method

Get a list of Models and Experiments to share. Signature:
getSharedList<T extends keyof (SharedGetReturnMaps & ToMeSharedCreateMaps)>(type: T, pageConfig: IPagingParams): Promise<IMCMCPagingType<(SharedGetReturnMaps & ToMeSharedCreateMaps)[T]> | null>;

Parameters

ParameterTypeDescription
typeT
pageConfigIPagingParams
Returns: Promise<IMCMCPagingType<(SharedGetReturnMaps & ToMeSharedCreateMaps)[T]> | null>

Coinfer.getSharedModel() method

Get the shared information of the Model. Signature:
getSharedModel(modelId: string, sharedId: string, extraParams?: ICoinferReqExtraParams): Promise<ICommonResWithStatus<SharedInfo> | null>;

Parameters

ParameterTypeDescription
modelIdstring
sharedIdstring
extraParamsICoinferReqExtraParams(Optional)
Returns: Promise<ICommonResWithStatus<SharedInfo> | null>

Coinfer.getTuringConfig() method

Get the turing configuration infomation. Signature:
getTuringConfig(): Promise<ITuringConfig>;
Returns: Promise<ITuringConfig>

Coinfer.list() method

Signature:
list(extraParams?: {
        [key: string]: any;
    }): Promise<any>;

Parameters

ParameterTypeDescription
extraParams{ [key: string]: any; }(Optional)
Returns: Promise<any>

Coinfer.listGithubBranches() method

List all branches of the repository specified by the user(Log in with Github) Signature:
listGithubBranches(repo: string): Promise<IGithubBranches>;

Parameters

ParameterTypeDescription
repostring
Returns: Promise<IGithubBranches>

Coinfer.listGithubReposAndGists() method

List all repositories and Gists owned by the current user(Log in with Github). Signature:
listGithubReposAndGists(): Promise<IGithubReposAndGists>;
Returns: Promise<IGithubReposAndGists>

Coinfer.loadConfigFile() method

Signature:
loadConfigFile(): Promise<any>;
Returns: Promise<any>

Coinfer.logs() method

Show the detailed logs (only for superuser). Signature:
logs(id: any): Promise<ISuperLogsType>;

Parameters

ParameterTypeDescription
idany
Returns: Promise<ISuperLogsType>

Example

const data = await coinfer.experiment.logs(experimentId);

Coinfer.markNotificationAs() method

mark the notification as read or unread. Signature:
markNotificationAs(notificationIds: string[], status: NotificationStatusType): Promise<ICommonResWithStatus<any>>;

Parameters

ParameterTypeDescription
notificationIdsstring[]
statusNotificationStatusType
Returns: Promise<ICommonResWithStatus<any>>

Coinfer class

The coinferJS’s main class. Signature:
declare class Coinfer 

Constructors

ConstructorModifiersDescription
(constructor)()Constructs a new instance of the Coinfer class

Properties

PropertyModifiersTypeDescription
__VERSIONstaticstringThe default backend API server version.
configICoinferConfig
DefaultSettingsstaticICoinferConfigThe default backend URL server address.
experimentreadonlythis
modelreadonlythis
onSavedAccessToken(any: any) => voidlogin with token
taskreadonlythis
tokenreadonlythis
websocketreadonlythis

Methods

MethodModifiersDescription
check(taskId, period)
checkToken(token)
create(payload)
createModelFromGithubGist(repo, modelName)Create a model from GitHub Gist.
createModelFromGithubRepo(repo, branch, modelName)Create a model from GitHub repository.
createShared(type, sharedItemId, sharedParams)Share Model or Experiment with other users.
del(shortIds)Delete the model.
deleteAccessToken()delete the access token.
deleteShared(type, ids)Delete the sharing of a Model or Experiment.
get(props, extraParams)
getColabLink(experimentId)Get the colab link of the Experiment.
getExperimentStatus(experimentId, params)Get the status infomation of the Experiment.
getNotifications(status, pageConfig)get the notification list.
getSharedInfo(type, shareId)Get the shared information of the Model/Experiment, such as whether a password is required
getSharedList(type, pageConfig)Get a list of Models and Experiments to share.
getSharedModel(modelId, sharedId, extraParams)Get the shared information of the Model.
getTuringConfig()Get the turing configuration infomation.
list(extraParams)
listGithubBranches(repo)List all branches of the repository specified by the user(Log in with Github)
listGithubReposAndGists()List all repositories and Gists owned by the current user(Log in with Github).
loadConfigFile()
logs(id)Show the detailed logs (only for superuser).
markNotificationAs(notificationIds, status)mark the notification as read or unread.
onDeleteAccessToken()
onError(err)This method is called when an error occurs, such as authentication failure
run(params)
runBatch(params)
runWithLambda(models)Run Model through lamdba
saveAccessToken(token)After successful login, the method of storing the authorization code.
setAccessToken(token)Set or update the authorization token.
setConfig(config)Set config for Coinfer.
update(payload)

Coinfer.model property

Signature:
get model(): this;

Coinfer.onDeleteAccessToken() method

Signature:
onDeleteAccessToken(): Promise<void>;
Returns: Promise<void>

Coinfer.onError() method

This method is called when an error occurs, such as authentication failure Signature:
onError(err: any): void;

Parameters

ParameterTypeDescription
errany
Returns: void

Coinfer.onSavedAccessToken property

login with token Signature:
onSavedAccessToken: (any: any) => void;

Coinfer.run() method

Warning: This API is now obsolete. Run a model, please instead it of runWithLambda.
Signature:
run(params: ICoinferRunModelProps): Promise<unknown>;

Parameters

ParameterTypeDescription
paramsICoinferRunModelProps
Returns: Promise<unknown>

Example 1

const res = await coinfer.model.run(params);
Alternatively, this method is invoked within useCoinferAction.

Example 2

const [result, runningModel, isRunningLoading] = useCoinferAction((params) => coinferjs?.model.run(params), [coinferjs]);

Coinfer.runBatch() method

Warning: This API is now obsolete. Run some models in batches, please instead it of runWithLambda.
Signature:
runBatch(params: IVectorlyRunModelProps[]): Promise<IModelRunInBatchResult>;

Parameters

ParameterTypeDescription
paramsIVectorlyRunModelProps[]
Returns: Promise<IModelRunInBatchResult>

Example 1

const res = await coinfer.model.run([
  {}
]);
Alternatively, this method is invoked within useCoinferAction.

Example 2

const [result, runningModel, isRunningLoading] = useCoinferAction((params) => coinferjs?.model.run(params), [coinferjs]);

Coinfer.runWithLambda() method

Run Model through lamdba Signature:
runWithLambda(...models: IModelConfigInLambda[]): Promise<IRunLambdaRes['data'] | IRunLambdaBatchRes['data']>;

Parameters

ParameterTypeDescription
modelsIModelConfigInLambda[]
Returns: Promise<IRunLambdaRes[‘data’] | IRunLambdaBatchRes[‘data’]>

Coinfer.saveAccessToken() method

After successful login, the method of storing the authorization code. Signature:
saveAccessToken(token: any): Promise<any>;

Parameters

ParameterTypeDescription
tokenany
Returns: Promise<any>

Coinfer.setAccessToken() method

Set or update the authorization token. Signature:
setAccessToken(token: string): void;

Parameters

ParameterTypeDescription
tokenstring
Returns: void

Coinfer.setConfig() method

Set config for Coinfer. Signature:
setConfig(config: Partial<ICoinferConfig>): void;

Parameters

ParameterTypeDescription
configPartial<ICoinferConfig>
Returns: void

Coinfer.task property

Signature:
get task(): this;

Coinfer.token property

Signature:
get token(): this;

Coinfer.update() method

Signature:
update(payload: ICoinferCommonPutProps): Promise<unknown>;

Parameters

ParameterTypeDescription
payloadICoinferCommonPutProps
Returns: Promise<unknown>

Coinfer.websocket property

Signature:
get websocket(): this;

CoinferContext variable

Coinferjs’s Context Signature:
CoinferContext: any

Example

You can invoke it in App.tsx or App.jsx.
<CoinferContext.Provider value={{ coinferjs: coinferjsInst }}>
  <Outlet />
</CoinferContext.Provider>

ExperimentSocketActionTypes type

The type of data obtained from the WebSocket. Signature:
type ExperimentSocketActionTypes$1 = 
  | IExperimentSocketPlotDataActionType$1
  | IExperimentSocketFinishedActionType$1
  | IExperimentSocketErrorActionType$1
  | IExperimentSocketLogActionType$1
  | IExperimentSocketNamesActionType$1
  | IExperimentSocketExtraActionType$1
  | IExperimentErrorActionType$1
References: IExperimentSocketPlotDataActionType$1, IExperimentSocketLogActionType$1, IExperimentSocketNamesActionType$1

FetchFunctionReturnType type

Signature:
type FetchFunctionReturnType$1<T> = [T | undefined, (...data: any[]) => Promise<T>, boolean];

FetchFunctionType type

Signature:
type FetchFunctionType$1 = <T = any>(cfAction: (...parms: any[]) => any, dependencies: any[]) => FetchFunctionReturnType$1<T>;
References: FetchFunctionReturnType$1

IExperimentSocketLogActionType.data property

Signature:
data: string

IExperimentSocketLogActionType interface

The data type of the log information obtained from WebSocket. Signature:
interface IExperimentSocketLogActionType$1 extends IReduceActionWithKV$1<'experiment:output', {data: string}>
Extends: IReduceActionWithKV$1<‘experiment:output’, {data: string}>

Properties

PropertyModifiersTypeDescription
datastring

IExperimentSocketNamesActionType.data property

Signature:
data: IChainNameType$1[]

IExperimentSocketNamesActionType interface

After establishing the connection on the backend (requiring version: ‘1.0’), the data returned once includes the Chains and all known Variable names under each Chain. Signature:
interface IExperimentSocketNamesActionType$1 extends IReduceActionWithKV$1<'names', {data: IChainNameType$1[]}>
Extends: IReduceActionWithKV$1<‘names’, {data: IChainNameType$1[]}>

Properties

PropertyModifiersTypeDescription
dataIChainNameType$1[]

IExperimentSocketPlotDataActionType.data property

Signature:
data: {[key: string]: any[]}

IExperimentSocketPlotDataActionType interface

The plot data obtained from the WebSocket. Signature:
interface IExperimentSocketPlotDataActionType$1 extends IReduceActionWithKV$1<'experiment:event', {data: {[key: string]: any[]}}>
Extends: IReduceActionWithKV$1<‘experiment:event’, {data: {[key: string]: any[]}}>

Properties

PropertyModifiersTypeDescription
data{[key: string]: any[]}

ISuperLogsType.logs property

Signature:
logs: [number, string]

ISuperLogsType interface

The logs for the super user. Signature:
interface ISuperLogsType$1 

Properties

PropertyModifiersTypeDescription
logs[number, string]

IUserInfoType.id property

Signature:
id: number

IUserInfoType.is_github_user property

Signature:
is_github_user: boolean

IUserInfoType interface

The userInfo structure. Signature:
interface IUserInfoType 

Properties

PropertyModifiersTypeDescription
idnumber
is_github_userboolean
superboolean
usernamestring

IUserInfoType.super property

Signature:
super: boolean

IUserInfoType.username property

Signature:
username: string

useCoinfer() function

A hook used to retrieve the Coinfer instance within CoinferContext. Signature:
useCoinfer: () => Coinfer | null
Returns: Coinfer | null

Example

Here’s an example :
// ...
const cf = useCoinfer();

useCoinferAction variable

A hook for invoking the coinferJS feature using a more convenient method. Signature:
useCoinferAction: FetchFunctionType

Example

const [models, fetchModels, isloading] = useCoinferAction(params => cf?.model.list(params.page_no, params.page_size), [cf]);
fetchModels({page_no: 1, page_size: 10});

useExperimentWebSocket variable

You can use this hook to access the WebSocket connection of the Experiment. Signature:
useExperimentWebSocket: UseExperimentWebSocketType

Example

const { replaySubject, addWebSocketListener, removeWebSocketListener, send } = useExperimentWebSocket(baseInfo.url, baseInfo.token);

useNewCoinfer variable

Signature:
useNewCoinfer: UseNewCoinferType