Skip to content

Commit 5bd23f8

Browse files
committed
responses stream event ergonomics: event_type
1 parent 7617e80 commit 5bd23f8

File tree

1 file changed

+131
-1
lines changed

1 file changed

+131
-1
lines changed

async-openai/src/types/responses/stream.rs

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ pub struct ResponseFunctionCallArgumentsDeltaEvent {
275275

276276
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
277277
pub struct ResponseFunctionCallArgumentsDoneEvent {
278-
pub name: String,
278+
/// https://github.com/64bit/async-openai/issues/472
279+
pub name: Option<String>,
279280
pub sequence_number: u64,
280281
pub item_id: String,
281282
pub output_index: u32,
@@ -542,3 +543,132 @@ pub struct ResponseErrorEvent {
542543
pub message: String,
543544
pub param: Option<String>,
544545
}
546+
547+
use crate::traits::EventType;
548+
549+
// Implement EventType trait for all event types in this file
550+
551+
macro_rules! impl_event_type {
552+
($($ty:ty => $event_type:expr),* $(,)?) => {
553+
$(
554+
impl EventType for $ty {
555+
fn event_type(&self) -> &'static str {
556+
$event_type
557+
}
558+
}
559+
)*
560+
};
561+
}
562+
563+
// Apply macro for each event struct type in this file.
564+
impl_event_type! {
565+
ResponseCreatedEvent => "response.created",
566+
ResponseInProgressEvent => "response.in_progress",
567+
ResponseCompletedEvent => "response.completed",
568+
ResponseFailedEvent => "response.failed",
569+
ResponseIncompleteEvent => "response.incomplete",
570+
ResponseOutputItemAddedEvent => "response.output_item.added",
571+
ResponseOutputItemDoneEvent => "response.output_item.done",
572+
ResponseContentPartAddedEvent => "response.content_part.added",
573+
ResponseContentPartDoneEvent => "response.content_part.done",
574+
ResponseTextDeltaEvent => "response.output_text.delta",
575+
ResponseTextDoneEvent => "response.output_text.done",
576+
ResponseRefusalDeltaEvent => "response.refusal.delta",
577+
ResponseRefusalDoneEvent => "response.refusal.done",
578+
ResponseFunctionCallArgumentsDeltaEvent => "response.function_call_arguments.delta",
579+
ResponseFunctionCallArgumentsDoneEvent => "response.function_call_arguments.done",
580+
ResponseFileSearchCallInProgressEvent => "response.file_search_call.in_progress",
581+
ResponseFileSearchCallSearchingEvent => "response.file_search_call.searching",
582+
ResponseFileSearchCallCompletedEvent => "response.file_search_call.completed",
583+
ResponseWebSearchCallInProgressEvent => "response.web_search_call.in_progress",
584+
ResponseWebSearchCallSearchingEvent => "response.web_search_call.searching",
585+
ResponseWebSearchCallCompletedEvent => "response.web_search_call.completed",
586+
ResponseReasoningSummaryPartAddedEvent => "response.reasoning_summary_part.added",
587+
ResponseReasoningSummaryPartDoneEvent => "response.reasoning_summary_part.done",
588+
ResponseReasoningSummaryTextDeltaEvent => "response.reasoning_summary_text.delta",
589+
ResponseReasoningSummaryTextDoneEvent => "response.reasoning_summary_text.done",
590+
ResponseReasoningTextDeltaEvent => "response.reasoning_text.delta",
591+
ResponseReasoningTextDoneEvent => "response.reasoning_text.done",
592+
ResponseImageGenCallCompletedEvent => "response.image_generation_call.completed",
593+
ResponseImageGenCallGeneratingEvent => "response.image_generation_call.generating",
594+
ResponseImageGenCallInProgressEvent => "response.image_generation_call.in_progress",
595+
ResponseImageGenCallPartialImageEvent => "response.image_generation_call.partial_image",
596+
ResponseMCPCallArgumentsDeltaEvent => "response.mcp_call_arguments.delta",
597+
ResponseMCPCallArgumentsDoneEvent => "response.mcp_call_arguments.done",
598+
ResponseMCPCallCompletedEvent => "response.mcp_call.completed",
599+
ResponseMCPCallFailedEvent => "response.mcp_call.failed",
600+
ResponseMCPCallInProgressEvent => "response.mcp_call.in_progress",
601+
ResponseMCPListToolsCompletedEvent => "response.mcp_list_tools.completed",
602+
ResponseMCPListToolsFailedEvent => "response.mcp_list_tools.failed",
603+
ResponseMCPListToolsInProgressEvent => "response.mcp_list_tools.in_progress",
604+
ResponseCodeInterpreterCallInProgressEvent => "response.code_interpreter_call.in_progress",
605+
ResponseCodeInterpreterCallInterpretingEvent => "response.code_interpreter_call.interpreting",
606+
ResponseCodeInterpreterCallCompletedEvent => "response.code_interpreter_call.completed",
607+
ResponseCodeInterpreterCallCodeDeltaEvent => "response.code_interpreter_call_code.delta",
608+
ResponseCodeInterpreterCallCodeDoneEvent => "response.code_interpreter_call_code.done",
609+
ResponseOutputTextAnnotationAddedEvent => "response.output_text.annotation.added",
610+
ResponseQueuedEvent => "response.queued",
611+
ResponseCustomToolCallInputDeltaEvent => "response.custom_tool_call_input.delta",
612+
ResponseCustomToolCallInputDoneEvent => "response.custom_tool_call_input.done",
613+
ResponseErrorEvent => "error",
614+
}
615+
616+
impl EventType for ResponseStreamEvent {
617+
fn event_type(&self) -> &'static str {
618+
match self {
619+
ResponseStreamEvent::ResponseCreated(event) => event.event_type(),
620+
ResponseStreamEvent::ResponseInProgress(event) => event.event_type(),
621+
ResponseStreamEvent::ResponseCompleted(event) => event.event_type(),
622+
ResponseStreamEvent::ResponseFailed(event) => event.event_type(),
623+
ResponseStreamEvent::ResponseIncomplete(event) => event.event_type(),
624+
ResponseStreamEvent::ResponseOutputItemAdded(event) => event.event_type(),
625+
ResponseStreamEvent::ResponseOutputItemDone(event) => event.event_type(),
626+
ResponseStreamEvent::ResponseContentPartAdded(event) => event.event_type(),
627+
ResponseStreamEvent::ResponseContentPartDone(event) => event.event_type(),
628+
ResponseStreamEvent::ResponseOutputTextDelta(event) => event.event_type(),
629+
ResponseStreamEvent::ResponseOutputTextDone(event) => event.event_type(),
630+
ResponseStreamEvent::ResponseRefusalDelta(event) => event.event_type(),
631+
ResponseStreamEvent::ResponseRefusalDone(event) => event.event_type(),
632+
ResponseStreamEvent::ResponseFunctionCallArgumentsDelta(event) => event.event_type(),
633+
ResponseStreamEvent::ResponseFunctionCallArgumentsDone(event) => event.event_type(),
634+
ResponseStreamEvent::ResponseFileSearchCallInProgress(event) => event.event_type(),
635+
ResponseStreamEvent::ResponseFileSearchCallSearching(event) => event.event_type(),
636+
ResponseStreamEvent::ResponseFileSearchCallCompleted(event) => event.event_type(),
637+
ResponseStreamEvent::ResponseWebSearchCallInProgress(event) => event.event_type(),
638+
ResponseStreamEvent::ResponseWebSearchCallSearching(event) => event.event_type(),
639+
ResponseStreamEvent::ResponseWebSearchCallCompleted(event) => event.event_type(),
640+
ResponseStreamEvent::ResponseReasoningSummaryPartAdded(event) => event.event_type(),
641+
ResponseStreamEvent::ResponseReasoningSummaryPartDone(event) => event.event_type(),
642+
ResponseStreamEvent::ResponseReasoningSummaryTextDelta(event) => event.event_type(),
643+
ResponseStreamEvent::ResponseReasoningSummaryTextDone(event) => event.event_type(),
644+
ResponseStreamEvent::ResponseReasoningTextDelta(event) => event.event_type(),
645+
ResponseStreamEvent::ResponseReasoningTextDone(event) => event.event_type(),
646+
ResponseStreamEvent::ResponseImageGenerationCallCompleted(event) => event.event_type(),
647+
ResponseStreamEvent::ResponseImageGenerationCallGenerating(event) => event.event_type(),
648+
ResponseStreamEvent::ResponseImageGenerationCallInProgress(event) => event.event_type(),
649+
ResponseStreamEvent::ResponseImageGenerationCallPartialImage(event) => {
650+
event.event_type()
651+
}
652+
ResponseStreamEvent::ResponseMCPCallArgumentsDelta(event) => event.event_type(),
653+
ResponseStreamEvent::ResponseMCPCallArgumentsDone(event) => event.event_type(),
654+
ResponseStreamEvent::ResponseMCPCallCompleted(event) => event.event_type(),
655+
ResponseStreamEvent::ResponseMCPCallFailed(event) => event.event_type(),
656+
ResponseStreamEvent::ResponseMCPCallInProgress(event) => event.event_type(),
657+
ResponseStreamEvent::ResponseMCPListToolsCompleted(event) => event.event_type(),
658+
ResponseStreamEvent::ResponseMCPListToolsFailed(event) => event.event_type(),
659+
ResponseStreamEvent::ResponseMCPListToolsInProgress(event) => event.event_type(),
660+
ResponseStreamEvent::ResponseCodeInterpreterCallInProgress(event) => event.event_type(),
661+
ResponseStreamEvent::ResponseCodeInterpreterCallInterpreting(event) => {
662+
event.event_type()
663+
}
664+
ResponseStreamEvent::ResponseCodeInterpreterCallCompleted(event) => event.event_type(),
665+
ResponseStreamEvent::ResponseCodeInterpreterCallCodeDelta(event) => event.event_type(),
666+
ResponseStreamEvent::ResponseCodeInterpreterCallCodeDone(event) => event.event_type(),
667+
ResponseStreamEvent::ResponseOutputTextAnnotationAdded(event) => event.event_type(),
668+
ResponseStreamEvent::ResponseQueued(event) => event.event_type(),
669+
ResponseStreamEvent::ResponseCustomToolCallInputDelta(event) => event.event_type(),
670+
ResponseStreamEvent::ResponseCustomToolCallInputDone(event) => event.event_type(),
671+
ResponseStreamEvent::ResponseError(event) => event.event_type(),
672+
}
673+
}
674+
}

0 commit comments

Comments
 (0)