From fc4075b129bec99e17489f734fd6bb6b5b0d261e Mon Sep 17 00:00:00 2001 From: Seif Ghazi Date: Mon, 4 Aug 2025 23:08:47 -0400 Subject: [PATCH] Standardize model check logic in react --- web/app/utils/models.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 web/app/utils/models.ts diff --git a/web/app/utils/models.ts b/web/app/utils/models.ts new file mode 100644 index 0000000..33d1d79 --- /dev/null +++ b/web/app/utils/models.ts @@ -0,0 +1,32 @@ +/** + * Utility functions for model-related operations + */ + +/** + * Checks if a model is an OpenAI model + * @param model - The model name to check + * @returns true if the model is an OpenAI model + */ +export function isOpenAIModel(model: string | null | undefined): boolean { + if (!model) return false; + return model.startsWith('gpt-') || model.startsWith('o'); +} + +/** + * Gets the provider name based on the model + * @param model - The model name + * @returns 'OpenAI' for OpenAI models, 'Anthropic' otherwise + */ +export function getProviderName(model: string | null | undefined): 'OpenAI' | 'Anthropic' { + return isOpenAIModel(model) ? 'OpenAI' : 'Anthropic'; +} + +/** + * Gets the appropriate chat completions endpoint based on the model + * @param model - The model name + * @param defaultEndpoint - The default endpoint to use for non-OpenAI models + * @returns The appropriate endpoint + */ +export function getChatCompletionsEndpoint(model: string | null | undefined, defaultEndpoint?: string): string { + return isOpenAIModel(model) ? '/v1/chat/completions' : (defaultEndpoint || '/v1/messages'); +} \ No newline at end of file