Skip to content

Commit 1be3b10

Browse files
authored
feat(openai): bump sdk (#8639)
1 parent 5ed9e75 commit 1be3b10

File tree

6 files changed

+66
-23
lines changed

6 files changed

+66
-23
lines changed

langchain/src/agents/openai_tools/output_parser.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,26 @@ export class OpenAIToolsAgentOutputParser extends AgentMultiActionOutputParser {
7676
const toolCalls: OpenAIClient.Chat.ChatCompletionMessageToolCall[] =
7777
message.additional_kwargs.tool_calls;
7878
try {
79-
return toolCalls.map((toolCall, i) => {
80-
const toolInput = toolCall.function.arguments
81-
? JSON.parse(toolCall.function.arguments)
82-
: {};
83-
const messageLog = i === 0 ? [message] : [];
84-
return {
85-
tool: toolCall.function.name as string,
86-
toolInput,
87-
toolCallId: toolCall.id,
88-
log: `Invoking "${toolCall.function.name}" with ${
89-
toolCall.function.arguments ?? "{}"
90-
}\n${message.content}`,
91-
messageLog,
92-
};
93-
});
79+
return toolCalls
80+
.map((toolCall, i) => {
81+
if (toolCall.type === "function") {
82+
const toolInput = toolCall.function.arguments
83+
? JSON.parse(toolCall.function.arguments)
84+
: {};
85+
const messageLog = i === 0 ? [message] : [];
86+
return {
87+
tool: toolCall.function.name as string,
88+
toolInput,
89+
toolCallId: toolCall.id,
90+
log: `Invoking "${toolCall.function.name}" with ${
91+
toolCall.function.arguments ?? "{}"
92+
}\n${message.content}`,
93+
messageLog,
94+
};
95+
}
96+
return undefined;
97+
})
98+
.filter(Boolean) as ToolsAgentAction[];
9499
} catch (error) {
95100
throw new OutputParserException(
96101
`Failed to parse tool arguments from chat model response. Text: "${JSON.stringify(

libs/langchain-openai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"license": "MIT",
3737
"dependencies": {
3838
"js-tiktoken": "^1.0.12",
39-
"openai": "^5.3.0",
39+
"openai": "^5.12.1",
4040
"zod": "^3.25.32"
4141
},
4242
"peerDependencies": {

libs/langchain-openai/src/chat_models.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,22 @@ export class ChatOpenAIResponses<
14471447
: (() => {
14481448
const formatted = formatToOpenAIToolChoice(options?.tool_choice);
14491449
if (typeof formatted === "object" && "type" in formatted) {
1450-
return { type: "function", name: formatted.function.name };
1451-
} else {
1452-
return undefined;
1450+
if (formatted.type === "function") {
1451+
return { type: "function", name: formatted.function.name };
1452+
} else if (formatted.type === "allowed_tools") {
1453+
return {
1454+
type: "allowed_tools",
1455+
mode: formatted.allowed_tools.mode,
1456+
tools: formatted.allowed_tools.tools,
1457+
};
1458+
} else if (formatted.type === "custom") {
1459+
return {
1460+
type: "custom",
1461+
name: formatted.custom.name,
1462+
};
1463+
}
14531464
}
1465+
return undefined;
14541466
})(),
14551467
text: (() => {
14561468
if (options?.text) return options.text;
@@ -1740,7 +1752,7 @@ export class ChatOpenAIResponses<
17401752
text: chunk.delta,
17411753
index: chunk.content_index,
17421754
});
1743-
} else if (chunk.type === "response.output_text_annotation.added") {
1755+
} else if (chunk.type === "response.output_text.annotation.added") {
17441756
content.push({
17451757
type: "text",
17461758
text: "",

libs/langchain-openai/src/tests/chat_models.standard.int.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ChatOpenAIStandardIntegrationTests extends ChatModelIntegrationTests<
2626
chatModelHasStructuredOutput: true,
2727
supportsParallelToolCalls: true,
2828
constructorArgs: {
29-
model: "gpt-3.5-turbo",
29+
model: "gpt-5",
3030
},
3131
supportsStandardContentType: {
3232
text: true,

libs/langchain-openai/src/tests/chat_models_responses.int.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,12 @@ test("useResponsesApi=true should emit handleLLMNewToken events during streaming
823823
expect(startEvents.length).toBeGreaterThan(0);
824824
expect(endEvents.length).toBeGreaterThan(0);
825825
});
826+
827+
test("gpt-5", async () => {
828+
const model = new ChatOpenAI({ model: "gpt-5" });
829+
const response = await model.invoke(
830+
"Write a short story about a robot who discovers they can dream. Include themes of consciousness, identity, and what it means to be alive. The story should be approximately 200 words and have a hopeful ending."
831+
);
832+
expect(response).toBeDefined();
833+
console.log(response);
834+
});

yarn.lock

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9526,7 +9526,7 @@ __metadata:
95269526
jest: ^29.5.0
95279527
jest-environment-node: ^29.6.4
95289528
js-tiktoken: ^1.0.12
9529-
openai: ^5.3.0
9529+
openai: ^5.12.1
95309530
prettier: ^2.8.3
95319531
release-it: ^18.1.2
95329532
rimraf: ^5.0.1
@@ -31590,7 +31590,7 @@ __metadata:
3159031590
languageName: node
3159131591
linkType: hard
3159231592

31593-
"openai@npm:*, openai@npm:^5.3.0":
31593+
"openai@npm:*":
3159431594
version: 5.3.0
3159531595
resolution: "openai@npm:5.3.0"
3159631596
peerDependencies:
@@ -31668,6 +31668,23 @@ __metadata:
3166831668
languageName: node
3166931669
linkType: hard
3167031670

31671+
"openai@npm:^5.12.1":
31672+
version: 5.12.1
31673+
resolution: "openai@npm:5.12.1"
31674+
peerDependencies:
31675+
ws: ^8.18.0
31676+
zod: ^3.23.8
31677+
peerDependenciesMeta:
31678+
ws:
31679+
optional: true
31680+
zod:
31681+
optional: true
31682+
bin:
31683+
openai: bin/cli
31684+
checksum: 619d93623790a7f8609d6d58cbac8a293dc75439fdc4f2ce81563df4d02b5488bb15ee5dc69dcfe9cc5202b5f4e3290b5feecbec55a74945966c97e00bf2f6b8
31685+
languageName: node
31686+
linkType: hard
31687+
3167131688
"openapi-types@npm:^12.1.3":
3167231689
version: 12.1.3
3167331690
resolution: "openapi-types@npm:12.1.3"

0 commit comments

Comments
 (0)