Skip to content

Commit 823b8d1

Browse files
committed
feat: response api stream event
1 parent d4e88a0 commit 823b8d1

28 files changed

+4327
-4
lines changed

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.47</version>
9+
<version>0.23.48</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212
<artifactId>openai-api</artifactId>

api/src/main/java/com/theokanning/openai/response/stream/BaseStreamEvent.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
@JsonSubTypes.Type(value = OutputItemAddedEvent.class, name = "response.output_item.added"),
2727
@JsonSubTypes.Type(value = OutputItemDoneEvent.class, name = "response.output_item.done"),
2828
@JsonSubTypes.Type(value = ContentPartAddedEvent.class, name = "response.content_part.added"),
29+
@JsonSubTypes.Type(value = ContentPartDoneEvent.class, name = "response.content_part.done"),
2930
@JsonSubTypes.Type(value = OutputTextDeltaEvent.class, name = "response.output_text.delta"),
3031
@JsonSubTypes.Type(value = OutputTextDoneEvent.class, name = "response.output_text.done"),
32+
@JsonSubTypes.Type(value = OutputTextAnnotationAddedEvent.class, name = "response.output_text.annotation.added"),
33+
@JsonSubTypes.Type(value = RefusalDeltaEvent.class, name = "response.refusal.delta"),
34+
@JsonSubTypes.Type(value = RefusalDoneEvent.class, name = "response.refusal.done"),
3135
@JsonSubTypes.Type(value = FunctionCallArgumentsDeltaEvent.class, name = "response.function_call_arguments.delta"),
3236
@JsonSubTypes.Type(value = FunctionCallArgumentsDoneEvent.class, name = "response.function_call_arguments.done"),
3337
@JsonSubTypes.Type(value = FileSearchInProgressEvent.class, name = "response.file_search_call.in_progress"),
@@ -42,7 +46,25 @@
4246
@JsonSubTypes.Type(value = CodeInterpreterCodeDeltaEvent.class, name = "response.code_interpreter_call_code.delta"),
4347
@JsonSubTypes.Type(value = CodeInterpreterCodeDoneEvent.class, name = "response.code_interpreter_call_code.done"),
4448
@JsonSubTypes.Type(value = ReasoningTextDeltaEvent.class, name = "response.reasoning_text.delta"),
49+
@JsonSubTypes.Type(value = ReasoningTextDoneEvent.class, name = "response.reasoning_text.done"),
50+
@JsonSubTypes.Type(value = ReasoningSummaryPartAddedEvent.class, name = "response.reasoning_summary_part.added"),
51+
@JsonSubTypes.Type(value = ReasoningSummaryPartDoneEvent.class, name = "response.reasoning_summary_part.done"),
4552
@JsonSubTypes.Type(value = ReasoningSummaryTextDeltaEvent.class, name = "response.reasoning_summary_text.delta"),
53+
@JsonSubTypes.Type(value = ReasoningSummaryTextDoneEvent.class, name = "response.reasoning_summary_text.done"),
54+
@JsonSubTypes.Type(value = ImageGenerationInProgressEvent.class, name = "response.image_generation_call.in_progress"),
55+
@JsonSubTypes.Type(value = ImageGenerationGeneratingEvent.class, name = "response.image_generation_call.generating"),
56+
@JsonSubTypes.Type(value = ImageGenerationCompletedEvent.class, name = "response.image_generation_call.completed"),
57+
@JsonSubTypes.Type(value = ImageGenerationPartialImageEvent.class, name = "response.image_generation_call.partial_image"),
58+
@JsonSubTypes.Type(value = McpCallArgumentsDeltaEvent.class, name = "response.mcp_call_arguments.delta"),
59+
@JsonSubTypes.Type(value = McpCallArgumentsDoneEvent.class, name = "response.mcp_call_arguments.done"),
60+
@JsonSubTypes.Type(value = McpCallInProgressEvent.class, name = "response.mcp_call.in_progress"),
61+
@JsonSubTypes.Type(value = McpCallCompletedEvent.class, name = "response.mcp_call.completed"),
62+
@JsonSubTypes.Type(value = McpCallFailedEvent.class, name = "response.mcp_call.failed"),
63+
@JsonSubTypes.Type(value = McpListToolsInProgressEvent.class, name = "response.mcp_list_tools.in_progress"),
64+
@JsonSubTypes.Type(value = McpListToolsCompletedEvent.class, name = "response.mcp_list_tools.completed"),
65+
@JsonSubTypes.Type(value = McpListToolsFailedEvent.class, name = "response.mcp_list_tools.failed"),
66+
@JsonSubTypes.Type(value = CustomToolCallInputDeltaEvent.class, name = "response.custom_tool_call_input.delta"),
67+
@JsonSubTypes.Type(value = CustomToolCallInputDoneEvent.class, name = "response.custom_tool_call_input.done"),
4668
@JsonSubTypes.Type(value = ErrorEvent.class, name = "error")
4769
})
4870
public abstract class BaseStreamEvent {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event emitted when a content part is done.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class ContentPartDoneEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The index of the content part that is done.
16+
*/
17+
@JsonProperty("content_index")
18+
private Integer contentIndex;
19+
20+
/**
21+
* The ID of the output item that the content part was added to.
22+
*/
23+
@JsonProperty("item_id")
24+
private String itemId;
25+
26+
/**
27+
* The index of the output item that the content part was added to.
28+
*/
29+
@JsonProperty("output_index")
30+
private Integer outputIndex;
31+
32+
/**
33+
* The content part that is done.
34+
*/
35+
private Object part;
36+
37+
@Override
38+
public String getType() {
39+
return "response.content_part.done";
40+
}
41+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event representing a delta (partial update) to the input of a custom tool call.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class CustomToolCallInputDeltaEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The incremental input data (delta) for the custom tool call.
16+
*/
17+
private String delta;
18+
19+
/**
20+
* Unique identifier for the API item associated with this event.
21+
*/
22+
@JsonProperty("item_id")
23+
private String itemId;
24+
25+
/**
26+
* The index of the output this delta applies to.
27+
*/
28+
@JsonProperty("output_index")
29+
private Integer outputIndex;
30+
31+
@Override
32+
public String getType() {
33+
return "response.custom_tool_call_input.delta";
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event indicating that input for a custom tool call is complete.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class CustomToolCallInputDoneEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The complete input data for the custom tool call.
16+
*/
17+
private String input;
18+
19+
/**
20+
* Unique identifier for the API item associated with this event.
21+
*/
22+
@JsonProperty("item_id")
23+
private String itemId;
24+
25+
/**
26+
* The index of the output this event applies to.
27+
*/
28+
@JsonProperty("output_index")
29+
private Integer outputIndex;
30+
31+
@Override
32+
public String getType() {
33+
return "response.custom_tool_call_input.done";
34+
}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event emitted when an image generation tool call has completed and the final image is available.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class ImageGenerationCompletedEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The unique identifier of the image generation item being processed.
16+
*/
17+
@JsonProperty("item_id")
18+
private String itemId;
19+
20+
/**
21+
* The index of the output item in the response's output array.
22+
*/
23+
@JsonProperty("output_index")
24+
private Integer outputIndex;
25+
26+
@Override
27+
public String getType() {
28+
return "response.image_generation_call.completed";
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event emitted when an image generation tool call is actively generating an image (intermediate state).
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class ImageGenerationGeneratingEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The unique identifier of the image generation item being processed.
16+
*/
17+
@JsonProperty("item_id")
18+
private String itemId;
19+
20+
/**
21+
* The index of the output item in the response's output array.
22+
*/
23+
@JsonProperty("output_index")
24+
private Integer outputIndex;
25+
26+
@Override
27+
public String getType() {
28+
return "response.image_generation_call.generating";
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event emitted when an image generation tool call is in progress.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class ImageGenerationInProgressEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The unique identifier of the image generation item being processed.
16+
*/
17+
@JsonProperty("item_id")
18+
private String itemId;
19+
20+
/**
21+
* The index of the output item in the response's output array.
22+
*/
23+
@JsonProperty("output_index")
24+
private Integer outputIndex;
25+
26+
@Override
27+
public String getType() {
28+
return "response.image_generation_call.in_progress";
29+
}
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event emitted when a partial image is available during image generation streaming.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class ImageGenerationPartialImageEvent extends BaseStreamEvent {
13+
14+
/**
15+
* The unique identifier of the image generation item being processed.
16+
*/
17+
@JsonProperty("item_id")
18+
private String itemId;
19+
20+
/**
21+
* The index of the output item in the response's output array.
22+
*/
23+
@JsonProperty("output_index")
24+
private Integer outputIndex;
25+
26+
/**
27+
* Base64-encoded partial image data, suitable for rendering as an image.
28+
*/
29+
@JsonProperty("partial_image_b64")
30+
private String partialImageB64;
31+
32+
/**
33+
* 0-based index for the partial image (backend is 1-based, but this is 0-based for the user).
34+
*/
35+
@JsonProperty("partial_image_index")
36+
private Integer partialImageIndex;
37+
38+
@Override
39+
public String getType() {
40+
return "response.image_generation_call.partial_image";
41+
}
42+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.theokanning.openai.response.stream;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* Event emitted when there is a delta (partial update) to the arguments of an MCP tool call.
9+
*/
10+
@Data
11+
@EqualsAndHashCode(callSuper = true)
12+
public class McpCallArgumentsDeltaEvent extends BaseStreamEvent {
13+
14+
/**
15+
* A JSON string containing the partial update to the arguments for the MCP tool call.
16+
*/
17+
private String delta;
18+
19+
/**
20+
* The unique identifier of the MCP tool call item being processed.
21+
*/
22+
@JsonProperty("item_id")
23+
private String itemId;
24+
25+
/**
26+
* The index of the output item in the response's output array.
27+
*/
28+
@JsonProperty("output_index")
29+
private Integer outputIndex;
30+
31+
@Override
32+
public String getType() {
33+
return "response.mcp_call_arguments.delta";
34+
}
35+
}

0 commit comments

Comments
 (0)