mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix(ai): preserve raw OpenAI response statuses
This commit is contained in:
parent
fe1c9b6d52
commit
e5ef8d0654
2 changed files with 7 additions and 1 deletions
|
|
@ -563,7 +563,9 @@ export async function processResponsesStream<TApi extends Api>(
|
|||
options.applyServiceTierPricing(output.usage, serviceTier);
|
||||
}
|
||||
// Map status to stop reason
|
||||
output.stopReason = mapStopReason(response?.status);
|
||||
const status = response?.status;
|
||||
output.rawStopReason = status;
|
||||
output.stopReason = mapStopReason(status);
|
||||
if (output.content.some((b) => b.type === "toolCall") && output.stopReason === "stop") {
|
||||
output.stopReason = "toolUse";
|
||||
}
|
||||
|
|
@ -716,6 +718,7 @@ export async function processResponsesStream<TApi extends Api>(
|
|||
throw new Error(`Error Code ${event.code}: ${event.message}` || "Unknown error");
|
||||
} else if (event.type === "response.failed") {
|
||||
sawTerminalResponseEvent = true;
|
||||
output.rawStopReason = event.response?.status;
|
||||
const error = event.response?.error;
|
||||
const details = event.response?.incomplete_details;
|
||||
const msg = error
|
||||
|
|
|
|||
|
|
@ -285,6 +285,7 @@ describe("OpenAI Responses terminal event handling", () => {
|
|||
|
||||
expect(output.responseId).toBe("resp_completed");
|
||||
expect(output.stopReason).toBe("stop");
|
||||
expect(output.rawStopReason).toBe("completed");
|
||||
expect(output.usage).toMatchObject({
|
||||
input: 15,
|
||||
output: 7,
|
||||
|
|
@ -303,6 +304,7 @@ describe("OpenAI Responses terminal event handling", () => {
|
|||
|
||||
expect(output.responseId).toBe("resp_incomplete");
|
||||
expect(output.stopReason).toBe("length");
|
||||
expect(output.rawStopReason).toBe("incomplete");
|
||||
expect(output.usage).toMatchObject({
|
||||
input: 25,
|
||||
output: 12,
|
||||
|
|
@ -320,5 +322,6 @@ describe("OpenAI Responses terminal event handling", () => {
|
|||
await expect(processResponsesStream(createFailedEvents(), output, stream, model)).rejects.toThrow(
|
||||
"server_error: boom",
|
||||
);
|
||||
expect(output.rawStopReason).toBe("failed");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue