























@@ -545,6 +545,34 @@ async function completeSimpleWithTimeout<TApi extends Api>(
545545}
546546}
547547548+function requireToolChoicePayload(payload: unknown): unknown | undefined {
549+if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
550+return undefined;
551+}
552+const candidate = payload as { tools?: unknown; tool_choice?: unknown };
553+if (!Array.isArray(candidate.tools) || candidate.tools.length === 0) {
554+return undefined;
555+}
556+return {
557+ ...candidate,
558+tool_choice: { type: "function", name: "noop" },
559+};
560+}
561+562+describe("requireToolChoicePayload", () => {
563+it("requires tool use when a Responses payload has tools", () => {
564+expect(requireToolChoicePayload({ model: "gpt", tools: [{ name: "noop" }] })).toEqual({
565+model: "gpt",
566+tools: [{ name: "noop" }],
567+tool_choice: { type: "function", name: "noop" },
568+});
569+});
570+571+it("leaves payloads without tools unchanged", () => {
572+expect(requireToolChoicePayload({ model: "gpt", tools: [] })).toBeUndefined();
573+});
574+});
575+548576async function completeOkWithRetry(params: {
549577model: Model<Api>;
550578apiKey: string;
@@ -982,6 +1010,7 @@ describeLive("live models (profile keys)", () => {
9821010 apiKey,
9831011reasoning: resolveTestReasoning(model),
9841012maxTokens: 128,
1013+onPayload: requireToolChoicePayload,
9851014},
9861015perModelTimeoutMs,
9871016`${progressLabel}: tool-only regression first call`,
@@ -1012,6 +1041,7 @@ describeLive("live models (profile keys)", () => {
10121041 apiKey,
10131042reasoning: resolveTestReasoning(model),
10141043maxTokens: 128,
1044+onPayload: requireToolChoicePayload,
10151045},
10161046perModelTimeoutMs,
10171047`${progressLabel}: tool-only regression retry ${i + 1}`,
@@ -1025,6 +1055,11 @@ describeLive("live models (profile keys)", () => {
10251055.trim();
10261056}
102710571058+if (first.stopReason === "error") {
1059+throw new Error(
1060+first.errorMessage || "tool-only regression returned error with no message",
1061+);
1062+}
10281063expect(firstText.length).toBe(0);
10291064if (!toolCall || toolCall.type !== "toolCall") {
10301065throw new Error("expected tool call");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。