Skip to content

Commit 5d0249d

Browse files
committed
test: add strict tool-calling tests + format responses.ts
1 parent 33d7dd7 commit 5d0249d

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

libs/providers/langchain-openai/src/chat_models/responses.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,32 @@ export class ChatOpenAIResponses<
9191
include: options?.include,
9292
tools: options?.tools?.length
9393
? this._reduceChatOpenAITools(options.tools, {
94-
stream: this.streaming,
95-
strict,
96-
})
94+
stream: this.streaming,
95+
strict,
96+
})
9797
: undefined,
9898
tool_choice: isBuiltInToolChoice(options?.tool_choice)
9999
? options?.tool_choice
100100
: (() => {
101-
const formatted = formatToOpenAIToolChoice(options?.tool_choice);
102-
if (typeof formatted === "object" && "type" in formatted) {
103-
if (formatted.type === "function") {
104-
return { type: "function", name: formatted.function.name };
105-
} else if (formatted.type === "allowed_tools") {
106-
return {
107-
type: "allowed_tools",
108-
mode: formatted.allowed_tools.mode,
109-
tools: formatted.allowed_tools.tools,
110-
};
111-
} else if (formatted.type === "custom") {
112-
return {
113-
type: "custom",
114-
name: formatted.custom.name,
115-
};
101+
const formatted = formatToOpenAIToolChoice(options?.tool_choice);
102+
if (typeof formatted === "object" && "type" in formatted) {
103+
if (formatted.type === "function") {
104+
return { type: "function", name: formatted.function.name };
105+
} else if (formatted.type === "allowed_tools") {
106+
return {
107+
type: "allowed_tools",
108+
mode: formatted.allowed_tools.mode,
109+
tools: formatted.allowed_tools.tools,
110+
};
111+
} else if (formatted.type === "custom") {
112+
return {
113+
type: "custom",
114+
name: formatted.custom.name,
115+
};
116+
}
116117
}
117-
}
118-
return undefined;
119-
})(),
118+
return undefined;
119+
})(),
120120
text: (() => {
121121
if (options?.text) return options.text;
122122
const format = this._getResponseFormat(options?.response_format);
@@ -201,10 +201,10 @@ export class ChatOpenAIResponses<
201201
id: data.id,
202202
estimatedTokenUsage: data.usage
203203
? {
204-
promptTokens: data.usage.input_tokens,
205-
completionTokens: data.usage.output_tokens,
206-
totalTokens: data.usage.total_tokens,
207-
}
204+
promptTokens: data.usage.input_tokens,
205+
completionTokens: data.usage.output_tokens,
206+
totalTokens: data.usage.total_tokens,
207+
}
208208
: undefined,
209209
},
210210
};

libs/providers/langchain-openai/src/chat_models/tests/responses.strict.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import { ChatOpenAIResponses } from "../responses";
2+
import { ChatOpenAIResponses } from "../responses.js";
33

44
describe("strict tool-calling configuration", () => {
55
it("falls back to supportsStrictToolCalling when strict is undefined", () => {
@@ -21,9 +21,15 @@ describe("strict tool-calling configuration", () => {
2121
],
2222
});
2323

24-
expect((params as any).strict).toBeUndefined();
24+
25+
expect(
26+
(params as unknown as { strict?: boolean }).strict
27+
).toBeUndefined();
2528

26-
expect((params.tools as any)[0].strict).toBe(true);
29+
30+
expect(
31+
(params.tools as unknown as Array<{ strict?: boolean }>)[0].strict
32+
).toBe(true);
2733
});
2834

2935
it("respects user-provided strict option", () => {
@@ -46,8 +52,14 @@ describe("strict tool-calling configuration", () => {
4652
],
4753
});
4854

49-
expect((params as any).strict).toBeUndefined();
5055

51-
expect((params.tools as any)[0].strict).toBe(false);
56+
expect(
57+
(params as unknown as { strict?: boolean }).strict
58+
).toBeUndefined();
59+
60+
61+
expect(
62+
(params.tools as unknown as Array<{ strict?: boolean }>)[0].strict
63+
).toBe(false);
5264
});
5365
});

0 commit comments

Comments
 (0)