langsmith 0.3.42 → 0.3.43
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/client.cjs +41 -10
- package/dist/client.d.ts +1 -0
- package/dist/client.js +41 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -202,6 +202,7 @@ exports.AutoBatchQueue = AutoBatchQueue;
|
|
|
202
202
|
// 20 MB
|
|
203
203
|
exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20_971_520;
|
|
204
204
|
const SERVER_INFO_REQUEST_TIMEOUT = 2500;
|
|
205
|
+
const DEFAULT_API_URL = "https://api.smith.langchain.com";
|
|
205
206
|
class Client {
|
|
206
207
|
constructor(config = {}) {
|
|
207
208
|
Object.defineProperty(this, "apiKey", {
|
|
@@ -349,6 +350,12 @@ class Client {
|
|
|
349
350
|
writable: true,
|
|
350
351
|
value: void 0
|
|
351
352
|
});
|
|
353
|
+
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
354
|
+
enumerable: true,
|
|
355
|
+
configurable: true,
|
|
356
|
+
writable: true,
|
|
357
|
+
value: false
|
|
358
|
+
});
|
|
352
359
|
Object.defineProperty(this, "debug", {
|
|
353
360
|
enumerable: true,
|
|
354
361
|
configurable: true,
|
|
@@ -400,8 +407,7 @@ class Client {
|
|
|
400
407
|
}
|
|
401
408
|
static getDefaultClientConfig() {
|
|
402
409
|
const apiKey = (0, env_js_1.getLangSmithEnvironmentVariable)("API_KEY");
|
|
403
|
-
const apiUrl = (0, env_js_1.getLangSmithEnvironmentVariable)("ENDPOINT") ??
|
|
404
|
-
"https://api.smith.langchain.com";
|
|
410
|
+
const apiUrl = (0, env_js_1.getLangSmithEnvironmentVariable)("ENDPOINT") ?? DEFAULT_API_URL;
|
|
405
411
|
const hideInputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_INPUTS") === "true";
|
|
406
412
|
const hideOutputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_OUTPUTS") === "true";
|
|
407
413
|
return {
|
|
@@ -1117,12 +1123,12 @@ class Client {
|
|
|
1117
1123
|
return stream;
|
|
1118
1124
|
}
|
|
1119
1125
|
async _sendMultipartRequest(parts, context, options) {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
+
// Create multipart form data boundary
|
|
1127
|
+
const boundary = "----LangSmithFormBoundary" + Math.random().toString(36).slice(2);
|
|
1128
|
+
const isNodeFetch = (0, fetch_js_1._globalFetchImplementationIsNodeFetch)();
|
|
1129
|
+
const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
|
|
1130
|
+
const buildStream = () => this._createMultipartStream(parts, boundary);
|
|
1131
|
+
const send = async (body) => {
|
|
1126
1132
|
const headers = {
|
|
1127
1133
|
...this.headers,
|
|
1128
1134
|
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
@@ -1130,7 +1136,7 @@ class Client {
|
|
|
1130
1136
|
if (options?.apiKey !== undefined) {
|
|
1131
1137
|
headers["x-api-key"] = options.apiKey;
|
|
1132
1138
|
}
|
|
1133
|
-
|
|
1139
|
+
return this.batchIngestCaller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${options?.apiUrl ?? this.apiUrl}/runs/multipart`, {
|
|
1134
1140
|
method: "POST",
|
|
1135
1141
|
headers,
|
|
1136
1142
|
body,
|
|
@@ -1138,6 +1144,31 @@ class Client {
|
|
|
1138
1144
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1139
1145
|
...this.fetchOptions,
|
|
1140
1146
|
});
|
|
1147
|
+
};
|
|
1148
|
+
try {
|
|
1149
|
+
let res;
|
|
1150
|
+
let streamedAttempt = false;
|
|
1151
|
+
// attempt stream only if not disabled and not using node-fetch
|
|
1152
|
+
if (!isNodeFetch && !this.multipartStreamingDisabled) {
|
|
1153
|
+
streamedAttempt = true;
|
|
1154
|
+
res = await send(await buildStream());
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
res = await send(await buildBuffered());
|
|
1158
|
+
}
|
|
1159
|
+
// if stream fails, fallback to buffered body
|
|
1160
|
+
if ((!this.multipartStreamingDisabled || streamedAttempt) &&
|
|
1161
|
+
res.status === 422 &&
|
|
1162
|
+
(options?.apiUrl ?? this.apiUrl) !== DEFAULT_API_URL) {
|
|
1163
|
+
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. ` +
|
|
1164
|
+
`This usually means the host does not support chunked uploads. ` +
|
|
1165
|
+
`Retrying with a buffered upload for operation "${context}".`);
|
|
1166
|
+
// Disable streaming for future requests
|
|
1167
|
+
this.multipartStreamingDisabled = true;
|
|
1168
|
+
// retry with fully-buffered body
|
|
1169
|
+
res = await send(await buildBuffered());
|
|
1170
|
+
}
|
|
1171
|
+
// raise if still failing
|
|
1141
1172
|
await (0, error_js_1.raiseForStatus)(res, "ingest multipart runs", true);
|
|
1142
1173
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1143
1174
|
}
|
|
@@ -3122,7 +3153,7 @@ class Client {
|
|
|
3122
3153
|
const settings = await this._getSettings();
|
|
3123
3154
|
if (options?.isPublic && !settings.tenant_handle) {
|
|
3124
3155
|
throw new Error(`Cannot create a public prompt without first\n
|
|
3125
|
-
creating a LangChain Hub handle.
|
|
3156
|
+
creating a LangChain Hub handle.
|
|
3126
3157
|
You can add a handle by creating a public prompt at:\n
|
|
3127
3158
|
https://smith.langchain.com/prompts`);
|
|
3128
3159
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -312,6 +312,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
312
312
|
private _getServerInfoPromise?;
|
|
313
313
|
private manualFlushMode;
|
|
314
314
|
private langSmithToOTELTranslator?;
|
|
315
|
+
private multipartStreamingDisabled;
|
|
315
316
|
debug: boolean;
|
|
316
317
|
constructor(config?: ClientConfig);
|
|
317
318
|
static getDefaultClientConfig(): {
|
package/dist/client.js
CHANGED
|
@@ -164,6 +164,7 @@ export class AutoBatchQueue {
|
|
|
164
164
|
// 20 MB
|
|
165
165
|
export const DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20_971_520;
|
|
166
166
|
const SERVER_INFO_REQUEST_TIMEOUT = 2500;
|
|
167
|
+
const DEFAULT_API_URL = "https://api.smith.langchain.com";
|
|
167
168
|
export class Client {
|
|
168
169
|
constructor(config = {}) {
|
|
169
170
|
Object.defineProperty(this, "apiKey", {
|
|
@@ -311,6 +312,12 @@ export class Client {
|
|
|
311
312
|
writable: true,
|
|
312
313
|
value: void 0
|
|
313
314
|
});
|
|
315
|
+
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
316
|
+
enumerable: true,
|
|
317
|
+
configurable: true,
|
|
318
|
+
writable: true,
|
|
319
|
+
value: false
|
|
320
|
+
});
|
|
314
321
|
Object.defineProperty(this, "debug", {
|
|
315
322
|
enumerable: true,
|
|
316
323
|
configurable: true,
|
|
@@ -362,8 +369,7 @@ export class Client {
|
|
|
362
369
|
}
|
|
363
370
|
static getDefaultClientConfig() {
|
|
364
371
|
const apiKey = getLangSmithEnvironmentVariable("API_KEY");
|
|
365
|
-
const apiUrl = getLangSmithEnvironmentVariable("ENDPOINT") ??
|
|
366
|
-
"https://api.smith.langchain.com";
|
|
372
|
+
const apiUrl = getLangSmithEnvironmentVariable("ENDPOINT") ?? DEFAULT_API_URL;
|
|
367
373
|
const hideInputs = getLangSmithEnvironmentVariable("HIDE_INPUTS") === "true";
|
|
368
374
|
const hideOutputs = getLangSmithEnvironmentVariable("HIDE_OUTPUTS") === "true";
|
|
369
375
|
return {
|
|
@@ -1079,12 +1085,12 @@ export class Client {
|
|
|
1079
1085
|
return stream;
|
|
1080
1086
|
}
|
|
1081
1087
|
async _sendMultipartRequest(parts, context, options) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
+
// Create multipart form data boundary
|
|
1089
|
+
const boundary = "----LangSmithFormBoundary" + Math.random().toString(36).slice(2);
|
|
1090
|
+
const isNodeFetch = _globalFetchImplementationIsNodeFetch();
|
|
1091
|
+
const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
|
|
1092
|
+
const buildStream = () => this._createMultipartStream(parts, boundary);
|
|
1093
|
+
const send = async (body) => {
|
|
1088
1094
|
const headers = {
|
|
1089
1095
|
...this.headers,
|
|
1090
1096
|
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
@@ -1092,7 +1098,7 @@ export class Client {
|
|
|
1092
1098
|
if (options?.apiKey !== undefined) {
|
|
1093
1099
|
headers["x-api-key"] = options.apiKey;
|
|
1094
1100
|
}
|
|
1095
|
-
|
|
1101
|
+
return this.batchIngestCaller.call(_getFetchImplementation(this.debug), `${options?.apiUrl ?? this.apiUrl}/runs/multipart`, {
|
|
1096
1102
|
method: "POST",
|
|
1097
1103
|
headers,
|
|
1098
1104
|
body,
|
|
@@ -1100,6 +1106,31 @@ export class Client {
|
|
|
1100
1106
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1101
1107
|
...this.fetchOptions,
|
|
1102
1108
|
});
|
|
1109
|
+
};
|
|
1110
|
+
try {
|
|
1111
|
+
let res;
|
|
1112
|
+
let streamedAttempt = false;
|
|
1113
|
+
// attempt stream only if not disabled and not using node-fetch
|
|
1114
|
+
if (!isNodeFetch && !this.multipartStreamingDisabled) {
|
|
1115
|
+
streamedAttempt = true;
|
|
1116
|
+
res = await send(await buildStream());
|
|
1117
|
+
}
|
|
1118
|
+
else {
|
|
1119
|
+
res = await send(await buildBuffered());
|
|
1120
|
+
}
|
|
1121
|
+
// if stream fails, fallback to buffered body
|
|
1122
|
+
if ((!this.multipartStreamingDisabled || streamedAttempt) &&
|
|
1123
|
+
res.status === 422 &&
|
|
1124
|
+
(options?.apiUrl ?? this.apiUrl) !== DEFAULT_API_URL) {
|
|
1125
|
+
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. ` +
|
|
1126
|
+
`This usually means the host does not support chunked uploads. ` +
|
|
1127
|
+
`Retrying with a buffered upload for operation "${context}".`);
|
|
1128
|
+
// Disable streaming for future requests
|
|
1129
|
+
this.multipartStreamingDisabled = true;
|
|
1130
|
+
// retry with fully-buffered body
|
|
1131
|
+
res = await send(await buildBuffered());
|
|
1132
|
+
}
|
|
1133
|
+
// raise if still failing
|
|
1103
1134
|
await raiseForStatus(res, "ingest multipart runs", true);
|
|
1104
1135
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1105
1136
|
}
|
|
@@ -3084,7 +3115,7 @@ export class Client {
|
|
|
3084
3115
|
const settings = await this._getSettings();
|
|
3085
3116
|
if (options?.isPublic && !settings.tenant_handle) {
|
|
3086
3117
|
throw new Error(`Cannot create a public prompt without first\n
|
|
3087
|
-
creating a LangChain Hub handle.
|
|
3118
|
+
creating a LangChain Hub handle.
|
|
3088
3119
|
You can add a handle by creating a public prompt at:\n
|
|
3089
3120
|
https://smith.langchain.com/prompts`);
|
|
3090
3121
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
|
|
|
10
10
|
var project_js_1 = require("./utils/project.cjs");
|
|
11
11
|
Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
|
|
12
12
|
// Update using yarn bump-version
|
|
13
|
-
exports.__version__ = "0.3.
|
|
13
|
+
exports.__version__ = "0.3.43";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
|
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
|
-
export declare const __version__ = "0.3.
|
|
6
|
+
export declare const __version__ = "0.3.43";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
|
|
|
3
3
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
4
4
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
5
5
|
// Update using yarn bump-version
|
|
6
|
-
export const __version__ = "0.3.
|
|
6
|
+
export const __version__ = "0.3.43";
|