mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 23:13:35 +00:00
🧬 feat: Show the Model Maker's Icon When Another Host Serves the Model (#17238)
This commit is contained in:
parent
2e9da70ca8
commit
ae7da84c7d
8 changed files with 227 additions and 10 deletions
|
|
@ -0,0 +1,42 @@
|
|||
import React from 'react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { ProviderId } from 'librechat-data-provider';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import type { TEndpointsConfig } from 'librechat-data-provider';
|
||||
import type { Endpoint } from '~/common';
|
||||
import { getSelectedIcon } from '../utils';
|
||||
|
||||
const ollama: Endpoint = {
|
||||
value: 'Ollama',
|
||||
label: 'Ollama',
|
||||
hasModels: true,
|
||||
icon: <span />,
|
||||
};
|
||||
|
||||
const endpointsConfig = {
|
||||
Ollama: { order: 1, providerId: ProviderId.ollama },
|
||||
} as unknown as TEndpointsConfig;
|
||||
|
||||
const renderSelected = (model: string) =>
|
||||
render(
|
||||
<>
|
||||
{getSelectedIcon({
|
||||
mappedEndpoints: [ollama],
|
||||
selectedValues: { endpoint: 'Ollama', model, modelSpec: '' },
|
||||
modelSpecs: [],
|
||||
endpointsConfig,
|
||||
})}
|
||||
</>,
|
||||
);
|
||||
|
||||
describe('getSelectedIcon', () => {
|
||||
it('shows the maker of a model the endpoint only hosts', () => {
|
||||
renderSelected('gemma4:12b-it-qat');
|
||||
expect(screen.getByRole('img', { name: 'Gemma' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps the endpoint icon for a model with no known maker', () => {
|
||||
renderSelected('phi4:14b');
|
||||
expect(screen.getByRole('img', { name: 'Ollama' })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -9,6 +9,8 @@ import type {
|
|||
} from 'librechat-data-provider';
|
||||
import type { useLocalize } from '~/hooks';
|
||||
import SpecIcon from '~/components/Chat/Menus/Endpoints/components/SpecIcon';
|
||||
import { resolveProviderIcon } from '~/hooks/Endpoint/useProviderIcon';
|
||||
import { createEndpointIcon } from '~/hooks/Endpoint/useEndpoints';
|
||||
import { Endpoint, SelectedValues } from '~/common';
|
||||
import { getSpecAgentAvatarURL } from '~/utils';
|
||||
|
||||
|
|
@ -170,13 +172,18 @@ export function getSelectedIcon({
|
|||
);
|
||||
}
|
||||
|
||||
return (
|
||||
selectedEndpoint.icon ||
|
||||
React.createElement(Bot, {
|
||||
size: 20,
|
||||
className: 'icon-md shrink-0 text-text-primary',
|
||||
})
|
||||
);
|
||||
if (selectedEndpoint.icon) {
|
||||
return createEndpointIcon(
|
||||
endpoint,
|
||||
resolveProviderIcon({ endpoint, endpointsConfig }),
|
||||
model,
|
||||
);
|
||||
}
|
||||
|
||||
return React.createElement(Bot, {
|
||||
size: 20,
|
||||
className: 'icon-md shrink-0 text-text-primary',
|
||||
});
|
||||
}
|
||||
|
||||
if (endpoint) {
|
||||
|
|
|
|||
|
|
@ -40,8 +40,13 @@ describe('FavoriteItem type="model" provider art', () => {
|
|||
expect(screen.getByAltText('MetaLlama Icon')).toHaveAttribute('src', '/assets/meta-llama.png');
|
||||
});
|
||||
|
||||
it('falls back to the custom art when the endpoint resolves to no provider', () => {
|
||||
it("shows the model's maker when the endpoint resolves to no provider", () => {
|
||||
render(<FavoriteItem type="model" item={claudeModel} />);
|
||||
expect(screen.getByRole('img', { name: 'Anthropic', hidden: true })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('falls back to the custom art when neither the endpoint nor the model has a brand', () => {
|
||||
render(<FavoriteItem type="model" item={{ model: 'phi4:14b', endpoint: 'Local' }} />);
|
||||
expect(screen.getByRole('img', { name: 'Custom', hidden: true })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,9 +30,11 @@ const artSize = 20;
|
|||
const artClassName = 'text-text-primary shrink-0 icon-md';
|
||||
const providerArtClassName = 'icon-md shrink-0';
|
||||
|
||||
const createEndpointIcon = (
|
||||
/** With a model, provider art shows the model's maker when the endpoint only hosts it. */
|
||||
export const createEndpointIcon = (
|
||||
endpoint: string,
|
||||
{ provider, imageURL }: ProviderIconResolution,
|
||||
model?: string,
|
||||
): React.ReactNode => {
|
||||
if (endpoint === EModelEndpoint.agents) {
|
||||
return React.createElement(Feather, { size: artSize, className: artClassName });
|
||||
|
|
@ -52,6 +54,7 @@ const createEndpointIcon = (
|
|||
|
||||
return React.createElement(ProviderIcon, {
|
||||
provider,
|
||||
model,
|
||||
size: artSize,
|
||||
className: providerArtClassName,
|
||||
});
|
||||
|
|
|
|||
50
e2e/specs/mock/scenarios/model-maker-icons.spec.ts
Normal file
50
e2e/specs/mock/scenarios/model-maker-icons.spec.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import {
|
||||
escapeRegExp,
|
||||
messagesView,
|
||||
modelSelectorTrigger,
|
||||
NEW_CHAT_PATH,
|
||||
sendMessageAndWaitForCompletion,
|
||||
} from '../helpers';
|
||||
|
||||
/** The shared helper treats the model submenu as optional; here the model decides the icon. */
|
||||
async function selectModel(page: Page, endpoint: string, model: string) {
|
||||
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
|
||||
await modelSelectorTrigger(page).click();
|
||||
await page.getByRole('option', { name: endpoint }).click();
|
||||
/** On mobile the option's accessible name also carries its pin button. */
|
||||
const option = page.getByRole('option', { name: new RegExp(`^${escapeRegExp(model)}( Pin)?$`) });
|
||||
await expect(option).toBeVisible({ timeout: 10000 });
|
||||
await option.click();
|
||||
}
|
||||
|
||||
const triggerArt = (page: Page, label: string) =>
|
||||
modelSelectorTrigger(page).getByRole('img', { name: label });
|
||||
|
||||
test('A Gemini model on a gateway endpoint shows the Gemini mark @scenario:a-hosted-gemini-model-shows-the-gemini-mark', async ({
|
||||
page,
|
||||
}) => {
|
||||
/** `Mock Gemini` names no provider, so before the maker lookup it rendered the generic art. */
|
||||
await selectModel(page, 'Mock Gemini', 'gemini-2.5-pro');
|
||||
await expect(triggerArt(page, 'Gemini')).toBeVisible();
|
||||
|
||||
await sendMessageAndWaitForCompletion(page, `Maker icon ${Date.now()}`);
|
||||
await expect(messagesView(page).getByRole('img', { name: 'Gemini' }).first()).toBeVisible();
|
||||
|
||||
await page.reload();
|
||||
await expect(messagesView(page).getByRole('img', { name: 'Gemini' }).first()).toBeVisible({
|
||||
timeout: 15000,
|
||||
});
|
||||
await expect(triggerArt(page, 'Gemini')).toBeVisible();
|
||||
});
|
||||
|
||||
test('A model with no known maker keeps the endpoint icon @scenario:a-model-with-no-known-maker-keeps-the-host-icon', async ({
|
||||
page,
|
||||
}) => {
|
||||
await selectModel(page, 'Mock Provider C', 'mock-model-c');
|
||||
await expect(triggerArt(page, 'Custom')).toBeVisible();
|
||||
|
||||
await sendMessageAndWaitForCompletion(page, `Host icon ${Date.now()}`);
|
||||
await expect(messagesView(page).getByRole('img', { name: 'Custom' }).first()).toBeVisible();
|
||||
});
|
||||
|
|
@ -17,7 +17,10 @@ export type BrandMarkId =
|
|||
| 'groq'
|
||||
| 'helicone'
|
||||
| 'huggingface'
|
||||
| 'meta'
|
||||
| 'minimax'
|
||||
| 'mistral'
|
||||
| 'nvidia'
|
||||
| 'ollama'
|
||||
| 'openrouter'
|
||||
| 'perplexity'
|
||||
|
|
@ -140,6 +143,24 @@ export const brandMarks: Record<BrandMarkId, BrandMark> = {
|
|||
},
|
||||
],
|
||||
},
|
||||
/** simple-icons meta */
|
||||
meta: {
|
||||
viewBox: '0 0 24 24',
|
||||
paths: [
|
||||
{
|
||||
d: 'M6.915 4.03c-1.968 0-3.683 1.28-4.871 3.113C.704 9.208 0 11.883 0 14.449c0 .706.07 1.369.21 1.973a6.624 6.624 0 0 0 .265.86 5.297 5.297 0 0 0 .371.761c.696 1.159 1.818 1.927 3.593 1.927 1.497 0 2.633-.671 3.965-2.444.76-1.012 1.144-1.626 2.663-4.32l.756-1.339.186-.325c.061.1.121.196.183.3l2.152 3.595c.724 1.21 1.665 2.556 2.47 3.314 1.046.987 1.992 1.22 3.06 1.22 1.075 0 1.876-.355 2.455-.843a3.743 3.743 0 0 0 .81-.973c.542-.939.861-2.127.861-3.745 0-2.72-.681-5.357-2.084-7.45-1.282-1.912-2.957-2.93-4.716-2.93-1.047 0-2.088.467-3.053 1.308-.652.57-1.257 1.29-1.82 2.05-.69-.875-1.335-1.547-1.958-2.056-1.182-.966-2.315-1.303-3.454-1.303zm10.16 2.053c1.147 0 2.188.758 2.992 1.999 1.132 1.748 1.647 4.195 1.647 6.4 0 1.548-.368 2.9-1.839 2.9-.58 0-1.027-.23-1.664-1.004-.496-.601-1.343-1.878-2.832-4.358l-.617-1.028a44.908 44.908 0 0 0-1.255-1.98c.07-.109.141-.224.211-.327 1.12-1.667 2.118-2.602 3.358-2.602zm-10.201.553c1.265 0 2.058.791 2.675 1.446.307.327.737.871 1.234 1.579l-1.02 1.566c-.757 1.163-1.882 3.017-2.837 4.338-1.191 1.649-1.81 1.817-2.486 1.817-.524 0-1.038-.237-1.383-.794-.263-.426-.464-1.13-.464-2.046 0-2.221.63-4.535 1.66-6.088.454-.687.964-1.226 1.533-1.533a2.264 2.264 0 0 1 1.088-.285z',
|
||||
},
|
||||
],
|
||||
},
|
||||
/** simple-icons minimax */
|
||||
minimax: {
|
||||
viewBox: '0 0 24 24',
|
||||
paths: [
|
||||
{
|
||||
d: 'M11.43 3.92a.86.86 0 1 0-1.718 0v14.236a1.999 1.999 0 0 1-3.997 0V9.022a.86.86 0 1 0-1.718 0v3.87a1.999 1.999 0 0 1-3.997 0V11.49a.57.57 0 0 1 1.139 0v1.404a.86.86 0 0 0 1.719 0V9.022a1.999 1.999 0 0 1 3.997 0v9.134a.86.86 0 0 0 1.719 0V3.92a1.998 1.998 0 1 1 3.996 0v11.788a.57.57 0 1 1-1.139 0zm10.572 3.105a2 2 0 0 0-1.999 1.997v7.63a.86.86 0 0 1-1.718 0V3.923a1.999 1.999 0 0 0-3.997 0v16.16a.86.86 0 0 1-1.719 0V18.08a.57.57 0 1 0-1.138 0v2a1.998 1.998 0 0 0 3.996 0V3.92a.86.86 0 0 1 1.719 0v12.73a1.999 1.999 0 0 0 3.996 0V9.023a.86.86 0 1 1 1.72 0v6.686a.57.57 0 0 0 1.138 0V9.022a2 2 0 0 0-1.998-1.997',
|
||||
},
|
||||
],
|
||||
},
|
||||
/** simple-icons mistralai */
|
||||
mistral: {
|
||||
viewBox: '0 0 24 24',
|
||||
|
|
@ -149,6 +170,15 @@ export const brandMarks: Record<BrandMarkId, BrandMark> = {
|
|||
},
|
||||
],
|
||||
},
|
||||
/** simple-icons nvidia */
|
||||
nvidia: {
|
||||
viewBox: '0 0 24 24',
|
||||
paths: [
|
||||
{
|
||||
d: 'M8.948 8.798v-1.43a6.7 6.7 0 0 1 .424-.018c3.922-.124 6.493 3.374 6.493 3.374s-2.774 3.851-5.75 3.851c-.398 0-.787-.062-1.158-.185v-4.346c1.528.185 1.837.857 2.747 2.385l2.04-1.714s-1.492-1.952-4-1.952a6.016 6.016 0 0 0-.796.035m0-4.735v2.138l.424-.027c5.45-.185 9.01 4.47 9.01 4.47s-4.08 4.964-8.33 4.964c-.37 0-.733-.035-1.095-.097v1.325c.3.035.61.062.91.062 3.957 0 6.82-2.023 9.593-4.408.459.371 2.34 1.263 2.73 1.652-2.633 2.208-8.772 3.984-12.253 3.984-.335 0-.653-.018-.971-.053v1.864H24V4.063zm0 10.326v1.131c-3.657-.654-4.673-4.46-4.673-4.46s1.758-1.944 4.673-2.262v1.237H8.94c-1.528-.186-2.73 1.245-2.73 1.245s.68 2.412 2.739 3.11M2.456 10.9s2.164-3.197 6.5-3.533V6.201C4.153 6.59 0 10.653 0 10.653s2.35 6.802 8.948 7.42v-1.237c-4.84-.6-6.492-5.936-6.492-5.936z',
|
||||
},
|
||||
],
|
||||
},
|
||||
/** simple-icons ollama */
|
||||
ollama: {
|
||||
viewBox: '0 0 24 24',
|
||||
|
|
|
|||
|
|
@ -43,6 +43,50 @@ describe('providerIcons', () => {
|
|||
expect(getProviderIconDef(ProviderId.google, 'some-other-model').label).toBe('Google');
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ProviderId.openrouter, 'anthropic/claude-sonnet-4.5', 'Anthropic'],
|
||||
[ProviderId.bedrock, 'us.anthropic.claude-opus-5-5-v1:0', 'Anthropic'],
|
||||
[ProviderId.azure, 'gpt-5.6', 'OpenAI'],
|
||||
[ProviderId.openrouter, 'openai/o4-mini', 'OpenAI'],
|
||||
[ProviderId.ollama, 'gemma4:12b-it-qat', 'Gemma'],
|
||||
[ProviderId.openrouter, 'google/gemini-3.7-flash', 'Gemini'],
|
||||
[ProviderId.openrouter, 'x-ai/grok-4', 'xAI'],
|
||||
[ProviderId.openrouter, 'moonshotai/kimi-k2', 'Moonshot'],
|
||||
[ProviderId.groq, 'qwen/qwen3-32b', 'Qwen'],
|
||||
[ProviderId.openrouter, 'mistralai/devstral-small', 'Mistral'],
|
||||
[ProviderId.ollama, 'mathstral:7b', 'Mistral'],
|
||||
[ProviderId.openrouter, 'openai/chatgpt-4o-latest', 'OpenAI'],
|
||||
[ProviderId.azure, 'gpt-35-turbo', 'OpenAI'],
|
||||
[ProviderId.openrouter, 'cohere/command-a', 'Cohere'],
|
||||
[ProviderId.openrouter, 'perplexity/sonar-pro', 'Perplexity'],
|
||||
[ProviderId.groq, 'llama-3.3-70b-versatile', 'Meta'],
|
||||
[ProviderId.ollama, 'llama3.1:8b', 'Meta'],
|
||||
[ProviderId.together, 'deepseek-ai/DeepSeek-R1-Distill-Llama-70B', 'DeepSeek'],
|
||||
[ProviderId.openrouter, 'nvidia/llama-3.1-nemotron-70b-instruct', 'NVIDIA'],
|
||||
[ProviderId.openrouter, 'minimax/minimax-m3', 'MiniMax'],
|
||||
[null, 'gpt-4o', 'OpenAI'],
|
||||
])('shows the maker for %s serving %s', (provider, model, label) => {
|
||||
expect(getProviderIconDef(provider, model).label).toBe(label);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ProviderId.anthropic, 'claude-opus-5-5', 'Anthropic'],
|
||||
[ProviderId.ollama, 'phi4:14b', 'Ollama'],
|
||||
[ProviderId.ollama, 'my-ollama-finetune', 'Ollama'],
|
||||
[ProviderId.openrouter, 'openrouter/auto', 'OpenRouter'],
|
||||
[ProviderId.groq, 'yolo1-vision', 'Groq'],
|
||||
[ProviderId.ollama, 'gpt4all-j', 'Ollama'],
|
||||
[ProviderId.ollama, 'nomic-ai/gpt4all-falcon', 'Ollama'],
|
||||
])('keeps the host for %s serving %s', (provider, model, label) => {
|
||||
expect(getProviderIconDef(provider, model).label).toBe(label);
|
||||
});
|
||||
|
||||
it('keeps the OpenAI tile color rule for OpenAI models on another host', () => {
|
||||
expect(getProviderIconDef(ProviderId.openrouter, 'openai/o4-mini').brandColor).toBe(
|
||||
'var(--provider-openai-reasoning, #000000)',
|
||||
);
|
||||
});
|
||||
|
||||
it('varies the OpenAI tile color by model generation', () => {
|
||||
const gpt4 = getProviderIconDef(ProviderId.openai, 'gpt-4o');
|
||||
const gpt5 = getProviderIconDef(ProviderId.openai, 'gpt-5.6');
|
||||
|
|
|
|||
|
|
@ -117,11 +117,47 @@ export const providerIcons: Record<ProviderId, ProviderIconDef> = {
|
|||
[ProviderId.unify]: { art: asset('assets/unify.webp'), label: 'Unify' },
|
||||
};
|
||||
|
||||
/** Merges any model level refinement over the base definition for a provider. */
|
||||
/**
|
||||
* The company that makes a model, matched on the model id so a model served by another host
|
||||
* (OpenRouter, Groq, Ollama, Bedrock...) shows its maker. First match wins, so ids that name
|
||||
* two families (`deepseek-r1-distill-llama`, `llama-nemotron`) list the more specific one first.
|
||||
*/
|
||||
const modelMakers: [RegExp, ProviderId | ProviderIconDef][] = [
|
||||
[/claude/, ProviderId.anthropic],
|
||||
[/(^|[^a-z])(chat)?gpt-|(^|[^a-z0-9])o[1-9](?![0-9])/, ProviderId.openai],
|
||||
[/gemini|gemma|learnlm/, ProviderId.google],
|
||||
[/grok/, ProviderId.xai],
|
||||
[/kimi|moonshot/, ProviderId.moonshot],
|
||||
[/deepseek/, ProviderId.deepseek],
|
||||
[/qwen|qwq/, ProviderId.qwen],
|
||||
[
|
||||
/mi[sx]tral|codestral|devstral|ministral|magistral|mathstral|pixtral|voxtral/,
|
||||
ProviderId.mistral,
|
||||
],
|
||||
[/command-[ar]|(^|[^a-z])aya-/, ProviderId.cohere],
|
||||
[/sonar/, ProviderId.perplexity],
|
||||
[/nemotron/, { art: mark('nvidia'), label: 'NVIDIA', mono: true }],
|
||||
[/minimax|abab/, { art: mark('minimax'), label: 'MiniMax', mono: true }],
|
||||
[/(?<!o)llama/, { art: mark('meta'), label: 'Meta', mono: true }],
|
||||
];
|
||||
|
||||
function resolveModelMaker(model: string): ProviderId | ProviderIconDef | undefined {
|
||||
const value = model.toLowerCase();
|
||||
return modelMakers.find(([pattern]) => pattern.test(value))?.[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the icon for a provider, preferring the model's maker when the host only serves it,
|
||||
* then merging any model level refinement over the base definition.
|
||||
*/
|
||||
export function getProviderIconDef(
|
||||
provider?: ProviderId | null,
|
||||
model?: string | null,
|
||||
): ProviderIconDef {
|
||||
const maker = model ? resolveModelMaker(model) : undefined;
|
||||
if (maker != null && maker !== provider) {
|
||||
return typeof maker === 'string' ? getProviderIconDef(maker, model) : maker;
|
||||
}
|
||||
const base = provider ? providerIcons[provider] : undefined;
|
||||
if (!base) {
|
||||
return { art: component(CustomMinimalIcon), label: 'Custom', mono: true };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue