@@ -10,7 +10,7 @@ import { AzureOpenAI } from 'openai'
10
10
11
11
// import { EventStream } from '@azure/openai'
12
12
import { Stream } from 'openai/streaming'
13
- import { FileSearchTool , ResponseIncludable , ResponseInput , ResponseStreamEvent } from 'openai/resources/responses/responses'
13
+ import type { FileSearchTool , ResponseIncludable , ResponseInput , ResponseItemsPage , ResponseStreamEvent } from 'openai/resources/responses/responses'
14
14
15
15
import { createFileSearchTool } from './util'
16
16
@@ -71,6 +71,15 @@ export class ResponsesClient {
71
71
tool_choice : 'auto' ,
72
72
store : true ,
73
73
include,
74
+ /**
75
+ * background: true is mot currenlty supported by Azure OpenAI.
76
+ * It breaks the text generation. But it is vital for really
77
+ * stopping the text generation. Currently cancelling a text
78
+ * generation is only handled on the client level.
79
+ *
80
+ * Waiting for Azure/openai to fix this issue.
81
+ */
82
+ // background: true,
74
83
} )
75
84
} catch ( error : any ) {
76
85
logger . error ( error )
@@ -167,4 +176,22 @@ export class ResponsesClient {
167
176
}
168
177
} )
169
178
}
179
+
180
+ static async cancelResponse ( { responseId } : { responseId : string } ) : Promise < void > {
181
+ try {
182
+ await client . responses . cancel ( responseId )
183
+ } catch ( error : any ) {
184
+ logger . error ( `Error cancelling response ${ responseId } :` , error )
185
+ throw new Error ( `Failed to cancel response: ${ error . message } ` )
186
+ }
187
+ }
188
+
189
+ static async getResponseItemList ( { responseId } : { responseId : string } ) : Promise < ResponseItemsPage > {
190
+ try {
191
+ return await client . responses . inputItems . list ( responseId )
192
+ } catch ( error : any ) {
193
+ logger . error ( `Error retrieving response items for ${ responseId } :` , error )
194
+ throw new Error ( `Failed to retrieve response items: ${ error . message } ` )
195
+ }
196
+ }
170
197
}
0 commit comments