@langchain/openai 1.7.0 → 1.8.0
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/CHANGELOG.md +15 -0
- package/dist/chat_models/base.cjs +1 -1
- package/dist/chat_models/base.js +1 -1
- package/dist/chat_models/index.d.cts +1 -1
- package/dist/chat_models/index.d.ts +1 -1
- package/dist/chat_models/profiles.cjs +230 -253
- package/dist/chat_models/profiles.cjs.map +1 -1
- package/dist/chat_models/profiles.js +230 -253
- package/dist/chat_models/profiles.js.map +1 -1
- package/dist/decisions/index.cjs +99 -0
- package/dist/decisions/index.cjs.map +1 -0
- package/dist/decisions/index.d.cts +52 -0
- package/dist/decisions/index.d.cts.map +1 -0
- package/dist/decisions/index.d.ts +52 -0
- package/dist/decisions/index.d.ts.map +1 -0
- package/dist/decisions/index.js +99 -0
- package/dist/decisions/index.js.map +1 -0
- package/dist/decisions/input.cjs +123 -0
- package/dist/decisions/input.cjs.map +1 -0
- package/dist/decisions/input.js +123 -0
- package/dist/decisions/input.js.map +1 -0
- package/dist/decisions/types.cjs +29 -0
- package/dist/decisions/types.cjs.map +1 -0
- package/dist/decisions/types.d.cts +60 -0
- package/dist/decisions/types.d.cts.map +1 -0
- package/dist/decisions/types.d.ts +60 -0
- package/dist/decisions/types.d.ts.map +1 -0
- package/dist/decisions/types.js +29 -0
- package/dist/decisions/types.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/llms.cjs +1 -1
- package/dist/llms.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const require_responses = require("../converters/responses.cjs");
|
|
2
|
+
let _langchain_core_messages = require("@langchain/core/messages");
|
|
3
|
+
//#region src/decisions/input.ts
|
|
4
|
+
/**
|
|
5
|
+
* Keeps text and image parts, which is all user messages and tool outputs accept,
|
|
6
|
+
* and replaces anything else, such as `input_file`, with a placeholder.
|
|
7
|
+
*/
|
|
8
|
+
function toInputParts(content) {
|
|
9
|
+
return content.map((part) => part.type === "input_text" && typeof part.text === "string" ? {
|
|
10
|
+
type: "input_text",
|
|
11
|
+
text: part.text
|
|
12
|
+
} : part.type === "input_image" && typeof part.image_url === "string" ? {
|
|
13
|
+
type: "input_image",
|
|
14
|
+
image_url: part.image_url
|
|
15
|
+
} : {
|
|
16
|
+
type: "input_text",
|
|
17
|
+
text: `[${part.type} omitted]`
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** System and developer messages accept only text parts. */
|
|
21
|
+
function toTextParts(content) {
|
|
22
|
+
return toInputParts(content).map((part) => part.type === "input_text" ? part : {
|
|
23
|
+
type: "input_text",
|
|
24
|
+
text: "[input_image omitted]"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Assistant messages accept `output_text` and `refusal` parts, without `annotations`. */
|
|
28
|
+
function toAssistantParts(content) {
|
|
29
|
+
return content.flatMap((part) => {
|
|
30
|
+
if (part.type === "output_text" && typeof part.text === "string") return [{
|
|
31
|
+
type: "output_text",
|
|
32
|
+
text: part.text
|
|
33
|
+
}];
|
|
34
|
+
if (part.type === "refusal" && typeof part.refusal === "string") return [{
|
|
35
|
+
type: "refusal",
|
|
36
|
+
refusal: part.refusal
|
|
37
|
+
}];
|
|
38
|
+
return [];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rebuilds one Responses item with only the fields the Decisions API accepts.
|
|
43
|
+
* Items it has no equivalent for, such as reasoning, are dropped.
|
|
44
|
+
*/
|
|
45
|
+
function toDecisionItem(item) {
|
|
46
|
+
if ("role" in item && (!("type" in item) || item.type === "message")) {
|
|
47
|
+
const { role, content } = item;
|
|
48
|
+
if (typeof content === "string") return role === "user" || role === "system" || role === "developer" || role === "assistant" ? [{
|
|
49
|
+
role,
|
|
50
|
+
content
|
|
51
|
+
}] : [];
|
|
52
|
+
if (role === "user") return [{
|
|
53
|
+
role,
|
|
54
|
+
content: toInputParts(content)
|
|
55
|
+
}];
|
|
56
|
+
if (role === "system" || role === "developer") return [{
|
|
57
|
+
role,
|
|
58
|
+
content: toTextParts(content)
|
|
59
|
+
}];
|
|
60
|
+
if (role === "assistant") return [{
|
|
61
|
+
role,
|
|
62
|
+
content: toAssistantParts(content)
|
|
63
|
+
}];
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
if (!("type" in item)) return [];
|
|
67
|
+
switch (item.type) {
|
|
68
|
+
case "function_call": return [{
|
|
69
|
+
type: item.type,
|
|
70
|
+
call_id: item.call_id,
|
|
71
|
+
name: item.name,
|
|
72
|
+
arguments: item.arguments
|
|
73
|
+
}];
|
|
74
|
+
case "custom_tool_call": return [{
|
|
75
|
+
type: item.type,
|
|
76
|
+
call_id: item.call_id,
|
|
77
|
+
name: item.name,
|
|
78
|
+
input: item.input
|
|
79
|
+
}];
|
|
80
|
+
case "function_call_output":
|
|
81
|
+
case "custom_tool_call_output": return [{
|
|
82
|
+
type: item.type,
|
|
83
|
+
call_id: item.call_id ?? "",
|
|
84
|
+
output: typeof item.output === "string" ? item.output : toInputParts(item.output)
|
|
85
|
+
}];
|
|
86
|
+
default: return [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Converts LangChain messages to Decisions input items. */
|
|
90
|
+
function toDecisionItems(messages) {
|
|
91
|
+
return require_responses.convertMessagesToResponsesInput({
|
|
92
|
+
messages,
|
|
93
|
+
zdrEnabled: true,
|
|
94
|
+
model: ""
|
|
95
|
+
}).flatMap(toDecisionItem);
|
|
96
|
+
}
|
|
97
|
+
/** Replaces messages nested in JSON state with their Decisions input items. */
|
|
98
|
+
function toJSONValue(value) {
|
|
99
|
+
if (_langchain_core_messages.BaseMessage.isInstance(value)) return toDecisionItems([value]);
|
|
100
|
+
if (Array.isArray(value)) return value.flatMap((item) => _langchain_core_messages.BaseMessage.isInstance(item) ? toDecisionItems([item]) : [toJSONValue(item)]);
|
|
101
|
+
if (typeof value === "object" && value?.constructor === Object) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toJSONValue(item)]));
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Converts input to the Decisions API `input` field: strings as they are, messages
|
|
106
|
+
* as a native conversation, and anything else as an `input_json` part.
|
|
107
|
+
*/
|
|
108
|
+
function toDecisionInput(input) {
|
|
109
|
+
if (typeof input === "string") return input;
|
|
110
|
+
const values = Array.isArray(input) ? input : [input];
|
|
111
|
+
if (values.length > 0 && values.every((value) => _langchain_core_messages.BaseMessage.isInstance(value))) return toDecisionItems(values);
|
|
112
|
+
return [{
|
|
113
|
+
role: "user",
|
|
114
|
+
content: [{
|
|
115
|
+
type: "input_json",
|
|
116
|
+
data: toJSONValue(input)
|
|
117
|
+
}]
|
|
118
|
+
}];
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.toDecisionInput = toDecisionInput;
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=input.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.cjs","names":["convertMessagesToResponsesInput","BaseMessage"],"sources":["../../src/decisions/input.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { convertMessagesToResponsesInput } from \"../converters/responses.js\";\nimport type { DecisionInput } from \"./types.js\";\n\n/**\n * How LangChain input becomes the Decisions API `input` field.\n *\n * The Decisions API accepts a string, or a list of items using a subset of the\n * Responses API input format: `user`, `system`, `developer` and `assistant` messages,\n * plus function and custom tool calls and their outputs. Rather than writing a second\n * LangChain message converter, messages go through the Responses converter\n * (`convertMessagesToResponsesInput`), which already handles roles, content blocks,\n * tool calls and tool results. The Decisions API is strict about what it accepts,\n * though, and Responses items carry things it rejects: reasoning items, item `id`s,\n * `annotations` and `phase` on assistant text, and content parts such as\n * `input_file`. So each Responses item is rebuilt with only the fields the Decisions\n * API accepts (`toDecisionItem`), and unsupported content parts are replaced by a\n * text placeholder so the model knows something was there.\n *\n * Input that is not messages, such as application state, is sent as an `input_json`\n * part, which the API reads as structured data. Messages nested in that state are\n * converted to the same items, because a `BaseMessage` instance would otherwise be\n * serialized as LangChain's internal constructor format.\n */\n\ntype ResponsesItem = ReturnType<typeof convertMessagesToResponsesInput>[number];\ntype DecisionItem = Exclude<\n OpenAIClient.DecisionCreateParams[\"input\"],\n string\n>[number];\ntype InputPart =\n | OpenAIClient.DecisionInputText\n | OpenAIClient.DecisionInputImage;\ntype AssistantPart = Exclude<\n OpenAIClient.DecisionInputMessage.DecisionInputAssistantMessage[\"content\"],\n string\n>[number];\n\n/** A Responses content part, loosely typed because roles and tool outputs use different part unions. */\ntype ResponsesPart = {\n type: string;\n text?: unknown;\n image_url?: unknown;\n refusal?: unknown;\n};\n\n/**\n * Keeps text and image parts, which is all user messages and tool outputs accept,\n * and replaces anything else, such as `input_file`, with a placeholder.\n */\nfunction toInputParts(content: unknown): InputPart[] {\n return (content as ResponsesPart[]).map((part) =>\n part.type === \"input_text\" && typeof part.text === \"string\"\n ? { type: \"input_text\", text: part.text }\n : part.type === \"input_image\" && typeof part.image_url === \"string\"\n ? { type: \"input_image\", image_url: part.image_url }\n : { type: \"input_text\", text: `[${part.type} omitted]` }\n );\n}\n\n/** System and developer messages accept only text parts. */\nfunction toTextParts(content: unknown): OpenAIClient.DecisionInputText[] {\n return toInputParts(content).map((part) =>\n part.type === \"input_text\"\n ? part\n : { type: \"input_text\", text: \"[input_image omitted]\" }\n );\n}\n\n/** Assistant messages accept `output_text` and `refusal` parts, without `annotations`. */\nfunction toAssistantParts(content: unknown): AssistantPart[] {\n return (content as ResponsesPart[]).flatMap((part): AssistantPart[] => {\n if (part.type === \"output_text\" && typeof part.text === \"string\")\n return [{ type: \"output_text\", text: part.text }];\n if (part.type === \"refusal\" && typeof part.refusal === \"string\")\n return [{ type: \"refusal\", refusal: part.refusal }];\n return [];\n });\n}\n\n/**\n * Rebuilds one Responses item with only the fields the Decisions API accepts.\n * Items it has no equivalent for, such as reasoning, are dropped.\n */\nfunction toDecisionItem(item: ResponsesItem): DecisionItem[] {\n if (\"role\" in item && (!(\"type\" in item) || item.type === \"message\")) {\n const { role, content } = item;\n if (typeof content === \"string\")\n return role === \"user\" ||\n role === \"system\" ||\n role === \"developer\" ||\n role === \"assistant\"\n ? [{ role, content }]\n : [];\n if (role === \"user\") return [{ role, content: toInputParts(content) }];\n if (role === \"system\" || role === \"developer\")\n return [{ role, content: toTextParts(content) }];\n if (role === \"assistant\")\n return [{ role, content: toAssistantParts(content) }];\n return [];\n }\n if (!(\"type\" in item)) return [];\n switch (item.type) {\n case \"function_call\":\n return [\n {\n type: item.type,\n call_id: item.call_id,\n name: item.name,\n arguments: item.arguments,\n },\n ];\n case \"custom_tool_call\":\n return [\n {\n type: item.type,\n call_id: item.call_id,\n name: item.name,\n input: item.input,\n },\n ];\n case \"function_call_output\":\n case \"custom_tool_call_output\":\n return [\n {\n type: item.type,\n call_id: item.call_id ?? \"\",\n output:\n typeof item.output === \"string\"\n ? item.output\n : toInputParts(item.output),\n },\n ];\n default:\n return [];\n }\n}\n\n/** Converts LangChain messages to Decisions input items. */\nfunction toDecisionItems(messages: BaseMessage[]): DecisionItem[] {\n return convertMessagesToResponsesInput({\n messages,\n zdrEnabled: true,\n model: \"\",\n }).flatMap(toDecisionItem);\n}\n\n/** Replaces messages nested in JSON state with their Decisions input items. */\nfunction toJSONValue(value: unknown): unknown {\n if (BaseMessage.isInstance(value)) return toDecisionItems([value]);\n if (Array.isArray(value))\n return value.flatMap((item) =>\n BaseMessage.isInstance(item)\n ? toDecisionItems([item])\n : [toJSONValue(item)]\n );\n if (typeof value === \"object\" && value?.constructor === Object)\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, toJSONValue(item)])\n );\n return value;\n}\n\n/**\n * Converts input to the Decisions API `input` field: strings as they are, messages\n * as a native conversation, and anything else as an `input_json` part.\n */\nexport function toDecisionInput(\n input: DecisionInput\n): OpenAIClient.DecisionCreateParams[\"input\"] {\n if (typeof input === \"string\") return input;\n const values = Array.isArray(input) ? input : [input];\n if (\n values.length > 0 &&\n values.every((value) => BaseMessage.isInstance(value))\n )\n return toDecisionItems(values);\n return [\n {\n role: \"user\",\n content: [\n {\n type: \"input_json\",\n data: toJSONValue(input) as OpenAIClient.DecisionInputJSON[\"data\"],\n },\n ],\n },\n ];\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { convertMessagesToResponsesInput } from "../converters/responses.js";
|
|
2
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
3
|
+
//#region src/decisions/input.ts
|
|
4
|
+
/**
|
|
5
|
+
* Keeps text and image parts, which is all user messages and tool outputs accept,
|
|
6
|
+
* and replaces anything else, such as `input_file`, with a placeholder.
|
|
7
|
+
*/
|
|
8
|
+
function toInputParts(content) {
|
|
9
|
+
return content.map((part) => part.type === "input_text" && typeof part.text === "string" ? {
|
|
10
|
+
type: "input_text",
|
|
11
|
+
text: part.text
|
|
12
|
+
} : part.type === "input_image" && typeof part.image_url === "string" ? {
|
|
13
|
+
type: "input_image",
|
|
14
|
+
image_url: part.image_url
|
|
15
|
+
} : {
|
|
16
|
+
type: "input_text",
|
|
17
|
+
text: `[${part.type} omitted]`
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** System and developer messages accept only text parts. */
|
|
21
|
+
function toTextParts(content) {
|
|
22
|
+
return toInputParts(content).map((part) => part.type === "input_text" ? part : {
|
|
23
|
+
type: "input_text",
|
|
24
|
+
text: "[input_image omitted]"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Assistant messages accept `output_text` and `refusal` parts, without `annotations`. */
|
|
28
|
+
function toAssistantParts(content) {
|
|
29
|
+
return content.flatMap((part) => {
|
|
30
|
+
if (part.type === "output_text" && typeof part.text === "string") return [{
|
|
31
|
+
type: "output_text",
|
|
32
|
+
text: part.text
|
|
33
|
+
}];
|
|
34
|
+
if (part.type === "refusal" && typeof part.refusal === "string") return [{
|
|
35
|
+
type: "refusal",
|
|
36
|
+
refusal: part.refusal
|
|
37
|
+
}];
|
|
38
|
+
return [];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rebuilds one Responses item with only the fields the Decisions API accepts.
|
|
43
|
+
* Items it has no equivalent for, such as reasoning, are dropped.
|
|
44
|
+
*/
|
|
45
|
+
function toDecisionItem(item) {
|
|
46
|
+
if ("role" in item && (!("type" in item) || item.type === "message")) {
|
|
47
|
+
const { role, content } = item;
|
|
48
|
+
if (typeof content === "string") return role === "user" || role === "system" || role === "developer" || role === "assistant" ? [{
|
|
49
|
+
role,
|
|
50
|
+
content
|
|
51
|
+
}] : [];
|
|
52
|
+
if (role === "user") return [{
|
|
53
|
+
role,
|
|
54
|
+
content: toInputParts(content)
|
|
55
|
+
}];
|
|
56
|
+
if (role === "system" || role === "developer") return [{
|
|
57
|
+
role,
|
|
58
|
+
content: toTextParts(content)
|
|
59
|
+
}];
|
|
60
|
+
if (role === "assistant") return [{
|
|
61
|
+
role,
|
|
62
|
+
content: toAssistantParts(content)
|
|
63
|
+
}];
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
if (!("type" in item)) return [];
|
|
67
|
+
switch (item.type) {
|
|
68
|
+
case "function_call": return [{
|
|
69
|
+
type: item.type,
|
|
70
|
+
call_id: item.call_id,
|
|
71
|
+
name: item.name,
|
|
72
|
+
arguments: item.arguments
|
|
73
|
+
}];
|
|
74
|
+
case "custom_tool_call": return [{
|
|
75
|
+
type: item.type,
|
|
76
|
+
call_id: item.call_id,
|
|
77
|
+
name: item.name,
|
|
78
|
+
input: item.input
|
|
79
|
+
}];
|
|
80
|
+
case "function_call_output":
|
|
81
|
+
case "custom_tool_call_output": return [{
|
|
82
|
+
type: item.type,
|
|
83
|
+
call_id: item.call_id ?? "",
|
|
84
|
+
output: typeof item.output === "string" ? item.output : toInputParts(item.output)
|
|
85
|
+
}];
|
|
86
|
+
default: return [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Converts LangChain messages to Decisions input items. */
|
|
90
|
+
function toDecisionItems(messages) {
|
|
91
|
+
return convertMessagesToResponsesInput({
|
|
92
|
+
messages,
|
|
93
|
+
zdrEnabled: true,
|
|
94
|
+
model: ""
|
|
95
|
+
}).flatMap(toDecisionItem);
|
|
96
|
+
}
|
|
97
|
+
/** Replaces messages nested in JSON state with their Decisions input items. */
|
|
98
|
+
function toJSONValue(value) {
|
|
99
|
+
if (BaseMessage.isInstance(value)) return toDecisionItems([value]);
|
|
100
|
+
if (Array.isArray(value)) return value.flatMap((item) => BaseMessage.isInstance(item) ? toDecisionItems([item]) : [toJSONValue(item)]);
|
|
101
|
+
if (typeof value === "object" && value?.constructor === Object) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toJSONValue(item)]));
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Converts input to the Decisions API `input` field: strings as they are, messages
|
|
106
|
+
* as a native conversation, and anything else as an `input_json` part.
|
|
107
|
+
*/
|
|
108
|
+
function toDecisionInput(input) {
|
|
109
|
+
if (typeof input === "string") return input;
|
|
110
|
+
const values = Array.isArray(input) ? input : [input];
|
|
111
|
+
if (values.length > 0 && values.every((value) => BaseMessage.isInstance(value))) return toDecisionItems(values);
|
|
112
|
+
return [{
|
|
113
|
+
role: "user",
|
|
114
|
+
content: [{
|
|
115
|
+
type: "input_json",
|
|
116
|
+
data: toJSONValue(input)
|
|
117
|
+
}]
|
|
118
|
+
}];
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { toDecisionInput };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","names":[],"sources":["../../src/decisions/input.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { convertMessagesToResponsesInput } from \"../converters/responses.js\";\nimport type { DecisionInput } from \"./types.js\";\n\n/**\n * How LangChain input becomes the Decisions API `input` field.\n *\n * The Decisions API accepts a string, or a list of items using a subset of the\n * Responses API input format: `user`, `system`, `developer` and `assistant` messages,\n * plus function and custom tool calls and their outputs. Rather than writing a second\n * LangChain message converter, messages go through the Responses converter\n * (`convertMessagesToResponsesInput`), which already handles roles, content blocks,\n * tool calls and tool results. The Decisions API is strict about what it accepts,\n * though, and Responses items carry things it rejects: reasoning items, item `id`s,\n * `annotations` and `phase` on assistant text, and content parts such as\n * `input_file`. So each Responses item is rebuilt with only the fields the Decisions\n * API accepts (`toDecisionItem`), and unsupported content parts are replaced by a\n * text placeholder so the model knows something was there.\n *\n * Input that is not messages, such as application state, is sent as an `input_json`\n * part, which the API reads as structured data. Messages nested in that state are\n * converted to the same items, because a `BaseMessage` instance would otherwise be\n * serialized as LangChain's internal constructor format.\n */\n\ntype ResponsesItem = ReturnType<typeof convertMessagesToResponsesInput>[number];\ntype DecisionItem = Exclude<\n OpenAIClient.DecisionCreateParams[\"input\"],\n string\n>[number];\ntype InputPart =\n | OpenAIClient.DecisionInputText\n | OpenAIClient.DecisionInputImage;\ntype AssistantPart = Exclude<\n OpenAIClient.DecisionInputMessage.DecisionInputAssistantMessage[\"content\"],\n string\n>[number];\n\n/** A Responses content part, loosely typed because roles and tool outputs use different part unions. */\ntype ResponsesPart = {\n type: string;\n text?: unknown;\n image_url?: unknown;\n refusal?: unknown;\n};\n\n/**\n * Keeps text and image parts, which is all user messages and tool outputs accept,\n * and replaces anything else, such as `input_file`, with a placeholder.\n */\nfunction toInputParts(content: unknown): InputPart[] {\n return (content as ResponsesPart[]).map((part) =>\n part.type === \"input_text\" && typeof part.text === \"string\"\n ? { type: \"input_text\", text: part.text }\n : part.type === \"input_image\" && typeof part.image_url === \"string\"\n ? { type: \"input_image\", image_url: part.image_url }\n : { type: \"input_text\", text: `[${part.type} omitted]` }\n );\n}\n\n/** System and developer messages accept only text parts. */\nfunction toTextParts(content: unknown): OpenAIClient.DecisionInputText[] {\n return toInputParts(content).map((part) =>\n part.type === \"input_text\"\n ? part\n : { type: \"input_text\", text: \"[input_image omitted]\" }\n );\n}\n\n/** Assistant messages accept `output_text` and `refusal` parts, without `annotations`. */\nfunction toAssistantParts(content: unknown): AssistantPart[] {\n return (content as ResponsesPart[]).flatMap((part): AssistantPart[] => {\n if (part.type === \"output_text\" && typeof part.text === \"string\")\n return [{ type: \"output_text\", text: part.text }];\n if (part.type === \"refusal\" && typeof part.refusal === \"string\")\n return [{ type: \"refusal\", refusal: part.refusal }];\n return [];\n });\n}\n\n/**\n * Rebuilds one Responses item with only the fields the Decisions API accepts.\n * Items it has no equivalent for, such as reasoning, are dropped.\n */\nfunction toDecisionItem(item: ResponsesItem): DecisionItem[] {\n if (\"role\" in item && (!(\"type\" in item) || item.type === \"message\")) {\n const { role, content } = item;\n if (typeof content === \"string\")\n return role === \"user\" ||\n role === \"system\" ||\n role === \"developer\" ||\n role === \"assistant\"\n ? [{ role, content }]\n : [];\n if (role === \"user\") return [{ role, content: toInputParts(content) }];\n if (role === \"system\" || role === \"developer\")\n return [{ role, content: toTextParts(content) }];\n if (role === \"assistant\")\n return [{ role, content: toAssistantParts(content) }];\n return [];\n }\n if (!(\"type\" in item)) return [];\n switch (item.type) {\n case \"function_call\":\n return [\n {\n type: item.type,\n call_id: item.call_id,\n name: item.name,\n arguments: item.arguments,\n },\n ];\n case \"custom_tool_call\":\n return [\n {\n type: item.type,\n call_id: item.call_id,\n name: item.name,\n input: item.input,\n },\n ];\n case \"function_call_output\":\n case \"custom_tool_call_output\":\n return [\n {\n type: item.type,\n call_id: item.call_id ?? \"\",\n output:\n typeof item.output === \"string\"\n ? item.output\n : toInputParts(item.output),\n },\n ];\n default:\n return [];\n }\n}\n\n/** Converts LangChain messages to Decisions input items. */\nfunction toDecisionItems(messages: BaseMessage[]): DecisionItem[] {\n return convertMessagesToResponsesInput({\n messages,\n zdrEnabled: true,\n model: \"\",\n }).flatMap(toDecisionItem);\n}\n\n/** Replaces messages nested in JSON state with their Decisions input items. */\nfunction toJSONValue(value: unknown): unknown {\n if (BaseMessage.isInstance(value)) return toDecisionItems([value]);\n if (Array.isArray(value))\n return value.flatMap((item) =>\n BaseMessage.isInstance(item)\n ? toDecisionItems([item])\n : [toJSONValue(item)]\n );\n if (typeof value === \"object\" && value?.constructor === Object)\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, toJSONValue(item)])\n );\n return value;\n}\n\n/**\n * Converts input to the Decisions API `input` field: strings as they are, messages\n * as a native conversation, and anything else as an `input_json` part.\n */\nexport function toDecisionInput(\n input: DecisionInput\n): OpenAIClient.DecisionCreateParams[\"input\"] {\n if (typeof input === \"string\") return input;\n const values = Array.isArray(input) ? input : [input];\n if (\n values.length > 0 &&\n values.every((value) => BaseMessage.isInstance(value))\n )\n return toDecisionItems(values);\n return [\n {\n role: \"user\",\n content: [\n {\n type: \"input_json\",\n data: toJSONValue(input) as OpenAIClient.DecisionInputJSON[\"data\"],\n },\n ],\n },\n ];\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/decisions/types.ts
|
|
2
|
+
/** Converts a named question to the shape the Decisions API expects. */
|
|
3
|
+
function toQuestionParam(name, question) {
|
|
4
|
+
const { type, instructions } = question;
|
|
5
|
+
if (type === "predicate") return {
|
|
6
|
+
type,
|
|
7
|
+
name,
|
|
8
|
+
instructions
|
|
9
|
+
};
|
|
10
|
+
if (type === "choice") return {
|
|
11
|
+
type,
|
|
12
|
+
name,
|
|
13
|
+
instructions,
|
|
14
|
+
choices: Object.entries(question.choices).map(([value, description]) => description == null ? { value } : {
|
|
15
|
+
value,
|
|
16
|
+
description
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
type,
|
|
21
|
+
name,
|
|
22
|
+
instructions,
|
|
23
|
+
levels: question.levels.map((level) => typeof level === "string" ? { label: level } : level)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.toQuestionParam = toQuestionParam;
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/decisions/types.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport type { BaseMessage, UsageMetadata } from \"@langchain/core/messages\";\n\ntype QuestionParam = OpenAIClient.DecisionCreateParams[\"questions\"][number];\n\n/** Estimate the probability that a condition is true. */\nexport interface Predicate {\n type: \"predicate\";\n instructions: string;\n}\n\n/** Select one option. Keys are the option values; values describe when each applies. */\nexport interface Choice<K extends string = string> {\n type: \"choice\";\n instructions: string;\n choices: Record<K, string | null>;\n}\n\n/** One level of a `Score` rubric. */\nexport type Level = OpenAIClient.DecisionCreateParams.QuestionParamScore.Level;\n\n/** Rate the input against two or more levels, ordered lowest to highest. */\nexport interface Score {\n type: \"score\";\n instructions: string;\n levels: readonly (string | Level)[];\n}\n\nexport type Question = Predicate | Choice | Score;\n\nexport type Questions = Record<string, Question>;\n\nexport type PredicateAnswer = Omit<\n OpenAIClient.Decision.AnswerResourcePredicate,\n \"name\"\n>;\n\nexport type ChoiceAnswer<K extends string = string> = Omit<\n OpenAIClient.Decision.AnswerResourceChoice,\n \"name\" | \"choice\" | \"probabilities\"\n> & {\n choice: K;\n probabilities: { value: K; probability: number }[];\n};\n\n/** `score` is the probability-weighted average of the zero-based level indices. */\nexport type ScoreAnswer = Omit<\n OpenAIClient.Decision.AnswerResourceScore,\n \"name\"\n>;\n\nexport type RefusalAnswer = Omit<\n OpenAIClient.Decision.AnswerResourceRefusal,\n \"name\"\n>;\n\nexport type Answer =\n | PredicateAnswer\n | ChoiceAnswer\n | ScoreAnswer\n | RefusalAnswer;\n\n/** The answer type a question produces. */\nexport type AnswerFor<T extends Question> = T extends Predicate\n ? PredicateAnswer\n : T extends Choice\n ? ChoiceAnswer<Extract<keyof T[\"choices\"], string>>\n : T extends Score\n ? ScoreAnswer\n : never;\n\n/** Answers keyed by question name, typed from the questions that were asked. */\nexport type Answers<Q extends Questions> = {\n -readonly [K in keyof Q]: AnswerFor<Q[K]> | RefusalAnswer;\n};\n\n/**\n * Text, LangChain messages, or JSON state to evaluate. Messages are sent as a native\n * conversation; JSON objects, which may contain messages, as an `input_json` part.\n */\nexport type DecisionInput =\n | string\n | BaseMessage\n | BaseMessage[]\n | Record<string, unknown>\n | Record<string, unknown>[];\n\n/** One Decisions request: what to evaluate and the named questions to ask. */\nexport interface DecisionRequest<Q extends Questions = Questions> {\n input: DecisionInput;\n questions: Q;\n}\n\nexport interface DecisionResult<Q extends Questions = Questions> {\n answers: Answers<Q>;\n /** The model that answered, as reported by the API. */\n model: string;\n requestId?: string;\n /** Read by LangSmith to record token usage on the traced run. */\n usage_metadata: UsageMetadata;\n}\n\n/** Converts a named question to the shape the Decisions API expects. */\nexport function toQuestionParam(\n name: string,\n question: Question\n): QuestionParam {\n const { type, instructions } = question;\n if (type === \"predicate\") return { type, name, instructions };\n if (type === \"choice\") {\n return {\n type,\n name,\n instructions,\n choices: Object.entries(question.choices).map(([value, description]) =>\n description == null ? { value } : { value, description }\n ),\n };\n }\n return {\n type,\n name,\n instructions,\n levels: question.levels.map((level) =>\n typeof level === \"string\" ? { label: level } : level\n ),\n };\n}\n"],"mappings":";;AAuGA,SAAgB,gBACd,MACA,UACe;CACf,MAAM,EAAE,MAAM,iBAAiB;CAC/B,IAAI,SAAS,aAAa,OAAO;EAAE;EAAM;EAAM;CAAa;CAC5D,IAAI,SAAS,UACX,OAAO;EACL;EACA;EACA;EACA,SAAS,OAAO,QAAQ,SAAS,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,iBACrD,eAAe,OAAO,EAAE,MAAM,IAAI;GAAE;GAAO;EAAY,CACzD;CACF;CAEF,OAAO;EACL;EACA;EACA;EACA,QAAQ,SAAS,OAAO,KAAK,UAC3B,OAAO,UAAU,WAAW,EAAE,OAAO,MAAM,IAAI,KACjD;CACF;AACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
|
+
import { BaseMessage, UsageMetadata } from "@langchain/core/messages";
|
|
3
|
+
//#region src/decisions/types.d.ts
|
|
4
|
+
/** Estimate the probability that a condition is true. */
|
|
5
|
+
export interface Predicate {
|
|
6
|
+
type: "predicate";
|
|
7
|
+
instructions: string;
|
|
8
|
+
}
|
|
9
|
+
/** Select one option. Keys are the option values; values describe when each applies. */
|
|
10
|
+
export interface Choice<K extends string = string> {
|
|
11
|
+
type: "choice";
|
|
12
|
+
instructions: string;
|
|
13
|
+
choices: Record<K, string | null>;
|
|
14
|
+
}
|
|
15
|
+
/** One level of a `Score` rubric. */
|
|
16
|
+
export type Level = OpenAI.DecisionCreateParams.QuestionParamScore.Level;
|
|
17
|
+
/** Rate the input against two or more levels, ordered lowest to highest. */
|
|
18
|
+
export interface Score {
|
|
19
|
+
type: "score";
|
|
20
|
+
instructions: string;
|
|
21
|
+
levels: readonly (string | Level)[];
|
|
22
|
+
}
|
|
23
|
+
export type Question = Predicate | Choice | Score;
|
|
24
|
+
export type Questions = Record<string, Question>;
|
|
25
|
+
export type PredicateAnswer = Omit<OpenAI.Decision.AnswerResourcePredicate, "name">;
|
|
26
|
+
export type ChoiceAnswer<K extends string = string> = Omit<OpenAI.Decision.AnswerResourceChoice, "name" | "choice" | "probabilities"> & {
|
|
27
|
+
choice: K;
|
|
28
|
+
probabilities: {
|
|
29
|
+
value: K;
|
|
30
|
+
probability: number;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
/** `score` is the probability-weighted average of the zero-based level indices. */
|
|
34
|
+
export type ScoreAnswer = Omit<OpenAI.Decision.AnswerResourceScore, "name">;
|
|
35
|
+
export type RefusalAnswer = Omit<OpenAI.Decision.AnswerResourceRefusal, "name">;
|
|
36
|
+
export type Answer = PredicateAnswer | ChoiceAnswer | ScoreAnswer | RefusalAnswer;
|
|
37
|
+
/** The answer type a question produces. */
|
|
38
|
+
export type AnswerFor<T extends Question> = T extends Predicate ? PredicateAnswer : T extends Choice ? ChoiceAnswer<Extract<keyof T["choices"], string>> : T extends Score ? ScoreAnswer : never;
|
|
39
|
+
/** Answers keyed by question name, typed from the questions that were asked. */
|
|
40
|
+
export type Answers<Q extends Questions> = { -readonly [K in keyof Q]: AnswerFor<Q[K]> | RefusalAnswer; };
|
|
41
|
+
/**
|
|
42
|
+
* Text, LangChain messages, or JSON state to evaluate. Messages are sent as a native
|
|
43
|
+
* conversation; JSON objects, which may contain messages, as an `input_json` part.
|
|
44
|
+
*/
|
|
45
|
+
export type DecisionInput = string | BaseMessage | BaseMessage[] | Record<string, unknown> | Record<string, unknown>[];
|
|
46
|
+
/** One Decisions request: what to evaluate and the named questions to ask. */
|
|
47
|
+
export interface DecisionRequest<Q extends Questions = Questions> {
|
|
48
|
+
input: DecisionInput;
|
|
49
|
+
questions: Q;
|
|
50
|
+
}
|
|
51
|
+
export interface DecisionResult<Q extends Questions = Questions> {
|
|
52
|
+
answers: Answers<Q>;
|
|
53
|
+
/** The model that answered, as reported by the API. */
|
|
54
|
+
model: string;
|
|
55
|
+
requestId?: string;
|
|
56
|
+
/** Read by LangSmith to record token usage on the traced run. */
|
|
57
|
+
usage_metadata: UsageMetadata;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":["OpenAIClient"],"sources":["../../src/decisions/types.ts"],"mappings":";;;;iBAMiB;EACf;EACA;;;iBAIe,OAAO;EACtB;EACA;EACA,SAAS,OAAO;;;YAIN,QAAQA,OAAa,qBAAqB,mBAAmB;;iBAGxD;EACf;EACA;EACA,2BAA2B;;YAGjB,WAAW,YAAY,SAAS;YAEhC,YAAY,eAAe;YAE3B,kBAAkB,KAC5BA,OAAa,SAAS;YAIZ,aAAa,6BAA6B,KACpDA,OAAa,SAAS;EAGtB,QAAQ;EACR;IAAiB,OAAO;IAAG;;;;YAIjB,cAAc,KACxBA,OAAa,SAAS;YAIZ,gBAAgB,KAC1BA,OAAa,SAAS;YAIZ,SACR,kBACA,eACA,cACA;;YAGQ,UAAU,UAAU,YAAY,UAAU,YAClD,kBACA,UAAU,SACR,aAAa,cAAc,yBAC3B,UAAU,QACR;;YAII,QAAQ,UAAU,0BACjB,WAAW,IAAI,UAAU,EAAE,MAAM;;;;;YAOlC,yBAER,cACA,gBACA,0BACA;;iBAGa,gBAAgB,UAAU,YAAY;EACrD,OAAO;EACP,WAAW;;iBAGI,eAAe,UAAU,YAAY;EACpD,SAAS,QAAQ;;EAEjB;EACA;;EAEA,gBAAgB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
|
+
import { BaseMessage, UsageMetadata } from "@langchain/core/messages";
|
|
3
|
+
//#region src/decisions/types.d.ts
|
|
4
|
+
/** Estimate the probability that a condition is true. */
|
|
5
|
+
export interface Predicate {
|
|
6
|
+
type: "predicate";
|
|
7
|
+
instructions: string;
|
|
8
|
+
}
|
|
9
|
+
/** Select one option. Keys are the option values; values describe when each applies. */
|
|
10
|
+
export interface Choice<K extends string = string> {
|
|
11
|
+
type: "choice";
|
|
12
|
+
instructions: string;
|
|
13
|
+
choices: Record<K, string | null>;
|
|
14
|
+
}
|
|
15
|
+
/** One level of a `Score` rubric. */
|
|
16
|
+
export type Level = OpenAI.DecisionCreateParams.QuestionParamScore.Level;
|
|
17
|
+
/** Rate the input against two or more levels, ordered lowest to highest. */
|
|
18
|
+
export interface Score {
|
|
19
|
+
type: "score";
|
|
20
|
+
instructions: string;
|
|
21
|
+
levels: readonly (string | Level)[];
|
|
22
|
+
}
|
|
23
|
+
export type Question = Predicate | Choice | Score;
|
|
24
|
+
export type Questions = Record<string, Question>;
|
|
25
|
+
export type PredicateAnswer = Omit<OpenAI.Decision.AnswerResourcePredicate, "name">;
|
|
26
|
+
export type ChoiceAnswer<K extends string = string> = Omit<OpenAI.Decision.AnswerResourceChoice, "name" | "choice" | "probabilities"> & {
|
|
27
|
+
choice: K;
|
|
28
|
+
probabilities: {
|
|
29
|
+
value: K;
|
|
30
|
+
probability: number;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
/** `score` is the probability-weighted average of the zero-based level indices. */
|
|
34
|
+
export type ScoreAnswer = Omit<OpenAI.Decision.AnswerResourceScore, "name">;
|
|
35
|
+
export type RefusalAnswer = Omit<OpenAI.Decision.AnswerResourceRefusal, "name">;
|
|
36
|
+
export type Answer = PredicateAnswer | ChoiceAnswer | ScoreAnswer | RefusalAnswer;
|
|
37
|
+
/** The answer type a question produces. */
|
|
38
|
+
export type AnswerFor<T extends Question> = T extends Predicate ? PredicateAnswer : T extends Choice ? ChoiceAnswer<Extract<keyof T["choices"], string>> : T extends Score ? ScoreAnswer : never;
|
|
39
|
+
/** Answers keyed by question name, typed from the questions that were asked. */
|
|
40
|
+
export type Answers<Q extends Questions> = { -readonly [K in keyof Q]: AnswerFor<Q[K]> | RefusalAnswer; };
|
|
41
|
+
/**
|
|
42
|
+
* Text, LangChain messages, or JSON state to evaluate. Messages are sent as a native
|
|
43
|
+
* conversation; JSON objects, which may contain messages, as an `input_json` part.
|
|
44
|
+
*/
|
|
45
|
+
export type DecisionInput = string | BaseMessage | BaseMessage[] | Record<string, unknown> | Record<string, unknown>[];
|
|
46
|
+
/** One Decisions request: what to evaluate and the named questions to ask. */
|
|
47
|
+
export interface DecisionRequest<Q extends Questions = Questions> {
|
|
48
|
+
input: DecisionInput;
|
|
49
|
+
questions: Q;
|
|
50
|
+
}
|
|
51
|
+
export interface DecisionResult<Q extends Questions = Questions> {
|
|
52
|
+
answers: Answers<Q>;
|
|
53
|
+
/** The model that answered, as reported by the API. */
|
|
54
|
+
model: string;
|
|
55
|
+
requestId?: string;
|
|
56
|
+
/** Read by LangSmith to record token usage on the traced run. */
|
|
57
|
+
usage_metadata: UsageMetadata;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["OpenAIClient"],"sources":["../../src/decisions/types.ts"],"mappings":";;;;iBAMiB;EACf;EACA;;;iBAIe,OAAO;EACtB;EACA;EACA,SAAS,OAAO;;;YAIN,QAAQA,OAAa,qBAAqB,mBAAmB;;iBAGxD;EACf;EACA;EACA,2BAA2B;;YAGjB,WAAW,YAAY,SAAS;YAEhC,YAAY,eAAe;YAE3B,kBAAkB,KAC5BA,OAAa,SAAS;YAIZ,aAAa,6BAA6B,KACpDA,OAAa,SAAS;EAGtB,QAAQ;EACR;IAAiB,OAAO;IAAG;;;;YAIjB,cAAc,KACxBA,OAAa,SAAS;YAIZ,gBAAgB,KAC1BA,OAAa,SAAS;YAIZ,SACR,kBACA,eACA,cACA;;YAGQ,UAAU,UAAU,YAAY,UAAU,YAClD,kBACA,UAAU,SACR,aAAa,cAAc,yBAC3B,UAAU,QACR;;YAII,QAAQ,UAAU,0BACjB,WAAW,IAAI,UAAU,EAAE,MAAM;;;;;YAOlC,yBAER,cACA,gBACA,0BACA;;iBAGa,gBAAgB,UAAU,YAAY;EACrD,OAAO;EACP,WAAW;;iBAGI,eAAe,UAAU,YAAY;EACpD,SAAS,QAAQ;;EAEjB;EACA;;EAEA,gBAAgB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/decisions/types.ts
|
|
2
|
+
/** Converts a named question to the shape the Decisions API expects. */
|
|
3
|
+
function toQuestionParam(name, question) {
|
|
4
|
+
const { type, instructions } = question;
|
|
5
|
+
if (type === "predicate") return {
|
|
6
|
+
type,
|
|
7
|
+
name,
|
|
8
|
+
instructions
|
|
9
|
+
};
|
|
10
|
+
if (type === "choice") return {
|
|
11
|
+
type,
|
|
12
|
+
name,
|
|
13
|
+
instructions,
|
|
14
|
+
choices: Object.entries(question.choices).map(([value, description]) => description == null ? { value } : {
|
|
15
|
+
value,
|
|
16
|
+
description
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
type,
|
|
21
|
+
name,
|
|
22
|
+
instructions,
|
|
23
|
+
levels: question.levels.map((level) => typeof level === "string" ? { label: level } : level)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { toQuestionParam };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/decisions/types.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport type { BaseMessage, UsageMetadata } from \"@langchain/core/messages\";\n\ntype QuestionParam = OpenAIClient.DecisionCreateParams[\"questions\"][number];\n\n/** Estimate the probability that a condition is true. */\nexport interface Predicate {\n type: \"predicate\";\n instructions: string;\n}\n\n/** Select one option. Keys are the option values; values describe when each applies. */\nexport interface Choice<K extends string = string> {\n type: \"choice\";\n instructions: string;\n choices: Record<K, string | null>;\n}\n\n/** One level of a `Score` rubric. */\nexport type Level = OpenAIClient.DecisionCreateParams.QuestionParamScore.Level;\n\n/** Rate the input against two or more levels, ordered lowest to highest. */\nexport interface Score {\n type: \"score\";\n instructions: string;\n levels: readonly (string | Level)[];\n}\n\nexport type Question = Predicate | Choice | Score;\n\nexport type Questions = Record<string, Question>;\n\nexport type PredicateAnswer = Omit<\n OpenAIClient.Decision.AnswerResourcePredicate,\n \"name\"\n>;\n\nexport type ChoiceAnswer<K extends string = string> = Omit<\n OpenAIClient.Decision.AnswerResourceChoice,\n \"name\" | \"choice\" | \"probabilities\"\n> & {\n choice: K;\n probabilities: { value: K; probability: number }[];\n};\n\n/** `score` is the probability-weighted average of the zero-based level indices. */\nexport type ScoreAnswer = Omit<\n OpenAIClient.Decision.AnswerResourceScore,\n \"name\"\n>;\n\nexport type RefusalAnswer = Omit<\n OpenAIClient.Decision.AnswerResourceRefusal,\n \"name\"\n>;\n\nexport type Answer =\n | PredicateAnswer\n | ChoiceAnswer\n | ScoreAnswer\n | RefusalAnswer;\n\n/** The answer type a question produces. */\nexport type AnswerFor<T extends Question> = T extends Predicate\n ? PredicateAnswer\n : T extends Choice\n ? ChoiceAnswer<Extract<keyof T[\"choices\"], string>>\n : T extends Score\n ? ScoreAnswer\n : never;\n\n/** Answers keyed by question name, typed from the questions that were asked. */\nexport type Answers<Q extends Questions> = {\n -readonly [K in keyof Q]: AnswerFor<Q[K]> | RefusalAnswer;\n};\n\n/**\n * Text, LangChain messages, or JSON state to evaluate. Messages are sent as a native\n * conversation; JSON objects, which may contain messages, as an `input_json` part.\n */\nexport type DecisionInput =\n | string\n | BaseMessage\n | BaseMessage[]\n | Record<string, unknown>\n | Record<string, unknown>[];\n\n/** One Decisions request: what to evaluate and the named questions to ask. */\nexport interface DecisionRequest<Q extends Questions = Questions> {\n input: DecisionInput;\n questions: Q;\n}\n\nexport interface DecisionResult<Q extends Questions = Questions> {\n answers: Answers<Q>;\n /** The model that answered, as reported by the API. */\n model: string;\n requestId?: string;\n /** Read by LangSmith to record token usage on the traced run. */\n usage_metadata: UsageMetadata;\n}\n\n/** Converts a named question to the shape the Decisions API expects. */\nexport function toQuestionParam(\n name: string,\n question: Question\n): QuestionParam {\n const { type, instructions } = question;\n if (type === \"predicate\") return { type, name, instructions };\n if (type === \"choice\") {\n return {\n type,\n name,\n instructions,\n choices: Object.entries(question.choices).map(([value, description]) =>\n description == null ? { value } : { value, description }\n ),\n };\n }\n return {\n type,\n name,\n instructions,\n levels: question.levels.map((level) =>\n typeof level === \"string\" ? { label: level } : level\n ),\n };\n}\n"],"mappings":";;AAuGA,SAAgB,gBACd,MACA,UACe;CACf,MAAM,EAAE,MAAM,iBAAiB;CAC/B,IAAI,SAAS,aAAa,OAAO;EAAE;EAAM;EAAM;CAAa;CAC5D,IAAI,SAAS,UACX,OAAO;EACL;EACA;EACA;EACA,SAAS,OAAO,QAAQ,SAAS,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,iBACrD,eAAe,OAAO,EAAE,MAAM,IAAI;GAAE;GAAO;EAAY,CACzD;CACF;CAEF,OAAO;EACL;EACA;EACA;EACA,QAAQ,SAAS,OAAO,KAAK,UAC3B,OAAO,UAAU,WAAW,EAAE,OAAO,MAAM,IAAI,KACjD;CACF;AACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ const require_index$2 = require("./tools/index.cjs");
|
|
|
22
22
|
const require_custom = require("./tools/custom.cjs");
|
|
23
23
|
const require_prompts = require("./utils/prompts.cjs");
|
|
24
24
|
require("./converters/index.cjs");
|
|
25
|
+
const require_index$4 = require("./decisions/index.cjs");
|
|
25
26
|
let openai = require("openai");
|
|
26
27
|
let _langchain_core_language_models_openai_completions_stream = require("@langchain/core/language_models/openai_completions_stream");
|
|
27
28
|
exports.AzureChatOpenAI = require_index$1.AzureChatOpenAI;
|
|
@@ -41,6 +42,7 @@ Object.defineProperty(exports, "OpenAIClient", {
|
|
|
41
42
|
return openai.OpenAI;
|
|
42
43
|
}
|
|
43
44
|
});
|
|
45
|
+
exports.OpenAIDecisions = require_index$4.OpenAIDecisions;
|
|
44
46
|
exports.OpenAIEmbeddings = require_embeddings.OpenAIEmbeddings;
|
|
45
47
|
exports.completionsApiContentBlockConverter = require_completions.completionsApiContentBlockConverter;
|
|
46
48
|
exports.convertCompletionsDeltaToBaseMessageChunk = require_completions.convertCompletionsDeltaToBaseMessageChunk;
|
package/dist/index.d.cts
CHANGED
|
@@ -33,5 +33,7 @@ import { ConvertOpenAIResponsesStreamOptions, convertOpenAIResponsesStream } fro
|
|
|
33
33
|
import { completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage } from "./converters/completions.cjs";
|
|
34
34
|
import { ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, convertMessagesToResponsesInput, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentMessageToResponsesInput } from "./converters/responses.cjs";
|
|
35
35
|
import "./converters/index.cjs";
|
|
36
|
+
import { Answer, AnswerFor, Answers, Choice, ChoiceAnswer, DecisionInput, DecisionRequest, DecisionResult, Level, Predicate, PredicateAnswer, Question, Questions, RefusalAnswer, Score, ScoreAnswer } from "./decisions/types.cjs";
|
|
37
|
+
import { OpenAIDecisions, OpenAIDecisionsFields } from "./decisions/index.cjs";
|
|
36
38
|
import { ClientOptions, OpenAI as OpenAIClient, toFile } from "openai";
|
|
37
|
-
export { type ApplyPatchCreateFileOperation, type ApplyPatchDeleteFileOperation, type ApplyPatchOperation, type ApplyPatchOptions, type ApplyPatchTool, type ApplyPatchUpdateFileOperation, AzureChatOpenAI, AzureChatOpenAICompletions, type AzureChatOpenAIFields, AzureChatOpenAIResponses, AzureOpenAI, AzureOpenAIChatInput, AzureOpenAIEmbeddings, AzureOpenAIInput, BaseChatOpenAI, type BaseChatOpenAICallOptions, type BaseChatOpenAIFields, ChatOpenAI, type ChatOpenAICallOptions, ChatOpenAICompletions, type ChatOpenAICompletionsCallOptions, type ChatOpenAIFields, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, ChatOpenAIResponses, type ChatOpenAIResponsesCallOptions, type ClientOptions, type CodeInterpreterAutoContainer, type CodeInterpreterMemoryLimit, type CodeInterpreterOptions, type CodeInterpreterTool, type ComputerUseAction, type ComputerUseClickAction, type ComputerUseDoubleClickAction, type ComputerUseDragAction, type ComputerUseEnvironment, type ComputerUseInput, type ComputerUseKeypressAction, type ComputerUseMoveAction, type ComputerUseOptions, type ComputerUseScreenshotAction, type ComputerUseScrollAction, type ComputerUseTool, type ComputerUseTypeAction, type ComputerUseWaitAction, type ConvertOpenAICompletionsStreamOptions, type ConvertOpenAIResponsesStreamOptions, DallEAPIWrapper, DallEAPIWrapperParams, type FileSearchComparisonFilter, type FileSearchComparisonType, type FileSearchCompoundFilter, type FileSearchFilter, type FileSearchHybridSearchWeights, type FileSearchOptions, type FileSearchRankingOptions, type FileSearchTool, HeadersLike, type ImageGenerationInputMask, type ImageGenerationOptions, type ImageGenerationTool, type LocalShellAction, type LocalShellOptions, type LocalShellTool, type McpApprovalFilter, type McpConnectorId, type McpConnectorOptions, type McpRemoteServerOptions, type McpTool, type McpToolFilter, OpenAI, OpenAIApiKey, OpenAIBaseInput, OpenAICacheRetentionParam, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAIClient, OpenAICoreRequestOptions, OpenAIEmbeddingModelId, OpenAIEmbeddings, OpenAIEmbeddingsParams, OpenAIEndpointConfig, OpenAIImageModelId, OpenAIInput, OpenAIPromptCacheOptions, OpenAIVerbosityParam, ResponseFormatConfiguration, ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, type ShellAction, type ShellCallOutcome, type ShellCommandOutput, type ShellOptions, type ShellResult, type ShellTool, type TiktokenModel, type ToolSearchOptions, type ToolSearchTool, type WebSearchFilters, type WebSearchOptions, type WebSearchTool, completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertMessagesToResponsesInput, convertOpenAICompletionsStream, convertOpenAIResponsesStream, convertPromptToOpenAI, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage, convertStandardContentMessageToResponsesInput, customTool, getEndpoint, getFormattedEnv, getHeadersWithUserAgent, isHeaders, messageToOpenAIRole, normalizeHeaders, toFile, tools, wrapOpenAIClientError };
|
|
39
|
+
export { type Answer, type AnswerFor, type Answers, type ApplyPatchCreateFileOperation, type ApplyPatchDeleteFileOperation, type ApplyPatchOperation, type ApplyPatchOptions, type ApplyPatchTool, type ApplyPatchUpdateFileOperation, AzureChatOpenAI, AzureChatOpenAICompletions, type AzureChatOpenAIFields, AzureChatOpenAIResponses, AzureOpenAI, AzureOpenAIChatInput, AzureOpenAIEmbeddings, AzureOpenAIInput, BaseChatOpenAI, type BaseChatOpenAICallOptions, type BaseChatOpenAIFields, ChatOpenAI, type ChatOpenAICallOptions, ChatOpenAICompletions, type ChatOpenAICompletionsCallOptions, type ChatOpenAIFields, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, ChatOpenAIResponses, type ChatOpenAIResponsesCallOptions, type Choice, type ChoiceAnswer, type ClientOptions, type CodeInterpreterAutoContainer, type CodeInterpreterMemoryLimit, type CodeInterpreterOptions, type CodeInterpreterTool, type ComputerUseAction, type ComputerUseClickAction, type ComputerUseDoubleClickAction, type ComputerUseDragAction, type ComputerUseEnvironment, type ComputerUseInput, type ComputerUseKeypressAction, type ComputerUseMoveAction, type ComputerUseOptions, type ComputerUseScreenshotAction, type ComputerUseScrollAction, type ComputerUseTool, type ComputerUseTypeAction, type ComputerUseWaitAction, type ConvertOpenAICompletionsStreamOptions, type ConvertOpenAIResponsesStreamOptions, DallEAPIWrapper, DallEAPIWrapperParams, type DecisionInput, type DecisionRequest, type DecisionResult, type FileSearchComparisonFilter, type FileSearchComparisonType, type FileSearchCompoundFilter, type FileSearchFilter, type FileSearchHybridSearchWeights, type FileSearchOptions, type FileSearchRankingOptions, type FileSearchTool, HeadersLike, type ImageGenerationInputMask, type ImageGenerationOptions, type ImageGenerationTool, type Level, type LocalShellAction, type LocalShellOptions, type LocalShellTool, type McpApprovalFilter, type McpConnectorId, type McpConnectorOptions, type McpRemoteServerOptions, type McpTool, type McpToolFilter, OpenAI, OpenAIApiKey, OpenAIBaseInput, OpenAICacheRetentionParam, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAIClient, OpenAICoreRequestOptions, OpenAIDecisions, OpenAIDecisionsFields, OpenAIEmbeddingModelId, OpenAIEmbeddings, OpenAIEmbeddingsParams, OpenAIEndpointConfig, OpenAIImageModelId, OpenAIInput, OpenAIPromptCacheOptions, OpenAIVerbosityParam, type Predicate, type PredicateAnswer, type Question, type Questions, type RefusalAnswer, ResponseFormatConfiguration, ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, type Score, type ScoreAnswer, type ShellAction, type ShellCallOutcome, type ShellCommandOutput, type ShellOptions, type ShellResult, type ShellTool, type TiktokenModel, type ToolSearchOptions, type ToolSearchTool, type WebSearchFilters, type WebSearchOptions, type WebSearchTool, completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertMessagesToResponsesInput, convertOpenAICompletionsStream, convertOpenAIResponsesStream, convertPromptToOpenAI, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage, convertStandardContentMessageToResponsesInput, customTool, getEndpoint, getFormattedEnv, getHeadersWithUserAgent, isHeaders, messageToOpenAIRole, normalizeHeaders, toFile, tools, wrapOpenAIClientError };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,5 +33,7 @@ import { ConvertOpenAIResponsesStreamOptions, convertOpenAIResponsesStream } fro
|
|
|
33
33
|
import { completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage } from "./converters/completions.js";
|
|
34
34
|
import { ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, convertMessagesToResponsesInput, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentMessageToResponsesInput } from "./converters/responses.js";
|
|
35
35
|
import "./converters/index.js";
|
|
36
|
+
import { Answer, AnswerFor, Answers, Choice, ChoiceAnswer, DecisionInput, DecisionRequest, DecisionResult, Level, Predicate, PredicateAnswer, Question, Questions, RefusalAnswer, Score, ScoreAnswer } from "./decisions/types.js";
|
|
37
|
+
import { OpenAIDecisions, OpenAIDecisionsFields } from "./decisions/index.js";
|
|
36
38
|
import { ClientOptions, OpenAI as OpenAIClient, toFile } from "openai";
|
|
37
|
-
export { type ApplyPatchCreateFileOperation, type ApplyPatchDeleteFileOperation, type ApplyPatchOperation, type ApplyPatchOptions, type ApplyPatchTool, type ApplyPatchUpdateFileOperation, AzureChatOpenAI, AzureChatOpenAICompletions, type AzureChatOpenAIFields, AzureChatOpenAIResponses, AzureOpenAI, AzureOpenAIChatInput, AzureOpenAIEmbeddings, AzureOpenAIInput, BaseChatOpenAI, type BaseChatOpenAICallOptions, type BaseChatOpenAIFields, ChatOpenAI, type ChatOpenAICallOptions, ChatOpenAICompletions, type ChatOpenAICompletionsCallOptions, type ChatOpenAIFields, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, ChatOpenAIResponses, type ChatOpenAIResponsesCallOptions, type ClientOptions, type CodeInterpreterAutoContainer, type CodeInterpreterMemoryLimit, type CodeInterpreterOptions, type CodeInterpreterTool, type ComputerUseAction, type ComputerUseClickAction, type ComputerUseDoubleClickAction, type ComputerUseDragAction, type ComputerUseEnvironment, type ComputerUseInput, type ComputerUseKeypressAction, type ComputerUseMoveAction, type ComputerUseOptions, type ComputerUseScreenshotAction, type ComputerUseScrollAction, type ComputerUseTool, type ComputerUseTypeAction, type ComputerUseWaitAction, type ConvertOpenAICompletionsStreamOptions, type ConvertOpenAIResponsesStreamOptions, DallEAPIWrapper, DallEAPIWrapperParams, type FileSearchComparisonFilter, type FileSearchComparisonType, type FileSearchCompoundFilter, type FileSearchFilter, type FileSearchHybridSearchWeights, type FileSearchOptions, type FileSearchRankingOptions, type FileSearchTool, HeadersLike, type ImageGenerationInputMask, type ImageGenerationOptions, type ImageGenerationTool, type LocalShellAction, type LocalShellOptions, type LocalShellTool, type McpApprovalFilter, type McpConnectorId, type McpConnectorOptions, type McpRemoteServerOptions, type McpTool, type McpToolFilter, OpenAI, OpenAIApiKey, OpenAIBaseInput, OpenAICacheRetentionParam, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAIClient, OpenAICoreRequestOptions, OpenAIEmbeddingModelId, OpenAIEmbeddings, OpenAIEmbeddingsParams, OpenAIEndpointConfig, OpenAIImageModelId, OpenAIInput, OpenAIPromptCacheOptions, OpenAIVerbosityParam, ResponseFormatConfiguration, ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, type ShellAction, type ShellCallOutcome, type ShellCommandOutput, type ShellOptions, type ShellResult, type ShellTool, type TiktokenModel, type ToolSearchOptions, type ToolSearchTool, type WebSearchFilters, type WebSearchOptions, type WebSearchTool, completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertMessagesToResponsesInput, convertOpenAICompletionsStream, convertOpenAIResponsesStream, convertPromptToOpenAI, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage, convertStandardContentMessageToResponsesInput, customTool, getEndpoint, getFormattedEnv, getHeadersWithUserAgent, isHeaders, messageToOpenAIRole, normalizeHeaders, toFile, tools, wrapOpenAIClientError };
|
|
39
|
+
export { type Answer, type AnswerFor, type Answers, type ApplyPatchCreateFileOperation, type ApplyPatchDeleteFileOperation, type ApplyPatchOperation, type ApplyPatchOptions, type ApplyPatchTool, type ApplyPatchUpdateFileOperation, AzureChatOpenAI, AzureChatOpenAICompletions, type AzureChatOpenAIFields, AzureChatOpenAIResponses, AzureOpenAI, AzureOpenAIChatInput, AzureOpenAIEmbeddings, AzureOpenAIInput, BaseChatOpenAI, type BaseChatOpenAICallOptions, type BaseChatOpenAIFields, ChatOpenAI, type ChatOpenAICallOptions, ChatOpenAICompletions, type ChatOpenAICompletionsCallOptions, type ChatOpenAIFields, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, ChatOpenAIResponses, type ChatOpenAIResponsesCallOptions, type Choice, type ChoiceAnswer, type ClientOptions, type CodeInterpreterAutoContainer, type CodeInterpreterMemoryLimit, type CodeInterpreterOptions, type CodeInterpreterTool, type ComputerUseAction, type ComputerUseClickAction, type ComputerUseDoubleClickAction, type ComputerUseDragAction, type ComputerUseEnvironment, type ComputerUseInput, type ComputerUseKeypressAction, type ComputerUseMoveAction, type ComputerUseOptions, type ComputerUseScreenshotAction, type ComputerUseScrollAction, type ComputerUseTool, type ComputerUseTypeAction, type ComputerUseWaitAction, type ConvertOpenAICompletionsStreamOptions, type ConvertOpenAIResponsesStreamOptions, DallEAPIWrapper, DallEAPIWrapperParams, type DecisionInput, type DecisionRequest, type DecisionResult, type FileSearchComparisonFilter, type FileSearchComparisonType, type FileSearchCompoundFilter, type FileSearchFilter, type FileSearchHybridSearchWeights, type FileSearchOptions, type FileSearchRankingOptions, type FileSearchTool, HeadersLike, type ImageGenerationInputMask, type ImageGenerationOptions, type ImageGenerationTool, type Level, type LocalShellAction, type LocalShellOptions, type LocalShellTool, type McpApprovalFilter, type McpConnectorId, type McpConnectorOptions, type McpRemoteServerOptions, type McpTool, type McpToolFilter, OpenAI, OpenAIApiKey, OpenAIBaseInput, OpenAICacheRetentionParam, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAIClient, OpenAICoreRequestOptions, OpenAIDecisions, OpenAIDecisionsFields, OpenAIEmbeddingModelId, OpenAIEmbeddings, OpenAIEmbeddingsParams, OpenAIEndpointConfig, OpenAIImageModelId, OpenAIInput, OpenAIPromptCacheOptions, OpenAIVerbosityParam, type Predicate, type PredicateAnswer, type Question, type Questions, type RefusalAnswer, ResponseFormatConfiguration, ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, type Score, type ScoreAnswer, type ShellAction, type ShellCallOutcome, type ShellCommandOutput, type ShellOptions, type ShellResult, type ShellTool, type TiktokenModel, type ToolSearchOptions, type ToolSearchTool, type WebSearchFilters, type WebSearchOptions, type WebSearchTool, completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertMessagesToResponsesInput, convertOpenAICompletionsStream, convertOpenAIResponsesStream, convertPromptToOpenAI, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage, convertStandardContentMessageToResponsesInput, customTool, getEndpoint, getFormattedEnv, getHeadersWithUserAgent, isHeaders, messageToOpenAIRole, normalizeHeaders, toFile, tools, wrapOpenAIClientError };
|
package/dist/index.js
CHANGED
|
@@ -21,5 +21,6 @@ import { tools } from "./tools/index.js";
|
|
|
21
21
|
import { customTool } from "./tools/custom.js";
|
|
22
22
|
import { convertPromptToOpenAI } from "./utils/prompts.js";
|
|
23
23
|
import "./converters/index.js";
|
|
24
|
+
import { OpenAIDecisions } from "./decisions/index.js";
|
|
24
25
|
import { OpenAI as OpenAIClient, toFile } from "openai";
|
|
25
|
-
export { AzureChatOpenAI, AzureChatOpenAICompletions, AzureChatOpenAIResponses, AzureOpenAI, AzureOpenAIEmbeddings, BaseChatOpenAI, ChatOpenAI, ChatOpenAICompletions, ChatOpenAIResponses, DallEAPIWrapper, OpenAI, OpenAIClient, OpenAIEmbeddings, completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertMessagesToResponsesInput, convertOpenAICompletionsStream, convertOpenAIResponsesStream, convertPromptToOpenAI, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage, convertStandardContentMessageToResponsesInput, customTool, getEndpoint, getFormattedEnv, getHeadersWithUserAgent, isHeaders, messageToOpenAIRole, normalizeHeaders, toFile, tools, wrapOpenAIClientError };
|
|
26
|
+
export { AzureChatOpenAI, AzureChatOpenAICompletions, AzureChatOpenAIResponses, AzureOpenAI, AzureOpenAIEmbeddings, BaseChatOpenAI, ChatOpenAI, ChatOpenAICompletions, ChatOpenAIResponses, DallEAPIWrapper, OpenAI, OpenAIClient, OpenAIDecisions, OpenAIEmbeddings, completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertMessagesToResponsesInput, convertOpenAICompletionsStream, convertOpenAIResponsesStream, convertPromptToOpenAI, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage, convertStandardContentMessageToResponsesInput, customTool, getEndpoint, getFormattedEnv, getHeadersWithUserAgent, isHeaders, messageToOpenAIRole, normalizeHeaders, toFile, tools, wrapOpenAIClientError };
|
package/dist/llms.cjs
CHANGED
|
@@ -82,7 +82,7 @@ var OpenAI = class extends _langchain_core_language_models_llms.BaseLLM {
|
|
|
82
82
|
clientConfig;
|
|
83
83
|
constructor(fields) {
|
|
84
84
|
super(fields ?? {});
|
|
85
|
-
this._addVersion("@langchain/openai", "1.
|
|
85
|
+
this._addVersion("@langchain/openai", "1.8.0");
|
|
86
86
|
this.openAIApiKey = fields?.apiKey ?? fields?.openAIApiKey ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("OPENAI_API_KEY");
|
|
87
87
|
this.apiKey = this.openAIApiKey;
|
|
88
88
|
this.organization = fields?.configuration?.organization ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("OPENAI_ORGANIZATION");
|
package/dist/llms.js
CHANGED
|
@@ -82,7 +82,7 @@ var OpenAI$2 = class extends BaseLLM {
|
|
|
82
82
|
clientConfig;
|
|
83
83
|
constructor(fields) {
|
|
84
84
|
super(fields ?? {});
|
|
85
|
-
this._addVersion("@langchain/openai", "1.
|
|
85
|
+
this._addVersion("@langchain/openai", "1.8.0");
|
|
86
86
|
this.openAIApiKey = fields?.apiKey ?? fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
|
|
87
87
|
this.apiKey = this.openAIApiKey;
|
|
88
88
|
this.organization = fields?.configuration?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"author": "LangChain",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/providers/langchain-openai/",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"js-tiktoken": "^1.0.12",
|
|
18
|
-
"openai": "^7.
|
|
18
|
+
"openai": "^7.45.1",
|
|
19
19
|
"zod": "^3.25.76 || ^4"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@langchain/core": "^1.3.
|
|
22
|
+
"@langchain/core": "^1.3.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@azure/identity": "^4.13.3",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typescript": "~7.0.2",
|
|
34
34
|
"vitest": "^5.0.2",
|
|
35
35
|
"zod-to-json-schema": "^3.25.2",
|
|
36
|
-
"@langchain/core": "^1.3.
|
|
36
|
+
"@langchain/core": "^1.3.1",
|
|
37
37
|
"@langchain/standard-tests": "0.0.23",
|
|
38
38
|
"@langchain/tsconfig": "0.0.1"
|
|
39
39
|
},
|