Standardize model check logic in react
This commit is contained in:
parent
547d4b620c
commit
fc4075b129
1 changed files with 32 additions and 0 deletions
32
web/app/utils/models.ts
Normal file
32
web/app/utils/models.ts
Normal 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');
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue