@langchain/core 0.2.26 → 0.2.28
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/prompts/chat.cjs +31 -5
- package/dist/prompts/chat.js +31 -5
- package/dist/prompts/image.cjs +13 -0
- package/dist/prompts/image.d.ts +13 -0
- package/dist/prompts/image.js +13 -0
- package/dist/prompts/prompt.cjs +12 -0
- package/dist/prompts/prompt.d.ts +13 -1
- package/dist/prompts/prompt.js +12 -0
- package/dist/tools/index.d.ts +5 -0
- 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 +15 -2
|
@@ -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/prompts/chat.cjs
CHANGED
|
@@ -305,7 +305,13 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
305
305
|
else if (typeof item.text === "string") {
|
|
306
306
|
text = item.text ?? "";
|
|
307
307
|
}
|
|
308
|
-
|
|
308
|
+
const options = {
|
|
309
|
+
...additionalOptions,
|
|
310
|
+
...(typeof item !== "string"
|
|
311
|
+
? { additionalContentFields: item }
|
|
312
|
+
: {}),
|
|
313
|
+
};
|
|
314
|
+
prompt.push(prompt_js_1.PromptTemplate.fromTemplate(text, options));
|
|
309
315
|
}
|
|
310
316
|
else if (typeof item === "object" && "image_url" in item) {
|
|
311
317
|
let imgTemplate = item.image_url ?? "";
|
|
@@ -334,6 +340,7 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
334
340
|
template: imgTemplate,
|
|
335
341
|
inputVariables,
|
|
336
342
|
templateFormat: additionalOptions?.templateFormat,
|
|
343
|
+
additionalContentFields: item,
|
|
337
344
|
});
|
|
338
345
|
}
|
|
339
346
|
else if (typeof imgTemplate === "object") {
|
|
@@ -354,6 +361,7 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
354
361
|
template: imgTemplate,
|
|
355
362
|
inputVariables,
|
|
356
363
|
templateFormat: additionalOptions?.templateFormat,
|
|
364
|
+
additionalContentFields: item,
|
|
357
365
|
});
|
|
358
366
|
}
|
|
359
367
|
else {
|
|
@@ -387,13 +395,31 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
387
395
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
388
396
|
if (prompt instanceof string_js_1.BaseStringPromptTemplate) {
|
|
389
397
|
const formatted = await prompt.format(inputs);
|
|
390
|
-
|
|
398
|
+
let additionalContentFields;
|
|
399
|
+
if ("additionalContentFields" in prompt) {
|
|
400
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
401
|
+
additionalContentFields = prompt.additionalContentFields;
|
|
402
|
+
}
|
|
403
|
+
content.push({
|
|
404
|
+
...additionalContentFields,
|
|
405
|
+
type: "text",
|
|
406
|
+
text: formatted,
|
|
407
|
+
});
|
|
391
408
|
/** @TODO replace this */
|
|
392
409
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
393
410
|
}
|
|
394
411
|
else if (prompt instanceof image_js_1.ImagePromptTemplate) {
|
|
395
412
|
const formatted = await prompt.format(inputs);
|
|
396
|
-
|
|
413
|
+
let additionalContentFields;
|
|
414
|
+
if ("additionalContentFields" in prompt) {
|
|
415
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
416
|
+
additionalContentFields = prompt.additionalContentFields;
|
|
417
|
+
}
|
|
418
|
+
content.push({
|
|
419
|
+
...additionalContentFields,
|
|
420
|
+
type: "image_url",
|
|
421
|
+
image_url: formatted,
|
|
422
|
+
});
|
|
397
423
|
}
|
|
398
424
|
}
|
|
399
425
|
return this.createMessage(content);
|
|
@@ -491,10 +517,10 @@ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike, extra) {
|
|
|
491
517
|
// Assuming message.content is an array of complex objects, transform it.
|
|
492
518
|
templateData = message.content.map((item) => {
|
|
493
519
|
if ("text" in item) {
|
|
494
|
-
return { text: item.text };
|
|
520
|
+
return { ...item, text: item.text };
|
|
495
521
|
}
|
|
496
522
|
else if ("image_url" in item) {
|
|
497
|
-
return { image_url: item.image_url };
|
|
523
|
+
return { ...item, image_url: item.image_url };
|
|
498
524
|
}
|
|
499
525
|
else {
|
|
500
526
|
return item;
|
package/dist/prompts/chat.js
CHANGED
|
@@ -297,7 +297,13 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
297
297
|
else if (typeof item.text === "string") {
|
|
298
298
|
text = item.text ?? "";
|
|
299
299
|
}
|
|
300
|
-
|
|
300
|
+
const options = {
|
|
301
|
+
...additionalOptions,
|
|
302
|
+
...(typeof item !== "string"
|
|
303
|
+
? { additionalContentFields: item }
|
|
304
|
+
: {}),
|
|
305
|
+
};
|
|
306
|
+
prompt.push(PromptTemplate.fromTemplate(text, options));
|
|
301
307
|
}
|
|
302
308
|
else if (typeof item === "object" && "image_url" in item) {
|
|
303
309
|
let imgTemplate = item.image_url ?? "";
|
|
@@ -326,6 +332,7 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
326
332
|
template: imgTemplate,
|
|
327
333
|
inputVariables,
|
|
328
334
|
templateFormat: additionalOptions?.templateFormat,
|
|
335
|
+
additionalContentFields: item,
|
|
329
336
|
});
|
|
330
337
|
}
|
|
331
338
|
else if (typeof imgTemplate === "object") {
|
|
@@ -346,6 +353,7 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
346
353
|
template: imgTemplate,
|
|
347
354
|
inputVariables,
|
|
348
355
|
templateFormat: additionalOptions?.templateFormat,
|
|
356
|
+
additionalContentFields: item,
|
|
349
357
|
});
|
|
350
358
|
}
|
|
351
359
|
else {
|
|
@@ -379,13 +387,31 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
|
|
|
379
387
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
380
388
|
if (prompt instanceof BaseStringPromptTemplate) {
|
|
381
389
|
const formatted = await prompt.format(inputs);
|
|
382
|
-
|
|
390
|
+
let additionalContentFields;
|
|
391
|
+
if ("additionalContentFields" in prompt) {
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
393
|
+
additionalContentFields = prompt.additionalContentFields;
|
|
394
|
+
}
|
|
395
|
+
content.push({
|
|
396
|
+
...additionalContentFields,
|
|
397
|
+
type: "text",
|
|
398
|
+
text: formatted,
|
|
399
|
+
});
|
|
383
400
|
/** @TODO replace this */
|
|
384
401
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
385
402
|
}
|
|
386
403
|
else if (prompt instanceof ImagePromptTemplate) {
|
|
387
404
|
const formatted = await prompt.format(inputs);
|
|
388
|
-
|
|
405
|
+
let additionalContentFields;
|
|
406
|
+
if ("additionalContentFields" in prompt) {
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
408
|
+
additionalContentFields = prompt.additionalContentFields;
|
|
409
|
+
}
|
|
410
|
+
content.push({
|
|
411
|
+
...additionalContentFields,
|
|
412
|
+
type: "image_url",
|
|
413
|
+
image_url: formatted,
|
|
414
|
+
});
|
|
389
415
|
}
|
|
390
416
|
}
|
|
391
417
|
return this.createMessage(content);
|
|
@@ -480,10 +506,10 @@ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike, extra) {
|
|
|
480
506
|
// Assuming message.content is an array of complex objects, transform it.
|
|
481
507
|
templateData = message.content.map((item) => {
|
|
482
508
|
if ("text" in item) {
|
|
483
|
-
return { text: item.text };
|
|
509
|
+
return { ...item, text: item.text };
|
|
484
510
|
}
|
|
485
511
|
else if ("image_url" in item) {
|
|
486
|
-
return { image_url: item.image_url };
|
|
512
|
+
return { ...item, image_url: item.image_url };
|
|
487
513
|
}
|
|
488
514
|
else {
|
|
489
515
|
return item;
|
package/dist/prompts/image.cjs
CHANGED
|
@@ -37,9 +37,22 @@ class ImagePromptTemplate extends base_js_1.BasePromptTemplate {
|
|
|
37
37
|
writable: true,
|
|
38
38
|
value: true
|
|
39
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Additional fields which should be included inside
|
|
42
|
+
* the message content array if using a complex message
|
|
43
|
+
* content.
|
|
44
|
+
*/
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
Object.defineProperty(this, "additionalContentFields", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
40
52
|
this.template = input.template;
|
|
41
53
|
this.templateFormat = input.templateFormat ?? this.templateFormat;
|
|
42
54
|
this.validateTemplate = input.validateTemplate ?? this.validateTemplate;
|
|
55
|
+
this.additionalContentFields = input.additionalContentFields;
|
|
43
56
|
if (this.validateTemplate) {
|
|
44
57
|
let totalInputVariables = this.inputVariables;
|
|
45
58
|
if (this.partialVariables) {
|
package/dist/prompts/image.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageContentComplex } from "../messages/index.js";
|
|
1
2
|
import { ImagePromptValue, ImageContent } from "../prompt_values.js";
|
|
2
3
|
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
3
4
|
import { BasePromptTemplate, BasePromptTemplateInput, TypedPromptInputValues } from "./base.js";
|
|
@@ -23,6 +24,12 @@ export interface ImagePromptTemplateInput<RunInput extends InputValues = any, Pa
|
|
|
23
24
|
* @defaultValue `true`
|
|
24
25
|
*/
|
|
25
26
|
validateTemplate?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Additional fields which should be included inside
|
|
29
|
+
* the message content array if using a complex message
|
|
30
|
+
* content.
|
|
31
|
+
*/
|
|
32
|
+
additionalContentFields?: MessageContentComplex;
|
|
26
33
|
}
|
|
27
34
|
/**
|
|
28
35
|
* An image prompt template for a multimodal model.
|
|
@@ -33,6 +40,12 @@ export declare class ImagePromptTemplate<RunInput extends InputValues = any, Par
|
|
|
33
40
|
template: Record<string, unknown>;
|
|
34
41
|
templateFormat: TemplateFormat;
|
|
35
42
|
validateTemplate: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Additional fields which should be included inside
|
|
45
|
+
* the message content array if using a complex message
|
|
46
|
+
* content.
|
|
47
|
+
*/
|
|
48
|
+
additionalContentFields?: MessageContentComplex;
|
|
36
49
|
constructor(input: ImagePromptTemplateInput<RunInput, PartialVariableName>);
|
|
37
50
|
_getPromptType(): "prompt";
|
|
38
51
|
/**
|
package/dist/prompts/image.js
CHANGED
|
@@ -34,9 +34,22 @@ export class ImagePromptTemplate extends BasePromptTemplate {
|
|
|
34
34
|
writable: true,
|
|
35
35
|
value: true
|
|
36
36
|
});
|
|
37
|
+
/**
|
|
38
|
+
* Additional fields which should be included inside
|
|
39
|
+
* the message content array if using a complex message
|
|
40
|
+
* content.
|
|
41
|
+
*/
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
Object.defineProperty(this, "additionalContentFields", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: void 0
|
|
48
|
+
});
|
|
37
49
|
this.template = input.template;
|
|
38
50
|
this.templateFormat = input.templateFormat ?? this.templateFormat;
|
|
39
51
|
this.validateTemplate = input.validateTemplate ?? this.validateTemplate;
|
|
52
|
+
this.additionalContentFields = input.additionalContentFields;
|
|
40
53
|
if (this.validateTemplate) {
|
|
41
54
|
let totalInputVariables = this.inputVariables;
|
|
42
55
|
if (this.partialVariables) {
|
package/dist/prompts/prompt.cjs
CHANGED
|
@@ -44,6 +44,18 @@ class PromptTemplate extends string_js_1.BaseStringPromptTemplate {
|
|
|
44
44
|
writable: true,
|
|
45
45
|
value: true
|
|
46
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* Additional fields which should be included inside
|
|
49
|
+
* the message content array if using a complex message
|
|
50
|
+
* content.
|
|
51
|
+
*/
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
Object.defineProperty(this, "additionalContentFields", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
47
59
|
// If input is mustache and validateTemplate is not defined, set it to false
|
|
48
60
|
if (input.templateFormat === "mustache" &&
|
|
49
61
|
input.validateTemplate === undefined) {
|
package/dist/prompts/prompt.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { BasePromptTemplateInput, TypedPromptInputValues } from "./base.js"
|
|
|
3
3
|
import { type TemplateFormat } from "./template.js";
|
|
4
4
|
import type { SerializedPromptTemplate } from "./serde.js";
|
|
5
5
|
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
6
|
-
import { MessageContent } from "../messages/index.js";
|
|
6
|
+
import { MessageContent, MessageContentComplex } from "../messages/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Inputs to create a {@link PromptTemplate}
|
|
9
9
|
* @augments BasePromptTemplateInput
|
|
@@ -23,6 +23,12 @@ export interface PromptTemplateInput<RunInput extends InputValues = any, Partial
|
|
|
23
23
|
* @defaultValue `true`
|
|
24
24
|
*/
|
|
25
25
|
validateTemplate?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Additional fields which should be included inside
|
|
28
|
+
* the message content array if using a complex message
|
|
29
|
+
* content.
|
|
30
|
+
*/
|
|
31
|
+
additionalContentFields?: MessageContentComplex;
|
|
26
32
|
}
|
|
27
33
|
type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" | "`" | ":" | ";";
|
|
28
34
|
/**
|
|
@@ -55,6 +61,12 @@ export declare class PromptTemplate<RunInput extends InputValues = any, PartialV
|
|
|
55
61
|
template: MessageContent;
|
|
56
62
|
templateFormat: TemplateFormat;
|
|
57
63
|
validateTemplate: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Additional fields which should be included inside
|
|
66
|
+
* the message content array if using a complex message
|
|
67
|
+
* content.
|
|
68
|
+
*/
|
|
69
|
+
additionalContentFields?: MessageContentComplex;
|
|
58
70
|
constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);
|
|
59
71
|
_getPromptType(): "prompt";
|
|
60
72
|
/**
|
package/dist/prompts/prompt.js
CHANGED
|
@@ -41,6 +41,18 @@ export class PromptTemplate extends BaseStringPromptTemplate {
|
|
|
41
41
|
writable: true,
|
|
42
42
|
value: true
|
|
43
43
|
});
|
|
44
|
+
/**
|
|
45
|
+
* Additional fields which should be included inside
|
|
46
|
+
* the message content array if using a complex message
|
|
47
|
+
* content.
|
|
48
|
+
*/
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
Object.defineProperty(this, "additionalContentFields", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
44
56
|
// If input is mustache and validateTemplate is not defined, set it to false
|
|
45
57
|
if (input.templateFormat === "mustache" &&
|
|
46
58
|
input.validateTemplate === undefined) {
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ export interface ToolParams extends BaseLangChainParams {
|
|
|
26
26
|
*/
|
|
27
27
|
responseFormat?: ResponseFormat;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Schema for defining tools.
|
|
31
|
+
*
|
|
32
|
+
* @version 0.2.19
|
|
33
|
+
*/
|
|
29
34
|
export interface StructuredToolParams extends Pick<StructuredToolInterface, "name" | "schema"> {
|
|
30
35
|
/**
|
|
31
36
|
* An optional description of the tool to pass to the model.
|
|
@@ -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.28",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"camelcase": "6",
|
|
46
46
|
"decamelize": "1.2.0",
|
|
47
47
|
"js-tiktoken": "^1.0.12",
|
|
48
|
-
"langsmith": "
|
|
48
|
+
"langsmith": "^0.1.43",
|
|
49
49
|
"mustache": "^4.2.0",
|
|
50
50
|
"p-queue": "^6.6.2",
|
|
51
51
|
"p-retry": "4",
|
|
@@ -186,6 +186,15 @@
|
|
|
186
186
|
"import": "./document_loaders/base.js",
|
|
187
187
|
"require": "./document_loaders/base.cjs"
|
|
188
188
|
},
|
|
189
|
+
"./document_loaders/langsmith": {
|
|
190
|
+
"types": {
|
|
191
|
+
"import": "./document_loaders/langsmith.d.ts",
|
|
192
|
+
"require": "./document_loaders/langsmith.d.cts",
|
|
193
|
+
"default": "./document_loaders/langsmith.d.ts"
|
|
194
|
+
},
|
|
195
|
+
"import": "./document_loaders/langsmith.js",
|
|
196
|
+
"require": "./document_loaders/langsmith.cjs"
|
|
197
|
+
},
|
|
189
198
|
"./embeddings": {
|
|
190
199
|
"types": {
|
|
191
200
|
"import": "./embeddings.d.ts",
|
|
@@ -653,6 +662,10 @@
|
|
|
653
662
|
"document_loaders/base.js",
|
|
654
663
|
"document_loaders/base.d.ts",
|
|
655
664
|
"document_loaders/base.d.cts",
|
|
665
|
+
"document_loaders/langsmith.cjs",
|
|
666
|
+
"document_loaders/langsmith.js",
|
|
667
|
+
"document_loaders/langsmith.d.ts",
|
|
668
|
+
"document_loaders/langsmith.d.cts",
|
|
656
669
|
"embeddings.cjs",
|
|
657
670
|
"embeddings.js",
|
|
658
671
|
"embeddings.d.ts",
|