Skip to content

Commit 98ead7f

Browse files
committed
add cancel and get items list static functions to Responses Class
1 parent a9cbe16 commit 98ead7f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/server/util/azure/ResponsesAPI.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AzureOpenAI } from 'openai'
1010

1111
// import { EventStream } from '@azure/openai'
1212
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'
1414

1515
import { createFileSearchTool } from './util'
1616

@@ -71,6 +71,15 @@ export class ResponsesClient {
7171
tool_choice: 'auto',
7272
store: true,
7373
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,
7483
})
7584
} catch (error: any) {
7685
logger.error(error)
@@ -167,4 +176,22 @@ export class ResponsesClient {
167176
}
168177
})
169178
}
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+
}
170197
}

0 commit comments

Comments
 (0)