@langchain/core 0.2.27 → 0.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document_loaders/langsmith.cjs +198 -0
- package/dist/document_loaders/langsmith.d.ts +96 -0
- package/dist/document_loaders/langsmith.js +194 -0
- package/dist/messages/utils.cjs +8 -0
- package/dist/messages/utils.js +8 -0
- package/dist/runnables/graph.cjs +10 -7
- package/dist/runnables/graph.js +10 -7
- package/dist/tools/index.cjs +15 -1
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.js +15 -1
- package/document_loaders/langsmith.cjs +1 -0
- package/document_loaders/langsmith.d.cts +1 -0
- package/document_loaders/langsmith.d.ts +1 -0
- package/document_loaders/langsmith.js +1 -0
- package/package.json +18 -13
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LangSmithLoader = void 0;
|
|
4
|
+
const langsmith_1 = require("langsmith");
|
|
5
|
+
const base_js_1 = require("./base.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Document loader integration with LangSmith.
|
|
8
|
+
*
|
|
9
|
+
* ## [Constructor args](https://api.js.langchain.com/interfaces/_langchain_core.document_loaders_langsmith.LangSmithLoaderFields.html)
|
|
10
|
+
*
|
|
11
|
+
* <details open>
|
|
12
|
+
* <summary><strong>Load</strong></summary>
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { LangSmithLoader } from '@langchain/core/document_loaders/langsmith';
|
|
16
|
+
* import { Client } from 'langsmith';
|
|
17
|
+
*
|
|
18
|
+
* const langSmithClient = new Client({
|
|
19
|
+
* apiKey: process.env.LANGSMITH_API_KEY,
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* const loader = new LangSmithLoader({
|
|
23
|
+
* datasetId: "9a3b36f7-b308-40a5-9b46-6613853b6330",
|
|
24
|
+
* limit: 1,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const docs = await loader.load();
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* ```txt
|
|
31
|
+
* [
|
|
32
|
+
* {
|
|
33
|
+
* pageContent: '{\n "input_key_str": "string",\n "input_key_bool": true\n}',
|
|
34
|
+
* metadata: {
|
|
35
|
+
* id: '8523d9e9-c123-4b23-9b46-21021nds289e',
|
|
36
|
+
* created_at: '2024-08-19T17:09:14.806441+00:00',
|
|
37
|
+
* modified_at: '2024-08-19T17:09:14.806441+00:00',
|
|
38
|
+
* name: '#8517 @ brace-test-dataset',
|
|
39
|
+
* dataset_id: '9a3b36f7-b308-40a5-9b46-6613853b6330',
|
|
40
|
+
* source_run_id: null,
|
|
41
|
+
* metadata: [Object],
|
|
42
|
+
* inputs: [Object],
|
|
43
|
+
* outputs: [Object]
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ]
|
|
47
|
+
* ```
|
|
48
|
+
* </details>
|
|
49
|
+
*/
|
|
50
|
+
class LangSmithLoader extends base_js_1.BaseDocumentLoader {
|
|
51
|
+
constructor(fields) {
|
|
52
|
+
super();
|
|
53
|
+
Object.defineProperty(this, "datasetId", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "datasetName", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "exampleIds", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "asOf", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: void 0
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "splits", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "inlineS3Urls", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: void 0
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "offset", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: void 0
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "limit", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(this, "metadata", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: void 0
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "filter", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: void 0
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "contentKey", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: void 0
|
|
118
|
+
});
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
Object.defineProperty(this, "formatContent", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value: void 0
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(this, "client", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true,
|
|
129
|
+
writable: true,
|
|
130
|
+
value: void 0
|
|
131
|
+
});
|
|
132
|
+
if (fields.client && fields.clientConfig) {
|
|
133
|
+
throw new Error("client and clientConfig cannot both be provided.");
|
|
134
|
+
}
|
|
135
|
+
this.client = fields.client ?? new langsmith_1.Client(fields?.clientConfig);
|
|
136
|
+
this.contentKey = fields.contentKey ? fields.contentKey.split(".") : [];
|
|
137
|
+
this.formatContent = fields.formatContent ?? _stringify;
|
|
138
|
+
this.datasetId = fields.datasetId;
|
|
139
|
+
this.datasetName = fields.datasetName;
|
|
140
|
+
this.exampleIds = fields.exampleIds;
|
|
141
|
+
this.asOf = fields.asOf;
|
|
142
|
+
this.splits = fields.splits;
|
|
143
|
+
this.inlineS3Urls = fields.inlineS3Urls;
|
|
144
|
+
this.offset = fields.offset;
|
|
145
|
+
this.limit = fields.limit;
|
|
146
|
+
this.metadata = fields.metadata;
|
|
147
|
+
this.filter = fields.filter;
|
|
148
|
+
}
|
|
149
|
+
async load() {
|
|
150
|
+
const documents = [];
|
|
151
|
+
for await (const example of this.client.listExamples({
|
|
152
|
+
datasetId: this.datasetId,
|
|
153
|
+
datasetName: this.datasetName,
|
|
154
|
+
exampleIds: this.exampleIds,
|
|
155
|
+
asOf: this.asOf,
|
|
156
|
+
splits: this.splits,
|
|
157
|
+
inlineS3Urls: this.inlineS3Urls,
|
|
158
|
+
offset: this.offset,
|
|
159
|
+
limit: this.limit,
|
|
160
|
+
metadata: this.metadata,
|
|
161
|
+
filter: this.filter,
|
|
162
|
+
})) {
|
|
163
|
+
let content = example.inputs;
|
|
164
|
+
for (const key of this.contentKey) {
|
|
165
|
+
content = content[key];
|
|
166
|
+
}
|
|
167
|
+
const contentStr = this.formatContent(content);
|
|
168
|
+
const metadata = example;
|
|
169
|
+
["created_at", "modified_at"].forEach((k) => {
|
|
170
|
+
if (k in metadata) {
|
|
171
|
+
if (typeof metadata[k] === "object") {
|
|
172
|
+
// Dates are of type `object`, we want to convert them to strings.
|
|
173
|
+
metadata[k] = metadata[k].toString();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
documents.push({
|
|
178
|
+
pageContent: contentStr,
|
|
179
|
+
metadata,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return documents;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.LangSmithLoader = LangSmithLoader;
|
|
186
|
+
function _stringify(x) {
|
|
187
|
+
if (typeof x === "string") {
|
|
188
|
+
return x;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
try {
|
|
192
|
+
return JSON.stringify(x, null, 2);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
return String(x);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { KVMap } from "langsmith/schemas";
|
|
2
|
+
import { Client } from "langsmith";
|
|
3
|
+
import { Document } from "../documents/document.js";
|
|
4
|
+
import { AsyncCallerParams } from "../utils/async_caller.js";
|
|
5
|
+
import { BaseDocumentLoader } from "./base.js";
|
|
6
|
+
interface ClientConfig {
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
callerOptions?: AsyncCallerParams;
|
|
10
|
+
timeout_ms?: number;
|
|
11
|
+
webUrl?: string;
|
|
12
|
+
anonymizer?: (values: KVMap) => KVMap;
|
|
13
|
+
hideInputs?: boolean | ((inputs: KVMap) => KVMap);
|
|
14
|
+
hideOutputs?: boolean | ((outputs: KVMap) => KVMap);
|
|
15
|
+
autoBatchTracing?: boolean;
|
|
16
|
+
pendingAutoBatchedRunLimit?: number;
|
|
17
|
+
fetchOptions?: RequestInit;
|
|
18
|
+
}
|
|
19
|
+
export interface LangSmithLoaderFields {
|
|
20
|
+
datasetId?: string;
|
|
21
|
+
datasetName?: string;
|
|
22
|
+
exampleIds?: Array<string>;
|
|
23
|
+
asOf?: Date | string;
|
|
24
|
+
splits?: string[];
|
|
25
|
+
inlineS3Urls?: boolean;
|
|
26
|
+
offset?: number;
|
|
27
|
+
limit?: number;
|
|
28
|
+
metadata?: KVMap;
|
|
29
|
+
filter?: string;
|
|
30
|
+
contentKey?: string;
|
|
31
|
+
formatContent?: (content: any) => string;
|
|
32
|
+
client?: Client;
|
|
33
|
+
clientConfig?: ClientConfig;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Document loader integration with LangSmith.
|
|
37
|
+
*
|
|
38
|
+
* ## [Constructor args](https://api.js.langchain.com/interfaces/_langchain_core.document_loaders_langsmith.LangSmithLoaderFields.html)
|
|
39
|
+
*
|
|
40
|
+
* <details open>
|
|
41
|
+
* <summary><strong>Load</strong></summary>
|
|
42
|
+
*
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { LangSmithLoader } from '@langchain/core/document_loaders/langsmith';
|
|
45
|
+
* import { Client } from 'langsmith';
|
|
46
|
+
*
|
|
47
|
+
* const langSmithClient = new Client({
|
|
48
|
+
* apiKey: process.env.LANGSMITH_API_KEY,
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* const loader = new LangSmithLoader({
|
|
52
|
+
* datasetId: "9a3b36f7-b308-40a5-9b46-6613853b6330",
|
|
53
|
+
* limit: 1,
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* const docs = await loader.load();
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* ```txt
|
|
60
|
+
* [
|
|
61
|
+
* {
|
|
62
|
+
* pageContent: '{\n "input_key_str": "string",\n "input_key_bool": true\n}',
|
|
63
|
+
* metadata: {
|
|
64
|
+
* id: '8523d9e9-c123-4b23-9b46-21021nds289e',
|
|
65
|
+
* created_at: '2024-08-19T17:09:14.806441+00:00',
|
|
66
|
+
* modified_at: '2024-08-19T17:09:14.806441+00:00',
|
|
67
|
+
* name: '#8517 @ brace-test-dataset',
|
|
68
|
+
* dataset_id: '9a3b36f7-b308-40a5-9b46-6613853b6330',
|
|
69
|
+
* source_run_id: null,
|
|
70
|
+
* metadata: [Object],
|
|
71
|
+
* inputs: [Object],
|
|
72
|
+
* outputs: [Object]
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ]
|
|
76
|
+
* ```
|
|
77
|
+
* </details>
|
|
78
|
+
*/
|
|
79
|
+
export declare class LangSmithLoader extends BaseDocumentLoader {
|
|
80
|
+
datasetId?: string;
|
|
81
|
+
datasetName?: string;
|
|
82
|
+
exampleIds?: Array<string>;
|
|
83
|
+
asOf?: Date | string;
|
|
84
|
+
splits?: string[];
|
|
85
|
+
inlineS3Urls?: boolean;
|
|
86
|
+
offset?: number;
|
|
87
|
+
limit?: number;
|
|
88
|
+
metadata?: KVMap;
|
|
89
|
+
filter?: string;
|
|
90
|
+
contentKey: string[];
|
|
91
|
+
formatContent: (content: any) => string;
|
|
92
|
+
client: Client;
|
|
93
|
+
constructor(fields: LangSmithLoaderFields);
|
|
94
|
+
load(): Promise<Document[]>;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Client } from "langsmith";
|
|
2
|
+
import { BaseDocumentLoader } from "./base.js";
|
|
3
|
+
/**
|
|
4
|
+
* Document loader integration with LangSmith.
|
|
5
|
+
*
|
|
6
|
+
* ## [Constructor args](https://api.js.langchain.com/interfaces/_langchain_core.document_loaders_langsmith.LangSmithLoaderFields.html)
|
|
7
|
+
*
|
|
8
|
+
* <details open>
|
|
9
|
+
* <summary><strong>Load</strong></summary>
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { LangSmithLoader } from '@langchain/core/document_loaders/langsmith';
|
|
13
|
+
* import { Client } from 'langsmith';
|
|
14
|
+
*
|
|
15
|
+
* const langSmithClient = new Client({
|
|
16
|
+
* apiKey: process.env.LANGSMITH_API_KEY,
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* const loader = new LangSmithLoader({
|
|
20
|
+
* datasetId: "9a3b36f7-b308-40a5-9b46-6613853b6330",
|
|
21
|
+
* limit: 1,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const docs = await loader.load();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ```txt
|
|
28
|
+
* [
|
|
29
|
+
* {
|
|
30
|
+
* pageContent: '{\n "input_key_str": "string",\n "input_key_bool": true\n}',
|
|
31
|
+
* metadata: {
|
|
32
|
+
* id: '8523d9e9-c123-4b23-9b46-21021nds289e',
|
|
33
|
+
* created_at: '2024-08-19T17:09:14.806441+00:00',
|
|
34
|
+
* modified_at: '2024-08-19T17:09:14.806441+00:00',
|
|
35
|
+
* name: '#8517 @ brace-test-dataset',
|
|
36
|
+
* dataset_id: '9a3b36f7-b308-40a5-9b46-6613853b6330',
|
|
37
|
+
* source_run_id: null,
|
|
38
|
+
* metadata: [Object],
|
|
39
|
+
* inputs: [Object],
|
|
40
|
+
* outputs: [Object]
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ]
|
|
44
|
+
* ```
|
|
45
|
+
* </details>
|
|
46
|
+
*/
|
|
47
|
+
export class LangSmithLoader extends BaseDocumentLoader {
|
|
48
|
+
constructor(fields) {
|
|
49
|
+
super();
|
|
50
|
+
Object.defineProperty(this, "datasetId", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "datasetName", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "exampleIds", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "asOf", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: void 0
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(this, "splits", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "inlineS3Urls", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: void 0
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(this, "offset", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: void 0
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this, "limit", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: void 0
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(this, "metadata", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: void 0
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(this, "filter", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
writable: true,
|
|
108
|
+
value: void 0
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(this, "contentKey", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
configurable: true,
|
|
113
|
+
writable: true,
|
|
114
|
+
value: void 0
|
|
115
|
+
});
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
+
Object.defineProperty(this, "formatContent", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
writable: true,
|
|
121
|
+
value: void 0
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(this, "client", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: true,
|
|
126
|
+
writable: true,
|
|
127
|
+
value: void 0
|
|
128
|
+
});
|
|
129
|
+
if (fields.client && fields.clientConfig) {
|
|
130
|
+
throw new Error("client and clientConfig cannot both be provided.");
|
|
131
|
+
}
|
|
132
|
+
this.client = fields.client ?? new Client(fields?.clientConfig);
|
|
133
|
+
this.contentKey = fields.contentKey ? fields.contentKey.split(".") : [];
|
|
134
|
+
this.formatContent = fields.formatContent ?? _stringify;
|
|
135
|
+
this.datasetId = fields.datasetId;
|
|
136
|
+
this.datasetName = fields.datasetName;
|
|
137
|
+
this.exampleIds = fields.exampleIds;
|
|
138
|
+
this.asOf = fields.asOf;
|
|
139
|
+
this.splits = fields.splits;
|
|
140
|
+
this.inlineS3Urls = fields.inlineS3Urls;
|
|
141
|
+
this.offset = fields.offset;
|
|
142
|
+
this.limit = fields.limit;
|
|
143
|
+
this.metadata = fields.metadata;
|
|
144
|
+
this.filter = fields.filter;
|
|
145
|
+
}
|
|
146
|
+
async load() {
|
|
147
|
+
const documents = [];
|
|
148
|
+
for await (const example of this.client.listExamples({
|
|
149
|
+
datasetId: this.datasetId,
|
|
150
|
+
datasetName: this.datasetName,
|
|
151
|
+
exampleIds: this.exampleIds,
|
|
152
|
+
asOf: this.asOf,
|
|
153
|
+
splits: this.splits,
|
|
154
|
+
inlineS3Urls: this.inlineS3Urls,
|
|
155
|
+
offset: this.offset,
|
|
156
|
+
limit: this.limit,
|
|
157
|
+
metadata: this.metadata,
|
|
158
|
+
filter: this.filter,
|
|
159
|
+
})) {
|
|
160
|
+
let content = example.inputs;
|
|
161
|
+
for (const key of this.contentKey) {
|
|
162
|
+
content = content[key];
|
|
163
|
+
}
|
|
164
|
+
const contentStr = this.formatContent(content);
|
|
165
|
+
const metadata = example;
|
|
166
|
+
["created_at", "modified_at"].forEach((k) => {
|
|
167
|
+
if (k in metadata) {
|
|
168
|
+
if (typeof metadata[k] === "object") {
|
|
169
|
+
// Dates are of type `object`, we want to convert them to strings.
|
|
170
|
+
metadata[k] = metadata[k].toString();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
documents.push({
|
|
175
|
+
pageContent: contentStr,
|
|
176
|
+
metadata,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return documents;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function _stringify(x) {
|
|
183
|
+
if (typeof x === "string") {
|
|
184
|
+
return x;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
try {
|
|
188
|
+
return JSON.stringify(x, null, 2);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
return String(x);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
package/dist/messages/utils.cjs
CHANGED
|
@@ -19,6 +19,14 @@ function _constructMessageFromParams(params) {
|
|
|
19
19
|
else if (type === "system") {
|
|
20
20
|
return new system_js_1.SystemMessage(rest);
|
|
21
21
|
}
|
|
22
|
+
else if (type === "tool" && "tool_call_id" in rest) {
|
|
23
|
+
return new tool_js_1.ToolMessage({
|
|
24
|
+
...rest,
|
|
25
|
+
content: rest.content,
|
|
26
|
+
tool_call_id: rest.tool_call_id,
|
|
27
|
+
name: rest.name,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
22
30
|
else {
|
|
23
31
|
throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
|
|
24
32
|
}
|
package/dist/messages/utils.js
CHANGED
|
@@ -16,6 +16,14 @@ function _constructMessageFromParams(params) {
|
|
|
16
16
|
else if (type === "system") {
|
|
17
17
|
return new SystemMessage(rest);
|
|
18
18
|
}
|
|
19
|
+
else if (type === "tool" && "tool_call_id" in rest) {
|
|
20
|
+
return new ToolMessage({
|
|
21
|
+
...rest,
|
|
22
|
+
content: rest.content,
|
|
23
|
+
tool_call_id: rest.tool_call_id,
|
|
24
|
+
name: rest.name,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
19
27
|
else {
|
|
20
28
|
throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
|
|
21
29
|
}
|
package/dist/runnables/graph.cjs
CHANGED
|
@@ -72,16 +72,19 @@ class Graph {
|
|
|
72
72
|
id: stableNodeIds[node.id],
|
|
73
73
|
...nodeDataJson(node),
|
|
74
74
|
})),
|
|
75
|
-
edges: this.edges.map((edge) =>
|
|
76
|
-
|
|
75
|
+
edges: this.edges.map((edge) => {
|
|
76
|
+
const item = {
|
|
77
77
|
source: stableNodeIds[edge.source],
|
|
78
78
|
target: stableNodeIds[edge.target],
|
|
79
|
-
|
|
79
|
+
};
|
|
80
|
+
if (typeof edge.data !== "undefined") {
|
|
81
|
+
item.data = edge.data;
|
|
80
82
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
if (typeof edge.conditional !== "undefined") {
|
|
84
|
+
item.conditional = edge.conditional;
|
|
85
|
+
}
|
|
86
|
+
return item;
|
|
87
|
+
}),
|
|
85
88
|
};
|
|
86
89
|
}
|
|
87
90
|
addNode(data, id) {
|
package/dist/runnables/graph.js
CHANGED
|
@@ -69,16 +69,19 @@ export class Graph {
|
|
|
69
69
|
id: stableNodeIds[node.id],
|
|
70
70
|
...nodeDataJson(node),
|
|
71
71
|
})),
|
|
72
|
-
edges: this.edges.map((edge) =>
|
|
73
|
-
|
|
72
|
+
edges: this.edges.map((edge) => {
|
|
73
|
+
const item = {
|
|
74
74
|
source: stableNodeIds[edge.source],
|
|
75
75
|
target: stableNodeIds[edge.target],
|
|
76
|
-
|
|
76
|
+
};
|
|
77
|
+
if (typeof edge.data !== "undefined") {
|
|
78
|
+
item.data = edge.data;
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (typeof edge.conditional !== "undefined") {
|
|
81
|
+
item.conditional = edge.conditional;
|
|
82
|
+
}
|
|
83
|
+
return item;
|
|
84
|
+
}),
|
|
82
85
|
};
|
|
83
86
|
}
|
|
84
87
|
addNode(data, id) {
|
package/dist/tools/index.cjs
CHANGED
|
@@ -25,6 +25,13 @@ class StructuredTool extends base_js_1.BaseLangChain {
|
|
|
25
25
|
writable: true,
|
|
26
26
|
value: false
|
|
27
27
|
});
|
|
28
|
+
// TODO: Make default in 0.3
|
|
29
|
+
Object.defineProperty(this, "verboseParsingErrors", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: false
|
|
34
|
+
});
|
|
28
35
|
/**
|
|
29
36
|
* The tool response format.
|
|
30
37
|
*
|
|
@@ -40,6 +47,8 @@ class StructuredTool extends base_js_1.BaseLangChain {
|
|
|
40
47
|
writable: true,
|
|
41
48
|
value: "content"
|
|
42
49
|
});
|
|
50
|
+
this.verboseParsingErrors =
|
|
51
|
+
fields?.verboseParsingErrors ?? this.verboseParsingErrors;
|
|
43
52
|
this.responseFormat = fields?.responseFormat ?? this.responseFormat;
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
@@ -84,9 +93,14 @@ class StructuredTool extends base_js_1.BaseLangChain {
|
|
|
84
93
|
let parsed;
|
|
85
94
|
try {
|
|
86
95
|
parsed = await this.schema.parseAsync(arg);
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
97
|
}
|
|
88
98
|
catch (e) {
|
|
89
|
-
|
|
99
|
+
let message = `Received tool input did not match expected schema`;
|
|
100
|
+
if (this.verboseParsingErrors) {
|
|
101
|
+
message = `${message}\nDetails: ${e.message}`;
|
|
102
|
+
}
|
|
103
|
+
throw new utils_js_1.ToolInputParsingException(message, JSON.stringify(arg));
|
|
90
104
|
}
|
|
91
105
|
const config = (0, manager_js_1.parseCallbackConfigArg)(configArg);
|
|
92
106
|
const callbackManager_ = await manager_js_1.CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -25,7 +25,18 @@ export interface ToolParams extends BaseLangChainParams {
|
|
|
25
25
|
* @default "content"
|
|
26
26
|
*/
|
|
27
27
|
responseFormat?: ResponseFormat;
|
|
28
|
+
/**
|
|
29
|
+
* Whether to show full details in the thrown parsing errors.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
verboseParsingErrors?: boolean;
|
|
28
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Schema for defining tools.
|
|
37
|
+
*
|
|
38
|
+
* @version 0.2.19
|
|
39
|
+
*/
|
|
29
40
|
export interface StructuredToolParams extends Pick<StructuredToolInterface, "name" | "schema"> {
|
|
30
41
|
/**
|
|
31
42
|
* An optional description of the tool to pass to the model.
|
|
@@ -70,6 +81,7 @@ export declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectA
|
|
|
70
81
|
abstract description: string;
|
|
71
82
|
abstract schema: T | z.ZodEffects<T>;
|
|
72
83
|
returnDirect: boolean;
|
|
84
|
+
verboseParsingErrors: boolean;
|
|
73
85
|
get lc_namespace(): string[];
|
|
74
86
|
/**
|
|
75
87
|
* The tool response format.
|
package/dist/tools/index.js
CHANGED
|
@@ -22,6 +22,13 @@ export class StructuredTool extends BaseLangChain {
|
|
|
22
22
|
writable: true,
|
|
23
23
|
value: false
|
|
24
24
|
});
|
|
25
|
+
// TODO: Make default in 0.3
|
|
26
|
+
Object.defineProperty(this, "verboseParsingErrors", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: false
|
|
31
|
+
});
|
|
25
32
|
/**
|
|
26
33
|
* The tool response format.
|
|
27
34
|
*
|
|
@@ -37,6 +44,8 @@ export class StructuredTool extends BaseLangChain {
|
|
|
37
44
|
writable: true,
|
|
38
45
|
value: "content"
|
|
39
46
|
});
|
|
47
|
+
this.verboseParsingErrors =
|
|
48
|
+
fields?.verboseParsingErrors ?? this.verboseParsingErrors;
|
|
40
49
|
this.responseFormat = fields?.responseFormat ?? this.responseFormat;
|
|
41
50
|
}
|
|
42
51
|
/**
|
|
@@ -81,9 +90,14 @@ export class StructuredTool extends BaseLangChain {
|
|
|
81
90
|
let parsed;
|
|
82
91
|
try {
|
|
83
92
|
parsed = await this.schema.parseAsync(arg);
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
94
|
}
|
|
85
95
|
catch (e) {
|
|
86
|
-
|
|
96
|
+
let message = `Received tool input did not match expected schema`;
|
|
97
|
+
if (this.verboseParsingErrors) {
|
|
98
|
+
message = `${message}\nDetails: ${e.message}`;
|
|
99
|
+
}
|
|
100
|
+
throw new ToolInputParsingException(message, JSON.stringify(arg));
|
|
87
101
|
}
|
|
88
102
|
const config = parseCallbackConfigArg(configArg);
|
|
89
103
|
const callbackManager_ = await CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/document_loaders/langsmith.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/document_loaders/langsmith.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/document_loaders/langsmith.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/document_loaders/langsmith.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.29",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -15,13 +15,8 @@
|
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/langchain-core/",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "yarn turbo:command build:internal --filter=@langchain/core",
|
|
18
|
-
"build:internal": "yarn
|
|
18
|
+
"build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
|
|
19
19
|
"clean": "rm -rf .turbo dist/",
|
|
20
|
-
"build:deps": "yarn turbo build",
|
|
21
|
-
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests",
|
|
22
|
-
"build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
|
|
23
|
-
"build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
|
|
24
|
-
"build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
|
|
25
20
|
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
26
21
|
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
27
22
|
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
@@ -33,10 +28,7 @@
|
|
|
33
28
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
34
29
|
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
35
30
|
"format": "prettier --config .prettierrc --write \"src\"",
|
|
36
|
-
"format:check": "prettier --config .prettierrc --check \"src\""
|
|
37
|
-
"move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
|
|
38
|
-
"create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
|
|
39
|
-
"check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
|
|
31
|
+
"format:check": "prettier --config .prettierrc --check \"src\""
|
|
40
32
|
},
|
|
41
33
|
"author": "LangChain",
|
|
42
34
|
"license": "MIT",
|
|
@@ -45,7 +37,7 @@
|
|
|
45
37
|
"camelcase": "6",
|
|
46
38
|
"decamelize": "1.2.0",
|
|
47
39
|
"js-tiktoken": "^1.0.12",
|
|
48
|
-
"langsmith": "
|
|
40
|
+
"langsmith": "^0.1.43",
|
|
49
41
|
"mustache": "^4.2.0",
|
|
50
42
|
"p-queue": "^6.6.2",
|
|
51
43
|
"p-retry": "4",
|
|
@@ -55,7 +47,7 @@
|
|
|
55
47
|
},
|
|
56
48
|
"devDependencies": {
|
|
57
49
|
"@jest/globals": "^29.5.0",
|
|
58
|
-
"@langchain/scripts": "
|
|
50
|
+
"@langchain/scripts": ">=0.1.0 <0.2.0",
|
|
59
51
|
"@swc/core": "^1.3.90",
|
|
60
52
|
"@swc/jest": "^0.2.29",
|
|
61
53
|
"@types/decamelize": "^1.2.0",
|
|
@@ -186,6 +178,15 @@
|
|
|
186
178
|
"import": "./document_loaders/base.js",
|
|
187
179
|
"require": "./document_loaders/base.cjs"
|
|
188
180
|
},
|
|
181
|
+
"./document_loaders/langsmith": {
|
|
182
|
+
"types": {
|
|
183
|
+
"import": "./document_loaders/langsmith.d.ts",
|
|
184
|
+
"require": "./document_loaders/langsmith.d.cts",
|
|
185
|
+
"default": "./document_loaders/langsmith.d.ts"
|
|
186
|
+
},
|
|
187
|
+
"import": "./document_loaders/langsmith.js",
|
|
188
|
+
"require": "./document_loaders/langsmith.cjs"
|
|
189
|
+
},
|
|
189
190
|
"./embeddings": {
|
|
190
191
|
"types": {
|
|
191
192
|
"import": "./embeddings.d.ts",
|
|
@@ -653,6 +654,10 @@
|
|
|
653
654
|
"document_loaders/base.js",
|
|
654
655
|
"document_loaders/base.d.ts",
|
|
655
656
|
"document_loaders/base.d.cts",
|
|
657
|
+
"document_loaders/langsmith.cjs",
|
|
658
|
+
"document_loaders/langsmith.js",
|
|
659
|
+
"document_loaders/langsmith.d.ts",
|
|
660
|
+
"document_loaders/langsmith.d.cts",
|
|
656
661
|
"embeddings.cjs",
|
|
657
662
|
"embeddings.js",
|
|
658
663
|
"embeddings.d.ts",
|