Merge pull request #12 from seifghazi/sg/clean-model-check
Standardize model check logic in react
This commit is contained in:
commit
7ab69a1081
3 changed files with 38 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ import {
|
|||
} from 'lucide-react';
|
||||
import { MessageContent } from './MessageContent';
|
||||
import { formatJSON } from '../utils/formatters';
|
||||
import { getChatCompletionsEndpoint, getProviderName } from '../utils/models';
|
||||
|
||||
interface Request {
|
||||
id: number;
|
||||
|
|
@ -152,7 +153,7 @@ export default function RequestDetailContent({ request, onGrade }: RequestDetail
|
|||
<div className="flex items-center space-x-3">
|
||||
<span className="text-gray-500 font-medium min-w-[80px]">Endpoint:</span>
|
||||
<code className="text-blue-600 bg-blue-50 px-2 py-1 rounded font-mono text-xs border border-blue-200">
|
||||
{request.routedModel && request.routedModel.startsWith('gpt-') ? '/v1/chat/completions' : request.endpoint}
|
||||
{getChatCompletionsEndpoint(request.routedModel, request.endpoint)}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -352,14 +353,14 @@ export default function RequestDetailContent({ request, onGrade }: RequestDetail
|
|||
{request.routedModel}
|
||||
</code>
|
||||
<span className="text-xs bg-blue-100 text-blue-700 px-2 py-1 rounded-full border border-blue-200">
|
||||
{request.routedModel.startsWith('gpt-') || request.routedModel.startsWith('o') ? 'OpenAI' : 'Anthropic'}
|
||||
{getProviderName(request.routedModel)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-xs text-gray-500 mb-1">Target Endpoint</div>
|
||||
<code className="text-xs bg-white px-2 py-1 rounded font-mono border border-gray-200">
|
||||
{request.routedModel.startsWith('gpt-') ? '/v1/chat/completions' : '/v1/messages'}
|
||||
{getChatCompletionsEndpoint(request.routedModel)}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import {
|
|||
|
||||
import RequestDetailContent from "../components/RequestDetailContent";
|
||||
import { ConversationThread } from "../components/ConversationThread";
|
||||
import { getChatCompletionsEndpoint } from "../utils/models";
|
||||
|
||||
export const meta: MetaFunction = () => {
|
||||
return [
|
||||
|
|
@ -697,7 +698,7 @@ export default function Index() {
|
|||
|
||||
{/* Endpoint */}
|
||||
<div className="text-xs text-gray-600 font-mono mb-1">
|
||||
{request.routedModel && request.routedModel.startsWith('gpt-') ? '/v1/chat/completions' : request.endpoint}
|
||||
{getChatCompletionsEndpoint(request.routedModel, request.endpoint)}
|
||||
</div>
|
||||
|
||||
{/* Metrics Row */}
|
||||
|
|
|
|||
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