@langchain/core 0.1.58 → 0.1.59
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.
|
@@ -77,7 +77,13 @@ ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(this.schema))}
|
|
|
77
77
|
const json = text.includes("```")
|
|
78
78
|
? text.trim().split(/```(?:json)?/)[1]
|
|
79
79
|
: text.trim();
|
|
80
|
-
|
|
80
|
+
const escapedJson = json
|
|
81
|
+
.replace(/"([^"\\]*(\\.[^"\\]*)*)"/g, (_match, capturedGroup) => {
|
|
82
|
+
const escapedInsideQuotes = capturedGroup.replace(/\n/g, "\\n");
|
|
83
|
+
return `"${escapedInsideQuotes}"`;
|
|
84
|
+
})
|
|
85
|
+
.replace(/\n/g, "");
|
|
86
|
+
return await this.schema.parseAsync(JSON.parse(escapedJson));
|
|
81
87
|
}
|
|
82
88
|
catch (e) {
|
|
83
89
|
throw new base_js_1.OutputParserException(`Failed to parse. Text: "${text}". Error: ${e}`, text);
|
|
@@ -74,7 +74,13 @@ ${JSON.stringify(zodToJsonSchema(this.schema))}
|
|
|
74
74
|
const json = text.includes("```")
|
|
75
75
|
? text.trim().split(/```(?:json)?/)[1]
|
|
76
76
|
: text.trim();
|
|
77
|
-
|
|
77
|
+
const escapedJson = json
|
|
78
|
+
.replace(/"([^"\\]*(\\.[^"\\]*)*)"/g, (_match, capturedGroup) => {
|
|
79
|
+
const escapedInsideQuotes = capturedGroup.replace(/\n/g, "\\n");
|
|
80
|
+
return `"${escapedInsideQuotes}"`;
|
|
81
|
+
})
|
|
82
|
+
.replace(/\n/g, "");
|
|
83
|
+
return await this.schema.parseAsync(JSON.parse(escapedJson));
|
|
78
84
|
}
|
|
79
85
|
catch (e) {
|
|
80
86
|
throw new OutputParserException(`Failed to parse. Text: "${text}". Error: ${e}`, text);
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -927,7 +927,8 @@ class RunnableRetry extends RunnableBinding {
|
|
|
927
927
|
}
|
|
928
928
|
async _invoke(input, config, runManager) {
|
|
929
929
|
return (0, p_retry_1.default)((attemptNumber) => super.invoke(input, this._patchConfigForRetry(attemptNumber, config, runManager)), {
|
|
930
|
-
|
|
930
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
931
|
+
onFailedAttempt: (error) => this.onFailedAttempt(error, input),
|
|
931
932
|
retries: Math.max(this.maxAttemptNumber - 1, 0),
|
|
932
933
|
randomize: true,
|
|
933
934
|
});
|
|
@@ -968,6 +969,8 @@ class RunnableRetry extends RunnableBinding {
|
|
|
968
969
|
if (result instanceof Error) {
|
|
969
970
|
if (firstException === undefined) {
|
|
970
971
|
firstException = result;
|
|
972
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
973
|
+
firstException.input = remainingInputs[i];
|
|
971
974
|
}
|
|
972
975
|
}
|
|
973
976
|
resultsMap[resultMapIndex.toString()] = result;
|
|
@@ -977,7 +980,8 @@ class RunnableRetry extends RunnableBinding {
|
|
|
977
980
|
}
|
|
978
981
|
return results;
|
|
979
982
|
}, {
|
|
980
|
-
|
|
983
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
984
|
+
onFailedAttempt: (error) => this.onFailedAttempt(error, error.input),
|
|
981
985
|
retries: Math.max(this.maxAttemptNumber - 1, 0),
|
|
982
986
|
randomize: true,
|
|
983
987
|
});
|
package/dist/runnables/base.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type RunnableMapLike<RunInput, RunOutput> = {
|
|
|
16
16
|
[K in keyof RunOutput]: RunnableLike<RunInput, RunOutput[K]>;
|
|
17
17
|
};
|
|
18
18
|
export type RunnableLike<RunInput = any, RunOutput = any> = RunnableInterface<RunInput, RunOutput> | RunnableFunc<RunInput, RunOutput> | RunnableMapLike<RunInput, RunOutput>;
|
|
19
|
-
export type RunnableRetryFailedAttemptHandler = (error: any) => any;
|
|
19
|
+
export type RunnableRetryFailedAttemptHandler = (error: any, input: any) => any;
|
|
20
20
|
export declare function _coerceToDict(value: any, defaultKey: string): any;
|
|
21
21
|
/**
|
|
22
22
|
* A Runnable is a generic unit of work that can be invoked, batched, streamed, and/or
|
|
@@ -332,7 +332,7 @@ export declare class RunnableRetry<RunInput = any, RunOutput = any, CallOptions
|
|
|
332
332
|
static lc_name(): string;
|
|
333
333
|
lc_namespace: string[];
|
|
334
334
|
protected maxAttemptNumber: number;
|
|
335
|
-
onFailedAttempt
|
|
335
|
+
onFailedAttempt: RunnableRetryFailedAttemptHandler;
|
|
336
336
|
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions> & {
|
|
337
337
|
maxAttemptNumber?: number;
|
|
338
338
|
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
package/dist/runnables/base.js
CHANGED
|
@@ -917,7 +917,8 @@ export class RunnableRetry extends RunnableBinding {
|
|
|
917
917
|
}
|
|
918
918
|
async _invoke(input, config, runManager) {
|
|
919
919
|
return pRetry((attemptNumber) => super.invoke(input, this._patchConfigForRetry(attemptNumber, config, runManager)), {
|
|
920
|
-
|
|
920
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
921
|
+
onFailedAttempt: (error) => this.onFailedAttempt(error, input),
|
|
921
922
|
retries: Math.max(this.maxAttemptNumber - 1, 0),
|
|
922
923
|
randomize: true,
|
|
923
924
|
});
|
|
@@ -958,6 +959,8 @@ export class RunnableRetry extends RunnableBinding {
|
|
|
958
959
|
if (result instanceof Error) {
|
|
959
960
|
if (firstException === undefined) {
|
|
960
961
|
firstException = result;
|
|
962
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
963
|
+
firstException.input = remainingInputs[i];
|
|
961
964
|
}
|
|
962
965
|
}
|
|
963
966
|
resultsMap[resultMapIndex.toString()] = result;
|
|
@@ -967,7 +970,8 @@ export class RunnableRetry extends RunnableBinding {
|
|
|
967
970
|
}
|
|
968
971
|
return results;
|
|
969
972
|
}, {
|
|
970
|
-
|
|
973
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
974
|
+
onFailedAttempt: (error) => this.onFailedAttempt(error, error.input),
|
|
971
975
|
retries: Math.max(this.maxAttemptNumber - 1, 0),
|
|
972
976
|
randomize: true,
|
|
973
977
|
});
|