Skip to content

Commit 2ab2654

Browse files
julien-cgary149
andauthored
Link to provider (#1938)
* Upgrade dep * link to provider's page on the Hub * add rounding * Update ChatMessage.svelte * Update provider type to InferenceProvider Replaces the provider type from string to InferenceProvider in endpoint and message update types for improved type safety and consistency with @huggingface/inference. * Remove model author avatar from chat message link Eliminated the model author avatar image from the chat message model link and adjusted the link's padding for consistency. Also fixed the Hugging Face organization link to use curly braces for variable interpolation. * Switch provider logos to dynamic avatars from Hugging Face Replaces static SVG provider logos with dynamic avatars fetched from Hugging Face organization API. Removes all local SVG assets for provider logos and updates the settings page to use the new avatar URLs, improving maintainability and ensuring up-to-date branding. * Remove unused variable and fix type in settings page Deleted an unused 'modelAuthor' constant in ChatMessage.svelte. Updated type assertion for 'hubOrg' in the settings page to ensure correct key usage with PROVIDERS_HUB_ORGS. --------- Co-authored-by: Victor Muštar <[email protected]>
1 parent 8731064 commit 2ab2654

File tree

22 files changed

+40
-105
lines changed

22 files changed

+40
-105
lines changed

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"dependencies": {
6969
"@elysiajs/swagger": "^1.3.0",
7070
"@huggingface/hub": "^2.2.0",
71-
"@huggingface/inference": "^3.12.1",
71+
"@huggingface/inference": "^4.11.3",
7272
"@iconify-json/bi": "^1.1.21",
7373
"@resvg/resvg-js": "^2.6.2",
7474
"autoprefixer": "^10.4.14",

src/lib/components/chat/ChatMessage.svelte

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import type { Message } from "$lib/types/Message";
33
import { tick } from "svelte";
4-
import { base } from "$app/paths";
54
65
import { usePublicConfig } from "$lib/utils/PublicConfig.svelte";
76
const publicConfig = usePublicConfig();
@@ -17,6 +16,7 @@
1716
import OpenReasoningResults from "./OpenReasoningResults.svelte";
1817
import Alternatives from "./Alternatives.svelte";
1918
import MessageAvatar from "./MessageAvatar.svelte";
19+
import { PROVIDERS_HUB_ORGS } from "@huggingface/inference";
2020
2121
interface Props {
2222
message: Message;
@@ -177,7 +177,7 @@
177177
{#if publicConfig.isHuggingChat}
178178
<a
179179
href="/chat/settings/{message.routerMetadata.model}"
180-
class="truncate rounded bg-gray-100 px-1 font-mono hover:text-gray-500 dark:bg-gray-800 dark:hover:text-gray-300 sm:py-px"
180+
class="flex items-center gap-1 truncate rounded bg-gray-100 px-1 font-mono hover:text-gray-500 dark:bg-gray-800 dark:hover:text-gray-300 sm:py-px"
181181
>
182182
{message.routerMetadata.model.split("/").pop()}
183183
</a>
@@ -190,18 +190,21 @@
190190
{/if}
191191
{/if}
192192
{#if message.routerMetadata.provider}
193+
{@const hubOrg = PROVIDERS_HUB_ORGS[message.routerMetadata.provider]}
193194
<span class="text-gray-500 max-sm:hidden">via</span>
194-
<span
195-
class="flex items-center gap-1 truncate rounded bg-gray-100 pl-1 pr-1.5 font-mono dark:bg-gray-800 max-sm:hidden sm:py-px"
195+
<a
196+
target="_blank"
197+
href="https://huggingface.co/{hubOrg}"
198+
class="flex items-center gap-1 truncate rounded bg-gray-100 px-1 font-mono hover:text-gray-500 dark:bg-gray-800 dark:hover:text-gray-300 max-sm:hidden sm:py-px"
196199
>
197200
<img
198-
src={`${base}/huggingchat/providers/${message.routerMetadata.provider}.svg`}
201+
src="https://huggingface.co/api/organizations/{hubOrg}/avatar"
199202
alt="{message.routerMetadata.provider} logo"
200-
class="size-2.5 flex-none"
203+
class="size-2.5 flex-none rounded-sm"
201204
onerror={(e) => ((e.currentTarget as HTMLImageElement).style.display = "none")}
202205
/>
203206
{message.routerMetadata.provider}
204-
</span>
207+
</a>
205208
{/if}
206209
</div>
207210
{/if}

src/lib/server/endpoints/endpoints.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { Conversation } from "$lib/types/Conversation";
22
import type { Message } from "$lib/types/Message";
3-
import type { TextGenerationStreamOutput, TextGenerationStreamToken } from "@huggingface/inference";
3+
import type {
4+
TextGenerationStreamOutput,
5+
TextGenerationStreamToken,
6+
InferenceProvider,
7+
} from "@huggingface/inference";
48
import { z } from "zod";
59
import { endpointOAIParametersSchema, endpointOai } from "./openai/endpointOai";
610
import type { Model } from "$lib/types/Model";
@@ -21,7 +25,7 @@ export interface EndpointParameters {
2125

2226
export type TextGenerationStreamOutputSimplified = TextGenerationStreamOutput & {
2327
token: TextGenerationStreamToken;
24-
routerMetadata?: { route?: string; model?: string; provider?: string };
28+
routerMetadata?: { route?: string; model?: string; provider?: InferenceProvider };
2529
};
2630
// type signature for the endpoint
2731
export type Endpoint = (

src/lib/types/Message.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { InferenceProvider } from "@huggingface/inference";
12
import type { MessageUpdate } from "./MessageUpdate";
23
import type { Timestamps } from "./Timestamps";
34
import type { v4 } from "uuid";
@@ -20,7 +21,7 @@ export type Message = Partial<Timestamps> & {
2021
routerMetadata?: {
2122
route: string;
2223
model: string;
23-
provider?: string;
24+
provider?: InferenceProvider;
2425
};
2526

2627
// needed for conversation trees

src/lib/types/MessageUpdate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { InferenceProvider } from "@huggingface/inference";
2+
13
export type MessageUpdate =
24
| MessageStatusUpdate
35
| MessageTitleUpdate
@@ -74,5 +76,5 @@ export interface MessageRouterMetadataUpdate {
7476
type: MessageUpdateType.RouterMetadata;
7577
route: string;
7678
model: string;
77-
provider?: string;
79+
provider?: InferenceProvider;
7880
}

src/routes/settings/(nav)/[...model]/+page.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import { goto } from "$app/navigation";
1515
import { usePublicConfig } from "$lib/utils/PublicConfig.svelte";
1616
import Switch from "$lib/components/Switch.svelte";
17+
import { PROVIDERS_HUB_ORGS } from "@huggingface/inference";
1718
1819
const publicConfig = usePublicConfig();
1920
const settings = useSettingsStore();
@@ -231,15 +232,17 @@
231232
</div>
232233
<ul class="mb-0.5 flex flex-wrap gap-2">
233234
{#each providerList as prov, i (prov.provider || i)}
235+
{@const hubOrg = PROVIDERS_HUB_ORGS[prov.provider as keyof typeof PROVIDERS_HUB_ORGS]}
234236
<li>
235237
<span
236238
class="flex items-center gap-1 rounded-md bg-gray-100 py-0.5 pl-1.5 pr-2 text-xs text-gray-700 dark:bg-gray-700/60 dark:text-gray-200"
237239
>
238-
{#if prov.provider}
240+
{#if hubOrg}
239241
<img
240-
class="h-[14px] w-auto"
241-
src={`${base}/huggingchat/providers/${prov.provider}.svg`}
242+
src="https://huggingface.co/api/organizations/{hubOrg}/avatar"
242243
alt="{prov.provider} logo"
244+
class="size-2.5 flex-none rounded-sm"
245+
onerror={(e) => ((e.currentTarget as HTMLImageElement).style.display = "none")}
243246
/>
244247
{/if}
245248
{prov.provider}

static/huggingchat/providers/cerebras.svg

Lines changed: 0 additions & 5 deletions
This file was deleted.

static/huggingchat/providers/cohere.svg

Lines changed: 0 additions & 6 deletions
This file was deleted.

static/huggingchat/providers/featherless-ai.svg

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)