Function interfaces(函数接口(Function interfaces))¶
Function interfaces allow function authors to integrate their custom logic with native Foundry features and offer a powerful way of defining contracts between consuming applications and functions.
Function interfaces define how an application or user should interact with a function. This includes the function’s inputs, outputs, and errors. In other words, a function interface describes a function’s signature, but a function interface is not itself a function. Function interfaces are designed to be implemented by functions.
Some Foundry applications use function interfaces to provide specialized behavior when executing functions which implement the interface, given the known inputs, outputs, and errors. Users can provide their own implementations of certain function interfaces, and Foundry can continue providing this specialized behavior. Applications within Foundry which depend on certain function interfaces can discover all functions which implement that interface.
For example, AIP Logic depends on function interfaces to allow users to bring their own LLMs into Logic functions. Specifically, the Use LLM block in AIP Logic allows users to select Palantir-provided LLMs or registered LLMs. Registered models are user-authored functions that have implemented a function interface provided by Foundry; for instance, the chat completion function interface. This allows AIP Logic to discover functions that have been explicitly defined as being an implementation of a chat completion, have a signature typical of a generic LLM, and return errors which AIP Logic can handle appropriately. In the future, user-provided chat completion implementations will be usable in other parts of the platform, such as Pipeline Builder and Model Catalog.
Learn how to register LLMs with the registered models feature. For the legacy method using function interfaces, see Register an LLM using function interfaces [Legacy].
Palantir-provided function interfaces¶
The following list contains the function interfaces currently provided by Palantir:
ChatCompletion¶
Description:
- Functions which generate contextually relevant text responses based on multi-turn and multi-user text conversation history.
- Ideal for conversational use cases.
Foundry integrations:
- The Use LLM board in AIP Logic.
- Support in Pipeline Builder coming soon.
Documentation:
Type customization¶
To provide more flexibility, you are not limited to the provided types when implementing a function interface. In some cases, you may want to create your own custom types. As long as a function is compatible ↗ with the function defined on the function interface, the function will be accepted by the compiler and successfully published. If the function interface defines an input type for which all fields are optional, at least one common optional field must be shared when customizing the type.
...
interface CustomParams extends GenericCompletionParams {
modelSpecificParam?: string
}
...
// valid implementation
@ChatCompletion()
public async myRegisteredModel(
messages: FunctionsGenericChatCompletionRequestMessages,
params: CustomParams
): Promise<FunctionsGenericChatCompletionResponse> {
...
}
Troubleshooting¶
Function interfaces are designed to be flexible and allow for a wide range of implementations. However, you may encounter errors when implementing a function interface. Here are some tips for TypeScript functions to help you avoid these errors when customizing your implementation.
Error: Function input name does not match the required input name of the function interface at the specific input position¶
The input names of each parameter must match the input names defined on the function interface at each specific input position. As the linting suggests, ensure that each input name has the exact same input name as declared on the function interface at each position.

Error: Function is missing input parameter of the function interface¶
This error arises if the implementing function does not include every required input defined on the function interface. To resolve the error, ensure each input declared on the function interface is included in the implementing function.

Error: Type {type1} is not assignable to type {type2}¶
The compiler may reject the implementing function as not compatible with the function defined on the interface. If so, ensure your implementing function is compatible ↗ with the function defined on the function interface by checking the structure of each type compared to the types defined on the function interface.

中文翻译¶
函数接口(Function interfaces)¶
函数接口允许函数作者将其自定义逻辑与 Foundry 原生功能集成,并为消费应用与函数之间定义契约提供了一种强大方式。
函数接口定义了应用或用户应如何与函数交互,包括函数的输入、输出和错误。换言之,函数接口描述了函数的签名,但其本身并非函数。函数接口旨在由函数实现。
某些 Foundry 应用利用函数接口,在已知输入、输出和错误的前提下,为执行实现该接口的函数提供专门行为。用户可以为特定函数接口提供自己的实现,而 Foundry 可继续提供这种专门行为。依赖特定函数接口的 Foundry 应用能够发现所有实现了该接口的函数。
例如,AIP Logic 依赖函数接口让用户将自己的 LLM 引入 Logic 函数。具体来说,AIP Logic 中的使用 LLM 模块允许用户选择 Palantir 提供的 LLM 或已注册的 LLM。已注册模型是用户自行编写的函数,这些函数实现了 Foundry 提供的函数接口,例如聊天补全(chat completion)函数接口。这使得 AIP Logic 能够发现那些被明确定义为聊天补全实现、具有通用 LLM 典型签名,并能返回 AIP Logic 可适当处理的错误的函数。未来,用户提供的聊天补全实现将可在平台其他部分(如 Pipeline Builder 和模型目录)中使用。
了解如何使用已注册模型功能注册 LLM。 关于使用函数接口的旧版方法,请参阅使用函数接口注册 LLM [旧版]。
Palantir 提供的函数接口¶
以下列表包含 Palantir 当前提供的函数接口:
ChatCompletion¶
描述:
- 基于多轮、多用户文本对话历史生成上下文相关文本响应的函数。
- 适用于对话场景。
Foundry 集成:
- AIP Logic 中的使用 LLM 模块。
- Pipeline Builder 支持即将推出。
文档:
类型自定义¶
为提供更高灵活性,实现函数接口时您不限于使用提供的类型。在某些情况下,您可能希望创建自己的自定义类型。只要函数与函数接口上定义的函数兼容 ↗,编译器就会接受该函数并成功发布。如果函数接口定义了一个所有字段均为可选的输入类型,则在自定义类型时必须至少共享一个公共可选字段。
...
interface CustomParams extends GenericCompletionParams {
modelSpecificParam?: string
}
...
// 有效实现
@ChatCompletion()
public async myRegisteredModel(
messages: FunctionsGenericChatCompletionRequestMessages,
params: CustomParams
): Promise<FunctionsGenericChatCompletionResponse> {
...
}
故障排除¶
函数接口设计灵活,允许广泛的实现方式。但在实现函数接口时仍可能遇到错误。以下是一些针对 TypeScript 函数的提示,帮助您在自定义实现时避免这些错误。
错误:函数输入名称与函数接口在特定输入位置要求的输入名称不匹配¶
每个参数的输入名称必须与函数接口在每个特定输入位置定义的输入名称匹配。如代码检查提示所示,请确保每个输入名称与函数接口在每个位置声明的输入名称完全一致。

错误:函数缺少函数接口的输入参数¶
如果实现函数未包含函数接口定义的每个必需输入,则会出现此错误。要解决该错误,请确保实现函数包含函数接口声明的所有输入。

错误:类型 {type1} 无法分配给类型 {type2}¶
编译器可能因实现函数与接口定义的函数不兼容而拒绝该函数。如果出现此情况,请通过检查每个类型与函数接口定义类型的结构对比,确保您的实现函数与函数接口定义的函数兼容 ↗。
