All files / api/src/ai-providers/google-vertex-ai list-batches.ts

15.38% Statements 4/26
100% Branches 0/0
0% Functions 0/1
15.38% Lines 4/26

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        1x   1x 1x   1x                                                    
import type {
  GoogleBatchRecord,
  GoogleListBatchesResponse,
} from '@api/ai-providers/google/types';
import { generateInvalidProviderResponseError } from '@api/utils/ai-provider';
import type { ResponseTransformFunction } from '@shared/types/ai-providers/config';
import { AIProvider } from '@shared/types/constants';
import { GoogleToOpenAIBatch } from './utils';
 
export const googleListBatchesResponseTransform: ResponseTransformFunction = (
  response,
  responseStatus,
) => {
  if (responseStatus !== 200) {
    return generateInvalidProviderResponseError(
      response as unknown as Record<string, unknown>,
      AIProvider.GOOGLE_VERTEX_AI,
    );
  }
 
  const batches =
    (response as { batchPredictionJobs: GoogleBatchRecord[] })
      .batchPredictionJobs ?? [];
 
  const objects = batches.map(GoogleToOpenAIBatch);
 
  return {
    data: objects,
    object: 'list',
    first_id: objects.at(0)?.id ?? '',
    last_id: objects.at(-1)?.id ?? '',
    has_more: !!(response as unknown as GoogleListBatchesResponse)
      ?.nextPageToken,
  };
};