Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x | import type { RequestHandlerFunction } from '@shared/types/ai-providers/config';
import type { RetrieveBatchResponseBody } from '@shared/types/api/routes/batch-api';
import { azureOpenAIAPIConfig } from './api';
// Return a ReadableStream containing batches output data
export const azureOpenAIGetBatchOutputRequestHandler: RequestHandlerFunction =
async ({ c, saTarget, saRequestData }) => {
// get batch details which has output file id
// get file content as ReadableStream
// return file content
// TODO: Fix this whole thing
const baseUrl = azureOpenAIAPIConfig.getBaseURL({
c,
saTarget,
saRequestData,
});
const retrieveBatchURL =
baseUrl +
azureOpenAIAPIConfig.getEndpoint({
c,
saTarget,
saRequestData,
});
const retrieveBatchesHeaders = await azureOpenAIAPIConfig.headers({
c,
saTarget,
saRequestData,
});
const retrieveBatchesResponse = await fetch(retrieveBatchURL, {
method: 'GET',
headers: retrieveBatchesHeaders,
});
const batchDetails: RetrieveBatchResponseBody =
await retrieveBatchesResponse.json();
const outputFileId = batchDetails.output_file_id;
if (!outputFileId) {
const errors = batchDetails.errors;
if (errors) {
return new Response(JSON.stringify(errors), {
status: 200,
});
}
return new Response(
JSON.stringify({ error: 'No output file ID found' }),
{
status: 404,
},
);
}
const retrieveFileContentURL =
baseUrl +
azureOpenAIAPIConfig.getEndpoint({
c,
saTarget,
saRequestData,
});
const retrieveFileContentHeaders = await azureOpenAIAPIConfig.headers({
c,
saTarget,
saRequestData,
});
const response = fetch(retrieveFileContentURL, {
method: 'GET',
headers: retrieveFileContentHeaders,
});
return response;
};
|