Standardize model check logic in react

This commit is contained in:
Seif Ghazi 2025-08-04 23:08:47 -04:00
parent 547d4b620c
commit fc4075b129
No known key found for this signature in database
GPG key ID: 4519A4B1EEC1494E

32
web/app/utils/models.ts Normal file
View file

@ -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');
}