跳至主要内容

LangSmithLoader

此笔记本提供了一个快速入门指南,用于介绍如何使用 LangSmithLoader。有关所有 LangSmithLoader 功能和配置的详细文档,请转至 API 参考

概述

集成详细信息

本地可序列化PY 支持
LangSmithLoader@langchain/communitybeta

加载器功能

网络加载器仅限 Node 环境
LangSmithLoader

设置

要访问 LangSmith 文档加载器,您需要安装 @langchain/core,创建一个 LangSmith 帐户并获取 API 密钥。

凭据

https://langsmith.com 上注册并生成一个 API 密钥。完成后,设置 LANGSMITH_API_KEY 环境变量

export LANGSMITH_API_KEY="your-api-key"

安装

LangSmithLoader 集成位于 @langchain/core 包中

yarn add @langchain/core

创建示例数据集

在本例中,我们将创建一个新数据集,我们将在文档加载器中使用它。

import { Client as LangSmithClient } from "langsmith";
import { faker } from "@faker-js/faker";

const lsClient = new LangSmithClient();

const datasetName = "LangSmith Few Shot Datasets Notebook";

const exampleInputs = Array.from({ length: 10 }, (_, i) => ({
input: faker.lorem.paragraph(),
}));
const exampleOutputs = Array.from({ length: 10 }, (_, i) => ({
output: faker.lorem.sentence(),
}));
const exampleMetadata = Array.from({ length: 10 }, (_, i) => ({
companyCatchPhrase: faker.company.catchPhrase(),
}));

await lsClient.deleteDataset({
datasetName,
});

const dataset = await lsClient.createDataset(datasetName);

const examples = await lsClient.createExamples({
inputs: exampleInputs,
outputs: exampleOutputs,
metadata: exampleMetadata,
datasetId: dataset.id,
});
import { LangSmithLoader } from "@langchain/core/document_loaders/langsmith";

const loader = new LangSmithLoader({
datasetName: "LangSmith Few Shot Datasets Notebook",
// Instead of a datasetName, you can alternatively provide a datasetId
// datasetId: dataset.id,
contentKey: "input",
limit: 5,
// formatContent: (content) => content,
// ... other options
});

加载

const docs = await loader.load();
docs[0];
{
pageContent: 'Conventus supellex aegrotatio termes. Vapulus abscido ubi vita coadunatio modi crapula comparo caecus. Acervus voluptate tergeo pariatur conor argumentum inventore vomito stella.',
metadata: {
id: 'f1a04800-6f7a-4232-9743-fb5d9029bf1f',
created_at: '2024-08-20T17:01:38.984045+00:00',
modified_at: '2024-08-20T17:01:38.984045+00:00',
name: '#f1a0 @ LangSmith Few Shot Datasets Notebook',
dataset_id: '9ccd66e6-e506-478c-9095-3d9e27575a89',
source_run_id: null,
metadata: {
dataset_split: [Array],
companyCatchPhrase: 'Integrated solution-oriented secured line'
},
inputs: {
input: 'Conventus supellex aegrotatio termes. Vapulus abscido ubi vita coadunatio modi crapula comparo caecus. Acervus voluptate tergeo pariatur conor argumentum inventore vomito stella.'
},
outputs: {
output: 'Excepturi adeptio spectaculum bis volaticus accusamus.'
}
}
}
console.log(docs[0].metadata);
{
id: 'f1a04800-6f7a-4232-9743-fb5d9029bf1f',
created_at: '2024-08-20T17:01:38.984045+00:00',
modified_at: '2024-08-20T17:01:38.984045+00:00',
name: '#f1a0 @ LangSmith Few Shot Datasets Notebook',
dataset_id: '9ccd66e6-e506-478c-9095-3d9e27575a89',
source_run_id: null,
metadata: {
dataset_split: [ 'base' ],
companyCatchPhrase: 'Integrated solution-oriented secured line'
},
inputs: {
input: 'Conventus supellex aegrotatio termes. Vapulus abscido ubi vita coadunatio modi crapula comparo caecus. Acervus voluptate tergeo pariatur conor argumentum inventore vomito stella.'
},
outputs: { output: 'Excepturi adeptio spectaculum bis volaticus accusamus.' }
}
console.log(docs[0].metadata.inputs);
{
input: 'Conventus supellex aegrotatio termes. Vapulus abscido ubi vita coadunatio modi crapula comparo caecus. Acervus voluptate tergeo pariatur conor argumentum inventore vomito stella.'
}
console.log(docs[0].metadata.outputs);
{ output: 'Excepturi adeptio spectaculum bis volaticus accusamus.' }
console.log(Object.keys(docs[0].metadata));
[
'id',
'created_at',
'modified_at',
'name',
'dataset_id',
'source_run_id',
'metadata',
'inputs',
'outputs'
]

API 参考

有关所有 LangSmithLoader 功能和配置的详细文档,请转至 API 参考


此页面对您有帮助吗?


您也可以在 GitHub 上留下详细的反馈 GitHub.