Spaces:
Running
Running
File size: 2,745 Bytes
8559a03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
/*
* This file patches OpenAI SDK types for OpenResponses spec compliance.
*
* The OpenAI SDK uses event type names like "response.reasoning_text.delta",
* but the OpenResponses spec uses "response.reasoning.delta" (without "_text").
* We maintain custom event types here to match the OpenResponses specification.
*
* Once the OpenAI SDK aligns with OpenResponses spec, this file can be simplified.
*/
import type {
ResponseReasoningItem as OpenAIResponseReasoningItem,
ResponseStreamEvent as OpenAIResponseStreamEvent,
ResponseOutputRefusal,
ResponseOutputText,
ResponseContentPartAddedEvent,
ResponseContentPartDoneEvent,
ResponseTextDeltaEvent,
ResponseTextDoneEvent,
} from "openai/resources/responses/responses";
import type { ChatCompletionChunk } from "openai/resources/chat/completions";
export interface ReasoningTextContent {
type: "reasoning_text";
text: string;
}
export type PatchedResponseReasoningItem = OpenAIResponseReasoningItem & {
// Raw CoT returned in reasoning item (in addition to the summary)
content: ReasoningTextContent[];
};
// Custom event types for OpenResponses spec (differs from SDK's "response.reasoning_text.*")
interface PatchedResponseReasoningDeltaEvent {
type: "response.reasoning.delta";
sequence_number: number;
item_id: string;
output_index: number;
content_index: number;
delta: string;
}
interface PatchedResponseReasoningDoneEvent {
type: "response.reasoning.done";
sequence_number: number;
item_id: string;
output_index: number;
content_index: number;
text: string;
}
export type PatchedResponseStreamEvent =
| OpenAIResponseStreamEvent
| PatchedResponseReasoningDeltaEvent
| PatchedResponseReasoningDoneEvent
| PatchedResponseContentPartAddedEvent
| PatchedResponseContentPartDoneEvent
| PatchedResponseOutputTextDeltaEvent
| PatchedResponseOutputTextDoneEvent;
export type PatchedResponseContentPart = ResponseOutputText | ResponseOutputRefusal | ReasoningTextContent;
export interface PatchedResponseOutputTextDeltaEvent extends ResponseTextDeltaEvent {
logprobs: unknown[];
}
export interface PatchedResponseOutputTextDoneEvent extends ResponseTextDoneEvent {
logprobs: unknown[];
}
interface PatchedResponseContentPartAddedEvent {
content_index: number;
item_id: string;
output_index: number;
part: PatchedResponseContentPart;
sequence_number: number;
type: "response.content_part.added";
}
interface PatchedResponseContentPartDoneEvent {
content_index: number;
item_id: string;
output_index: number;
part: PatchedResponseContentPart;
sequence_number: number;
type: "response.content_part.done";
}
export type PatchedDeltaWithReasoning = ChatCompletionChunk.Choice.Delta & {
reasoning?: string;
reasoning_content?: string;
};
|