@langchain/openai 0.3.7 → 0.3.8
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/utils/errors.cjs +11 -0
- package/dist/utils/errors.d.ts +2 -0
- package/dist/utils/errors.js +7 -0
- package/dist/utils/openai.cjs +13 -0
- package/dist/utils/openai.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
/* eslint-disable no-param-reassign */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.addLangChainErrorFields = void 0;
|
|
6
|
+
function addLangChainErrorFields(error, lc_error_code) {
|
|
7
|
+
error.lc_error_code = lc_error_code;
|
|
8
|
+
error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
|
|
9
|
+
return error;
|
|
10
|
+
}
|
|
11
|
+
exports.addLangChainErrorFields = addLangChainErrorFields;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type LangChainErrorCodes = "INVALID_PROMPT_INPUT" | "INVALID_TOOL_RESULTS" | "MESSAGE_COERCION_FAILURE" | "MODEL_AUTHENTICATION" | "MODEL_NOT_FOUND" | "MODEL_RATE_LIMIT" | "OUTPUT_PARSING_FAILURE";
|
|
2
|
+
export declare function addLangChainErrorFields(error: any, lc_error_code: LangChainErrorCodes): any;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
export function addLangChainErrorFields(error, lc_error_code) {
|
|
4
|
+
error.lc_error_code = lc_error_code;
|
|
5
|
+
error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
|
|
6
|
+
return error;
|
|
7
|
+
}
|
package/dist/utils/openai.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
|
6
6
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
7
7
|
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
|
|
8
8
|
Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
|
|
9
|
+
const errors_js_1 = require("./errors.cjs");
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
11
|
function wrapOpenAIClientError(e) {
|
|
11
12
|
let error;
|
|
@@ -17,6 +18,18 @@ function wrapOpenAIClientError(e) {
|
|
|
17
18
|
error = new Error(e.message);
|
|
18
19
|
error.name = "AbortError";
|
|
19
20
|
}
|
|
21
|
+
else if (e.status === 400 && e.message.includes("tool_calls")) {
|
|
22
|
+
error = (0, errors_js_1.addLangChainErrorFields)(e, "INVALID_TOOL_RESULTS");
|
|
23
|
+
}
|
|
24
|
+
else if (e.status === 401) {
|
|
25
|
+
error = (0, errors_js_1.addLangChainErrorFields)(e, "MODEL_AUTHENTICATION");
|
|
26
|
+
}
|
|
27
|
+
else if (e.status === 429) {
|
|
28
|
+
error = (0, errors_js_1.addLangChainErrorFields)(e, "MODEL_RATE_LIMIT");
|
|
29
|
+
}
|
|
30
|
+
else if (e.status === 404) {
|
|
31
|
+
error = (0, errors_js_1.addLangChainErrorFields)(e, "MODEL_NOT_FOUND");
|
|
32
|
+
}
|
|
20
33
|
else {
|
|
21
34
|
error = e;
|
|
22
35
|
}
|
package/dist/utils/openai.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { APIConnectionTimeoutError, APIUserAbortError, } from "openai";
|
|
2
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
3
|
import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
|
|
4
|
+
import { addLangChainErrorFields } from "./errors.js";
|
|
4
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
6
|
export function wrapOpenAIClientError(e) {
|
|
6
7
|
let error;
|
|
@@ -12,6 +13,18 @@ export function wrapOpenAIClientError(e) {
|
|
|
12
13
|
error = new Error(e.message);
|
|
13
14
|
error.name = "AbortError";
|
|
14
15
|
}
|
|
16
|
+
else if (e.status === 400 && e.message.includes("tool_calls")) {
|
|
17
|
+
error = addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
|
|
18
|
+
}
|
|
19
|
+
else if (e.status === 401) {
|
|
20
|
+
error = addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
|
|
21
|
+
}
|
|
22
|
+
else if (e.status === 429) {
|
|
23
|
+
error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
|
|
24
|
+
}
|
|
25
|
+
else if (e.status === 404) {
|
|
26
|
+
error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
|
|
27
|
+
}
|
|
15
28
|
else {
|
|
16
29
|
error = e;
|
|
17
30
|
}
|