All files / api/src/ai-providers/openai index.ts

100% Statements 74/74
100% Branches 0/0
100% Functions 0/0
100% Lines 74/74

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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137  1x 1x 1x             1x 1x 1x       1x       1x       1x       1x       1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x         1x 1x 1x   1x     1x     1x 1x     1x 1x     1x     1x     1x     1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x     1x 1x 1x 1x     1x       1x       1x 1x 1x 1x 1x     1x 1x     1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import type { AIProviderConfig } from '@shared/types/ai-providers/config';
import { FunctionName } from '@shared/types/api/request';
import { AIProvider } from '@shared/types/constants';
import {
  createModelResponseParams,
  openAICreateModelResponseTransformer,
  openAIDeleteModelResponseTransformer,
  openAIGetModelResponseTransformer,
  openAIListInputItemsResponseTransformer,
} from '../open-ai-base';
import { openAIAPIConfig } from './api';
import { openAICancelBatchResponseTransform } from './cancel-batch';
import {
  openAIChatCompleteConfig,
  openAIChatCompleteResponseTransform,
} from './chat-complete';
import {
  openAICompleteConfig,
  openAICompleteResponseTransform,
} from './complete';
import {
  openAICreateBatchConfig,
  openAICreateBatchResponseTransform,
} from './create-batch';
import {
  openAICreateFinetuneConfig,
  openAIFinetuneResponseTransform,
} from './create-finetune';
import {
  openAICreateSpeechConfig,
  openAICreateSpeechResponseTransform,
} from './create-speech';
import { openAICreateTranscriptionResponseTransform } from './create-transcription';
import { openAICreateTranslationResponseTransform } from './create-translation';
import { openAIDeleteFileResponseTransform } from './delete-file';
import { openAIEmbedConfig } from './embed';
import {
  openAIImageGenerateConfig,
  openAIImageGenerateResponseTransform,
} from './image-generate';
import { openAIListBatchesResponseTransform } from './list-batches';
import { openAIGetFilesResponseTransform } from './list-files';
import { openAIModelCapabilities } from './model-capabilities';
import { openAIRetrieveBatchResponseTransform } from './retrieve-batch';
import { openAIGetFileContentResponseTransform } from './retrieve-file-content';
import {
  openAIFileUploadRequestTransform,
  openAIUploadFileResponseTransform,
} from './upload-file';
 
export const openAIConfig: AIProviderConfig = {
  api: openAIAPIConfig,
  modelCapabilities: openAIModelCapabilities,
  // Audio API
  [FunctionName.CREATE_SPEECH]: openAICreateSpeechConfig,
 
  // Batch API
  [FunctionName.CREATE_BATCH]: openAICreateBatchConfig,
 
  // Chat Completions API
  [FunctionName.CHAT_COMPLETE]: openAIChatCompleteConfig,
  [FunctionName.STREAM_CHAT_COMPLETE]: openAIChatCompleteConfig,
 
  // Completions API
  [FunctionName.COMPLETE]: openAICompleteConfig,
  [FunctionName.STREAM_COMPLETE]: openAICompleteConfig,
 
  // Embeddings API
  [FunctionName.EMBED]: openAIEmbedConfig,
 
  // Image Generation API
  [FunctionName.GENERATE_IMAGE]: openAIImageGenerateConfig,
 
  // Finetuning API
  [FunctionName.CREATE_FINE_TUNING_JOB]: openAICreateFinetuneConfig,
 
  // Responses API
  [FunctionName.CREATE_MODEL_RESPONSE]: createModelResponseParams([
    'temperature',
    'top_p',
    'frequency_penalty',
    'presence_penalty',
  ]),
 
  requestTransforms: {
    [FunctionName.UPLOAD_FILE]: openAIFileUploadRequestTransform,
  },
  responseTransforms: {
    // Audio API
    [FunctionName.CREATE_SPEECH]: openAICreateSpeechResponseTransform,
    [FunctionName.CREATE_TRANSCRIPTION]:
      openAICreateTranscriptionResponseTransform,
    [FunctionName.CREATE_TRANSLATION]: openAICreateTranslationResponseTransform,
 
    // Batch API
    [FunctionName.CREATE_BATCH]: openAICreateBatchResponseTransform,
    [FunctionName.RETRIEVE_BATCH]: openAIRetrieveBatchResponseTransform,
    [FunctionName.CANCEL_BATCH]: openAICancelBatchResponseTransform,
    [FunctionName.LIST_BATCHES]: openAIListBatchesResponseTransform,
 
    // Chat Completions API
    [FunctionName.CHAT_COMPLETE]: openAIChatCompleteResponseTransform,
    // Note: STREAM_CHAT_COMPLETE has no transformer - OpenAI already returns correct format
 
    // Completions API
    [FunctionName.COMPLETE]: openAICompleteResponseTransform,
    // Note: STREAM_COMPLETE has no transformer - OpenAI already returns correct format
 
    // Files API
    [FunctionName.UPLOAD_FILE]: openAIUploadFileResponseTransform,
    [FunctionName.LIST_FILES]: openAIGetFilesResponseTransform,
    [FunctionName.RETRIEVE_FILE]: openAIGetFilesResponseTransform,
    [FunctionName.DELETE_FILE]: openAIDeleteFileResponseTransform,
    [FunctionName.RETRIEVE_FILE_CONTENT]: openAIGetFileContentResponseTransform,
 
    // Finetuning API
    [FunctionName.CREATE_FINE_TUNING_JOB]: openAIFinetuneResponseTransform,
    [FunctionName.RETRIEVE_FINE_TUNING_JOB]: openAIFinetuneResponseTransform,
 
    // Images API
    [FunctionName.GENERATE_IMAGE]: openAIImageGenerateResponseTransform,
 
    // Responses API
    [FunctionName.CREATE_MODEL_RESPONSE]: openAICreateModelResponseTransformer(
      AIProvider.OPENAI,
    ),
    [FunctionName.GET_MODEL_RESPONSE]: openAIGetModelResponseTransformer(
      AIProvider.OPENAI,
    ),
    [FunctionName.DELETE_MODEL_RESPONSE]: openAIDeleteModelResponseTransformer(
      AIProvider.OPENAI,
    ),
    [FunctionName.LIST_RESPONSE_INPUT_ITEMS]:
      openAIListInputItemsResponseTransformer(AIProvider.OPENAI),
  },
};