Functions on models(模型函数)¶
You can deploy models as functions to enable live usage of models in end-user applications like Workshop, Slate, Actions, and more. Model functions can also be used in other functions to write custom business logic involving the model in code.
Publish a function for your model¶
Functions can be published for models with a live deployment configured, or for Modeling Objectives live deployments.
Learn more about how to configure and manage model functions.
Call a model function in code¶
Below is a simplified example of a function that calls a live deployment that takes an input Double[] and returns a Double[] output called output_df in the model API:
import { Function, Double } from "@foundry/functions-api";
import { ModelDeployment } from "@foundry/models-api/deployments";
@Function()
public async predictValues(inputs: Double[]): Promise<Double[]> {
const modelOutput = await ModelDeployment(inputs);
return modelOutput.output_df;
}
Learn more about how to use model functions in other functions.
中文翻译¶
模型函数¶
您可以将模型部署为函数,以便在最终用户应用程序中实时使用模型,例如 Workshop、Slate、Actions 以及更多应用。模型函数还可以在其他函数中使用,以便在代码中编写涉及模型的定制业务逻辑。
为模型发布函数¶
函数可以为已配置实时部署的模型发布,也可以为 Modeling Objectives 实时部署发布。
在代码中调用模型函数¶
以下是一个简化示例,展示了一个调用实时部署的函数,该部署接收一个 Double[] 输入,并在模型 API 中返回一个名为 output_df 的 Double[] 输出:
import { Function, Double } from "@foundry/functions-api";
import { ModelDeployment } from "@foundry/models-api/deployments";
@Function()
public async predictValues(inputs: Double[]): Promise<Double[]> {
const modelOutput = await ModelDeployment(inputs);
return modelOutput.output_df;
}