数据集转换
LangSmith 允许您将转换附加到数据集模式中的字段,这些转换会在数据通过 UI、API 或运行规则添加到数据集之前应用于您的数据。
与 LangSmith 的预构建 JSON Schema 类型 配合使用,这些功能允许您在将数据保存到数据集之前轻松地进行预处理。
转换类型
| 转换类型 | 目标类型 | 功能 |
|---|---|---|
| remove_system_messages | Array[Message] | Filters a list of messages to remove any system messages. |
| convert_to_openai_message | Message Array[Message] | Converts any incoming data from LangChain's internal serialization format to OpenAI's standard message format using langchain's convert_to_openai_messages. If the target field is marked as required, and no matching message is found upon entry, it will attempt to extract a message (or list of messages) from several well-known LangSmith tracing formats (e.g., any traced LangChain BaseChatModel run or traced run from the LangSmith OpenAI wrapper), and remove the original key containing the message. |
| convert_to_openai_tool | Array[Tool] Only available on top level fields in the inputs dictionary. | Converts any incoming data into OpenAI standard tool formats here using langchain's convert_to_openai_tool Will extract tool definitions from a run's invocation parameters if present / no tools are found at the specified key. This is useful because LangChain chat models trace tool definitions to the extra.invocation_params field of the run rather than inputs. |
| remove_extra_fields | Object | Removes any field not defined in the schema for this target object. |
Chat Model 预构建架构
转换的主要用例是简化将生产跟踪收集到数据集中,以便以跨模型提供商标准化的格式用于下游评估/少样本提示等。
为了简化我们最终用户进行转换的设置,LangSmith 提供了一个预定义的架构,它将执行以下操作:
- 从您收集的运行中提取消息,并将其转换为 OpenAI 标准格式,使其与所有 LangChain ChatModels 以及大多数模型提供商的 SDK 兼容,从而支持下游评估和实验
- 提取您的 LLM 所使用的任何工具,并将其添加到示例的输入中以用于下游评估的可复现性
提示
用户若希望对其系统提示词进行迭代,在使用我们的 Chat Model schema 时,通常还会在输入消息上添加“移除系统消息”转换,这将防止您将系统提示词保存到数据集中。
兼容性
LLM 运行集合架构旨在从 LangChain BaseChatModel 运行或来自 LangSmith OpenAI 包装器 的追踪运行中收集数据。
如果您有无法兼容的 LLM 运行跟踪任务,请通过 support@langchain.dev 与我们联系,我们将为您扩展支持。
如果您希望对其他类型的运行应用转换(例如,用消息历史表示 LangGraph 状态),请直接定义您的模式并手动添加相关转换。
赋能
当从追踪项目或注释队列将运行添加到数据集时,如果它具有 LLM 运行类型,我们将默认应用 Chat Model 架构。
关于新数据集的启用,请参阅我们的数据集管理操操作指南。
规格
对于预构建模式的完整 API 规范,请参阅以下章节:
输入模式
{
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"$ref": "https://api.smith.langchain.com/public/schemas/v1/message.json"
}
},
"tools": {
"type": "array",
"items": {
"$ref": "https://api.smith.langchain.com/public/schemas/v1/tooldef.json"
}
}
},
"required": ["messages"]
}
输出架构
{
"type": "object",
"properties": {
"message": {
"$ref": "https://api.smith.langchain.com/public/schemas/v1/message.json"
}
},
"required": ["message"]
}
转换
转换结果如下:
[
{
"path": ["inputs"],
"transformation_type": "remove_extra_fields"
},
{
"path": ["inputs", "messages"],
"transformation_type": "convert_to_openai_message"
},
{
"path": ["inputs", "tools"],
"transformation_type": "convert_to_openai_tool"
},
{
"path": ["outputs"],
"transformation_type": "remove_extra_fields"
},
{
"path": ["outputs", "message"],
"transformation_type": "convert_to_openai_message"
}
]