index
int64
0
0
repo_id
stringclasses
351 values
file_path
stringlengths
26
186
content
stringlengths
1
990k
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/getGradioApi.ts
import { base } from "$app/paths"; import type { Client } from "@gradio/client"; export type ApiReturnType = Awaited<ReturnType<typeof Client.prototype.view_api>>; export async function getGradioApi(space: string) { const api: ApiReturnType = await fetch(`${base}/api/spaces-config?space=${space}`).then( async (res...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/isUrl.ts
export function isURL(url: string) { try { new URL(url); return true; } catch (e) { return false; } }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/sum.ts
export function sum(nums: number[]): number { return nums.reduce((a, b) => a + b, 0); }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/getReturnFromGenerator.ts
export async function getReturnFromGenerator<T, R>(generator: AsyncGenerator<T, R>): Promise<R> { let result: IteratorResult<T, R>; do { result = await generator.next(); } while (!result.done); // Keep calling `next()` until `done` is true return result.value; // Return the final value }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/hashConv.ts
import type { Conversation } from "$lib/types/Conversation"; import { sha256 } from "./sha256"; export async function hashConv(conv: Conversation) { // messages contains the conversation message but only the immutable part const messages = conv.messages.map((message) => { return (({ from, id, content, webSearchId ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/parseStringToList.ts
export function parseStringToList(links: unknown): string[] { if (typeof links !== "string") { throw new Error("Expected a string"); } return links .split(",") .map((link) => link.trim()) .filter((link) => link.length > 0); }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/models.ts
import type { Model } from "$lib/types/Model"; export const findCurrentModel = (models: Model[], id?: string): Model => models.find((m) => m.id === id) ?? models[0];
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/template.ts
import type { Message } from "$lib/types/Message"; import Handlebars from "handlebars"; Handlebars.registerHelper("ifUser", function (this: Pick<Message, "from" | "content">, options) { if (this.from == "user") return options.fn(this); }); Handlebars.registerHelper( "ifAssistant", function (this: Pick<Message, "fr...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/mergeAsyncGenerators.ts
type Gen<T, TReturn> = AsyncGenerator<T, TReturn, undefined>; type GenPromiseMap<T, TReturn> = Map< Gen<T, TReturn>, Promise<{ gen: Gen<T, TReturn> } & IteratorResult<T, TReturn>> >; /** Merges multiple async generators into a single async generator that yields values from all of them in parallel. */ export async f...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/timeout.ts
export const timeout = <T>(prom: Promise<T>, time: number): Promise<T> => { let timer: NodeJS.Timeout; return Promise.race([ prom, new Promise<T>((_, reject) => { timer = setTimeout(() => reject(new Error(`Timeout after ${time / 1000} seconds`)), time); }), ]).finally(() => clearTimeout(timer)); };
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/searchTokens.ts
const PUNCTUATION_REGEX = /\p{P}/gu; function removeDiacritics(s: string, form: "NFD" | "NFKD" = "NFD"): string { return s.normalize(form).replace(/[\u0300-\u036f]/g, ""); } export function generateSearchTokens(value: string): string[] { const fullTitleToken = removeDiacritics(value) .replace(PUNCTUATION_REGEX, "...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/isDesktop.ts
// Approximate width from which we disable autofocus const TABLET_VIEWPORT_WIDTH = 768; export function isDesktop(window: Window) { const { innerWidth } = window; return innerWidth > TABLET_VIEWPORT_WIDTH; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/getTokenizer.ts
import type { Model } from "$lib/types/Model"; import { AutoTokenizer, PreTrainedTokenizer } from "@huggingface/transformers"; export async function getTokenizer(_modelTokenizer: Exclude<Model["tokenizer"], undefined>) { if (typeof _modelTokenizer === "string") { // return auto tokenizer return await AutoTokenize...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/messageUpdates.ts
import type { MessageFile } from "$lib/types/Message"; import { type MessageUpdate, type MessageStreamUpdate, type MessageToolCallUpdate, MessageToolUpdateType, MessageUpdateType, type MessageToolUpdate, type MessageWebSearchUpdate, type MessageWebSearchGeneralUpdate, type MessageWebSearchSourcesUpdate, type ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/getHref.ts
export function getHref( url: URL | string, modifications: { newKeys?: Record<string, string | undefined | null>; existingKeys?: { behaviour: "delete_except" | "delete"; keys: string[] }; } ) { const newUrl = new URL(url); const { newKeys, existingKeys } = modifications; // exsiting keys logic if (existingK...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/chunk.ts
/** * Chunk array into arrays of length at most `chunkSize` * * @param chunkSize must be greater than or equal to 1 */ export function chunk<T extends unknown[] | string>(arr: T, chunkSize: number): T[] { if (isNaN(chunkSize) || chunkSize < 1) { throw new RangeError("Invalid chunk size: " + chunkSize); } if (...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/debounce.ts
/** * A debounce function that works in both browser and Nodejs. * For pure Nodejs work, prefer the `Debouncer` class. */ export function debounce<T extends unknown[]>( callback: (...rest: T) => unknown, limit: number ): (...rest: T) => void { let timer: ReturnType<typeof setTimeout>; return function (...rest) ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/isHuggingChat.ts
import { env as envPublic } from "$env/dynamic/public"; export const isHuggingChat = envPublic.PUBLIC_APP_ASSETS === "huggingchat";
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/cookiesAreEnabled.ts
import { browser } from "$app/environment"; export function cookiesAreEnabled(): boolean { if (!browser) return false; if (navigator.cookieEnabled) return navigator.cookieEnabled; // Create cookie document.cookie = "cookietest=1"; const ret = document.cookie.indexOf("cookietest=") != -1; // Delete cookie docum...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/formatUserCount.ts
export function formatUserCount(userCount: number): string { const userCountRanges: { min: number; max: number; label: string }[] = [ { min: 0, max: 1, label: "1" }, { min: 2, max: 9, label: "1-10" }, { min: 10, max: 49, label: "10+" }, { min: 50, max: 99, label: "50+" }, { min: 100, max: 299, label: "100+" ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/stringifyError.ts
/** Takes an unknown error and attempts to convert it to a string */ export function stringifyError(error: unknown): string { if (error instanceof Error) return error.message; if (typeof error === "string") return error; if (typeof error === "object" && error !== null) { // try a few common properties if ("messa...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/treeHelpers.spec.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { describe, expect, it } from "vitest"; // function used to insert conversations used for testing export const insertLegacyConversation = async () => { const res = await collections.conversations.insertOne({ _id: new Obj...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/addSibling.spec.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { describe, expect, it } from "vitest"; import { insertLegacyConversation, insertSideBranchesConversation } from "./treeHelpers.spec"; import type { Message } from "$lib/types/Message"; import { addSibling } from "./addSibli...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/convertLegacyConversation.ts
import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; import { v4 } from "uuid"; export function convertLegacyConversation( conv: Pick<Conversation, "messages" | "rootMessageId" | "preprompt"> ): Pick<Conversation, "messages" | "rootMessageId" | "preprompt"> {...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/buildSubtree.ts
import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; export function buildSubtree( conv: Pick<Conversation, "messages" | "rootMessageId">, id: Message["id"] ): Message[] { if (!conv.rootMessageId) { if (conv.messages.length === 0) return []; // legacy c...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/addChildren.ts
import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; import { v4 } from "uuid"; export function addChildren( conv: Pick<Conversation, "messages" | "rootMessageId">, message: Omit<Message, "id">, parentId?: Message["id"] ): Message["id"] { // if this is the...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/isMessageId.ts
import type { Message } from "$lib/types/Message"; export function isMessageId(id: string): id is Message["id"] { return id.split("-").length === 5; }
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/convertLegacyConversation.spec.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { describe, expect, it } from "vitest"; import { convertLegacyConversation } from "./convertLegacyConversation"; import { insertLegacyConversation } from "./treeHelpers.spec"; describe("convertLegacyConversation", () => { ...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/isMessageId.spec.ts
import { describe, expect, it } from "vitest"; import { isMessageId } from "./isMessageId"; import { v4 } from "uuid"; describe("isMessageId", () => { it("should return true for a valid message id", () => { expect(isMessageId(v4())).toBe(true); }); it("should return false for an invalid message id", () => { exp...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/addSibling.ts
import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; import { v4 } from "uuid"; export function addSibling( conv: Pick<Conversation, "messages" | "rootMessageId">, message: Omit<Message, "id">, siblingId: Message["id"] ): Message["id"] { if (conv.messages....
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/buildSubtree.spec.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { describe, expect, it } from "vitest"; import { insertLegacyConversation, insertLinearBranchConversation, insertSideBranchesConversation, } from "./treeHelpers.spec"; import { buildSubtree } from "./buildSubtree"; descr...
0
hf_public_repos/chat-ui/src/lib/utils
hf_public_repos/chat-ui/src/lib/utils/tree/addChildren.spec.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { describe, expect, it } from "vitest"; import { insertLegacyConversation, insertSideBranchesConversation } from "./treeHelpers.spec"; import { addChildren } from "./addChildren"; import type { Message } from "$lib/types/Mes...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/jobs/refresh-assistants-counts.ts
import { Database } from "$lib/server/database"; import { acquireLock, refreshLock } from "$lib/migrations/lock"; import type { ObjectId } from "mongodb"; import { subDays } from "date-fns"; import { logger } from "$lib/server/logger"; const LOCK_KEY = "assistants.count"; let hasLock = false; let lockId: ObjectId | n...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/jobs/refresh-conversation-stats.ts
import type { ConversationStats } from "$lib/types/ConversationStats"; import { CONVERSATION_STATS_COLLECTION, collections } from "$lib/server/database"; import { logger } from "$lib/server/logger"; import type { ObjectId } from "mongodb"; import { acquireLock, refreshLock } from "$lib/migrations/lock"; export async f...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/NavConversationItem.svelte
<script lang="ts"> import { base } from "$app/paths"; import { page } from "$app/stores"; import { createEventDispatcher } from "svelte"; import CarbonCheckmark from "~icons/carbon/checkmark"; import CarbonTrashCan from "~icons/carbon/trash-can"; import CarbonClose from "~icons/carbon/close"; import CarbonEdit ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/NavMenu.svelte
<script lang="ts"> import { base } from "$app/paths"; import Logo from "$lib/components/icons/Logo.svelte"; import { switchTheme } from "$lib/switchTheme"; import { isAborted } from "$lib/stores/isAborted"; import { env as envPublic } from "$env/dynamic/public"; import NavConversationItem from "./NavConversation...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ScrollToBottomBtn.svelte
<script lang="ts"> import { fade } from "svelte/transition"; import { onDestroy } from "svelte"; import IconChevron from "./icons/IconChevron.svelte"; export let scrollNode: HTMLElement; export { className as class }; let visible = false; let className = ""; let observer: ResizeObserver | null = null; $: if...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ToolLogo.svelte
<script lang="ts"> import CarbonWikis from "~icons/carbon/wikis"; import CarbonTools from "~icons/carbon/tools"; import CarbonCamera from "~icons/carbon/camera"; import CarbonCode from "~icons/carbon/code"; import CarbonEmail from "~icons/carbon/email"; import CarbonCloud from "~icons/carbon/cloud-upload"; impor...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ToolBadge.svelte
<script lang="ts"> import ToolLogo from "./ToolLogo.svelte"; import { base } from "$app/paths"; import { browser } from "$app/environment"; export let toolId: string; </script> <div class="relative flex items-center justify-center space-x-2 rounded border border-gray-300 bg-gray-200 px-2 py-1" > {#if browser} ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/AssistantToolPicker.svelte
<script lang="ts"> import { base } from "$app/paths"; import type { ToolLogoColor, ToolLogoIcon } from "$lib/types/Tool"; import { debounce } from "$lib/utils/debounce"; import { onMount } from "svelte"; import ToolLogo from "./ToolLogo.svelte"; import CarbonClose from "~icons/carbon/close"; interface ToolSugg...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ExpandNavigation.svelte
<script lang="ts"> export let isCollapsed: boolean; export let classNames: string; </script> <button on:click class="{classNames} group flex h-16 w-6 flex-col items-center justify-center -space-y-1 outline-none *:h-3 *:w-1 *:rounded-full *:hover:bg-gray-300 dark:*:hover:bg-gray-600 max-md:hidden {!isCollapsed ? ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/CopyToClipBoardBtn.svelte
<script lang="ts"> import { onDestroy } from "svelte"; import IconCopy from "./icons/IconCopy.svelte"; import Tooltip from "./Tooltip.svelte"; export let classNames = ""; export let value: string; let isSuccess = false; let timeout: ReturnType<typeof setTimeout>; const handleClick = async () => { // write...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/StopGeneratingBtn.svelte
<script lang="ts"> import CarbonStopFilledAlt from "~icons/carbon/stop-filled-alt"; export let classNames = ""; </script> <button type="button" on:click class="btn flex h-8 rounded-lg border bg-white px-3 py-1 shadow-sm transition-all hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-700 dark:hover:bg-gray-600...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/SystemPromptModal.svelte
<script lang="ts"> import Modal from "./Modal.svelte"; import CarbonClose from "~icons/carbon/close"; import CarbonBlockchain from "~icons/carbon/blockchain"; export let preprompt: string; let isOpen = false; </script> <button type="button" class="mx-auto flex items-center gap-1.5 rounded-full border border-g...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/RetryBtn.svelte
<script lang="ts"> import CarbonRotate360 from "~icons/carbon/rotate-360"; export let classNames = ""; </script> <button type="button" on:click class="btn flex h-8 rounded-lg border bg-white px-3 py-1 text-gray-500 shadow-sm transition-all hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-30...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ScrollToPreviousBtn.svelte
<script lang="ts"> import { fade } from "svelte/transition"; import { onDestroy } from "svelte"; import IconChevron from "./icons/IconChevron.svelte"; export let scrollNode: HTMLElement; export { className as class }; let visible = false; let className = ""; let observer: ResizeObserver | null = null; $: if...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/CodeBlock.svelte
<script lang="ts"> import CopyToClipBoardBtn from "./CopyToClipBoardBtn.svelte"; import DOMPurify from "isomorphic-dompurify"; import hljs from "highlight.js"; export let code = ""; export let lang = ""; $: highlightedCode = hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value; </script> <div class=...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/Portal.svelte
<script lang="ts"> import { onMount, onDestroy } from "svelte"; let el: HTMLElement; onMount(() => { el.ownerDocument.body.appendChild(el); }); onDestroy(() => { if (el?.parentNode) { el.parentNode.removeChild(el); } }); </script> <div bind:this={el} class="contents" hidden> <slot /> </div>
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/Switch.svelte
<script lang="ts"> export let checked: boolean; export let name: string; </script> <input bind:checked type="checkbox" {name} class="peer pointer-events-none absolute opacity-0" /> <div aria-checked={checked} aria-roledescription="switch" aria-label="switch" role="switch" tabindex="0" class="relative inline-fl...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/Pagination.svelte
<script lang="ts"> import { page } from "$app/stores"; import { getHref } from "$lib/utils/getHref"; import PaginationArrow from "./PaginationArrow.svelte"; export let classNames = ""; export let numItemsPerPage: number; export let numTotalItems: number; const ELLIPSIS_IDX = -1 as const; $: numTotalPages = M...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/TokensCounter.svelte
<script lang="ts"> import type { Model } from "$lib/types/Model"; import { getTokenizer } from "$lib/utils/getTokenizer"; import type { PreTrainedTokenizer } from "@huggingface/transformers"; export let classNames = ""; export let prompt = ""; export let modelTokenizer: Exclude<Model["tokenizer"], undefined>; e...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/MobileNav.svelte
<script lang="ts"> import { navigating } from "$app/stores"; import { createEventDispatcher } from "svelte"; import { browser } from "$app/environment"; import { base } from "$app/paths"; import { page } from "$app/stores"; import CarbonClose from "~icons/carbon/close"; import CarbonTextAlignJustify from "~icon...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/WebSearchToggle.svelte
<script lang="ts"> import { webSearchParameters } from "$lib/stores/webSearchParameters"; import CarbonInformation from "~icons/carbon/information"; import Switch from "./Switch.svelte"; const toggle = () => ($webSearchParameters.useSearch = !$webSearchParameters.useSearch); </script> <div class="flex h-8 cursor...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/PaginationArrow.svelte
<script lang="ts"> import CarbonCaretLeft from "~icons/carbon/caret-left"; import CarbonCaretRight from "~icons/carbon/caret-right"; export let href: string; export let direction: "next" | "previous"; export let isDisabled = false; </script> <a class="flex items-center rounded-lg px-2.5 py-1 hover:bg-gray-50 da...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/DisclaimerModal.svelte
<script lang="ts"> import { base } from "$app/paths"; import { page } from "$app/stores"; import { env as envPublic } from "$env/dynamic/public"; import LogoHuggingFaceBorderless from "$lib/components/icons/LogoHuggingFaceBorderless.svelte"; import Modal from "$lib/components/Modal.svelte"; import { useSettingsSt...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/AssistantSettings.svelte
<script lang="ts"> import type { readAndCompressImage } from "browser-image-resizer"; import type { Model } from "$lib/types/Model"; import type { Assistant } from "$lib/types/Assistant"; import { onMount } from "svelte"; import { applyAction, enhance } from "$app/forms"; import { page } from "$app/stores"; imp...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/AnnouncementBanner.svelte
<script lang="ts"> export let title = ""; export let classNames = ""; </script> <div class="flex items-center rounded-xl bg-gray-100 p-1 text-sm dark:bg-gray-800 {classNames}"> <span class="from-primary-300 text-primary-700 dark:from-primary-900 dark:text-primary-400 mr-2 inline-flex items-center rounded-lg bg-gr...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/OpenWebSearchResults.svelte
<script lang="ts"> import { MessageWebSearchUpdateType, type MessageWebSearchUpdate, } from "$lib/types/MessageUpdate"; import { isMessageWebSearchSourcesUpdate } from "$lib/utils/messageUpdates"; import CarbonError from "~icons/carbon/error-filled"; import EosIconsLoading from "~icons/eos-icons/loading"; im...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/UploadBtn.svelte
<script lang="ts"> import CarbonUpload from "~icons/carbon/upload"; export let classNames = ""; export let files: File[]; export let mimeTypes: string[]; /** * Due to a bug with Svelte, we cannot use bind:files with multiple * So we use this workaround **/ const onFileChange = (e: Event) => { if (!e.tar...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ModelCardMetadata.svelte
<script lang="ts"> import CarbonEarth from "~icons/carbon/earth"; import CarbonArrowUpRight from "~icons/carbon/arrow-up-right"; import BIMeta from "~icons/bi/meta"; import CarbonCode from "~icons/carbon/code"; import type { Model } from "$lib/types/Model"; export let model: Pick< Model, "name" | "datasetNam...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ContinueBtn.svelte
<script lang="ts"> import CarbonContinue from "~icons/carbon/continue"; export let classNames = ""; </script> <button type="button" on:click class="btn flex h-8 rounded-lg border bg-white px-3 py-1 text-gray-500 shadow-sm transition-all hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 d...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/HoverTooltip.svelte
<script lang="ts"> export let label = ""; </script> <div class="group/tooltip md:relative"> <slot /> <div class="invisible absolute z-10 w-64 whitespace-normal rounded-md bg-black p-2 text-center text-white group-hover/tooltip:visible group-active/tooltip:visible max-sm:left-1/2 max-sm:-translate-x-1/2" > {lab...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/Modal.svelte
<script lang="ts"> import { createEventDispatcher, onDestroy, onMount } from "svelte"; import { cubicOut } from "svelte/easing"; import { fade } from "svelte/transition"; import Portal from "./Portal.svelte"; import { browser } from "$app/environment"; export let width = "max-w-sm"; let backdropEl: HTMLDivElem...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/LoginModal.svelte
<script lang="ts"> import { base } from "$app/paths"; import { page } from "$app/stores"; import { env as envPublic } from "$env/dynamic/public"; import LogoHuggingFaceBorderless from "$lib/components/icons/LogoHuggingFaceBorderless.svelte"; import Modal from "$lib/components/Modal.svelte"; import { useSettingsSt...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/ToolsMenu.svelte
<script lang="ts"> import { base } from "$app/paths"; import { page } from "$app/stores"; import { clickOutside } from "$lib/actions/clickOutside"; import { useSettingsStore } from "$lib/stores/settings"; import type { ToolFront } from "$lib/types/Tool"; import { isHuggingChat } from "$lib/utils/isHuggingChat"; ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/Toast.svelte
<script lang="ts"> import { fade } from "svelte/transition"; import IconDazzled from "$lib/components/icons/IconDazzled.svelte"; export let message = ""; </script> <div transition:fade|global={{ duration: 300 }} class="pointer-events-none fixed right-0 top-12 z-20 bg-gradient-to-bl from-red-500/20 via-red-500/0...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/components/Tooltip.svelte
<script lang="ts"> export let classNames = ""; export let label = "Copied"; export let position = "left-1/2 top-full transform -translate-x-1/2 translate-y-2"; </script> <div class=" pointer-events-none absolute rounded bg-black px-2 py-1 font-normal leading-tight text-white shadow transition-opacity {position...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/ModelSwitch.svelte
<script lang="ts"> import { invalidateAll } from "$app/navigation"; import { page } from "$app/stores"; import { base } from "$app/paths"; import type { Model } from "$lib/types/Model"; export let models: Model[]; export let currentModel: Model; let selectedModelId = models.map((m) => m.id).includes(currentMod...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/AssistantIntroduction.svelte
<script lang="ts"> import { createEventDispatcher } from "svelte"; import { base } from "$app/paths"; import { goto } from "$app/navigation"; import type { Model } from "$lib/types/Model"; import type { Assistant } from "$lib/types/Assistant"; import { useSettingsStore } from "$lib/stores/settings"; import { for...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/ChatIntroduction.svelte
<script lang="ts"> import { env as envPublic } from "$env/dynamic/public"; import Logo from "$lib/components/icons/Logo.svelte"; import { createEventDispatcher } from "svelte"; import IconGear from "~icons/bi/gear-fill"; import AnnouncementBanner from "../AnnouncementBanner.svelte"; import type { Model } from "$l...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/UploadedFile.svelte
<script lang="ts"> import { createEventDispatcher } from "svelte"; import { page } from "$app/stores"; import type { MessageFile } from "$lib/types/Message"; import CarbonClose from "~icons/carbon/close"; import CarbonDocumentBlank from "~icons/carbon/document-blank"; import CarbonDownload from "~icons/carbon/dow...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/MarkdownRenderer.svelte
<script lang="ts"> import type { WebSearchSource } from "$lib/types/WebSearch"; import katex from "katex"; import DOMPurify from "isomorphic-dompurify"; import { Marked } from "marked"; import CodeBlock from "../CodeBlock.svelte"; export let content: string; export let sources: WebSearchSource[] = []; functio...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/FileDropzone.svelte
<script lang="ts"> import CarbonImage from "~icons/carbon/image"; // import EosIconsLoading from "~icons/eos-icons/loading"; export let files: File[]; export let mimeTypes: string[] = []; export let onDrag = false; export let onDragInner = false; async function dropHandle(event: DragEvent) { event.preventDe...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/ChatInput.svelte
<script lang="ts"> import { browser } from "$app/environment"; import { createEventDispatcher, onMount } from "svelte"; export let value = ""; export let minRows = 1; export let maxRows: null | number = null; export let placeholder = ""; export let disabled = false; let textareaElement: HTMLTextAreaElement; ...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/ToolUpdate.svelte
<script lang="ts"> import { MessageToolUpdateType, type MessageToolUpdate } from "$lib/types/MessageUpdate"; import { isMessageToolCallUpdate, isMessageToolErrorUpdate, isMessageToolResultUpdate, } from "$lib/utils/messageUpdates"; import CarbonTools from "~icons/carbon/tools"; import { ToolResultStatus, ty...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/OpenReasoningResults.svelte
<script lang="ts"> import MarkdownRenderer from "./MarkdownRenderer.svelte"; import CarbonCaretDown from "~icons/carbon/caret-down"; export let summary: string; export let content: string; export let loading: boolean = false; </script> <details class="group flex w-fit max-w-full flex-col rounded-xl border borde...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/ChatMessage.svelte
<script lang="ts"> import type { Message } from "$lib/types/Message"; import { afterUpdate, createEventDispatcher, tick } from "svelte"; import { deepestChild } from "$lib/utils/deepestChild"; import { page } from "$app/stores"; import CopyToClipBoardBtn from "../CopyToClipBoardBtn.svelte"; import IconLoading fr...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/chat/ChatWindow.svelte
<script lang="ts"> import type { Message, MessageFile } from "$lib/types/Message"; import { createEventDispatcher, onDestroy, tick } from "svelte"; import CarbonSendAltFilled from "~icons/carbon/send-alt-filled"; import CarbonExport from "~icons/carbon/export"; import CarbonStopFilledAlt from "~icons/carbon/stop-...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/players/AudioPlayer.svelte
<script lang="ts"> export let src: string; export let name: string; import CarbonPause from "~icons/carbon/pause"; import CarbonPlay from "~icons/carbon/play"; let time = 0; let duration = 0; let paused = true; function format(time: number) { if (isNaN(time)) return "..."; const minutes = Math.floor(tim...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconTool.svelte
<script lang="ts"> export let classNames = ""; </script> <svg xmlns="http://www.w3.org/2000/svg" class={classNames} width="1em" height="1em" fill="none" viewBox="0 0 15 15" ><path fill="currentColor" d="M8.33 6.56c0 .11-.04.22-.1.31a.55.55 0 0 1-.26.2l-.71.23c-.2.07-.38.18-.53.33-.15.15-.26.33-.33.53l-.24....
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/Logo.svelte
<script lang="ts"> import { page } from "$app/stores"; import { env as envPublic } from "$env/dynamic/public"; import { base } from "$app/paths"; export let classNames = ""; </script> {#if envPublic.PUBLIC_APP_ASSETS === "chatui"} <svg height="30" width="30" viewBox="0 0 30 30" xmlns="http://www.w3.org/2...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconNew.svelte
<script lang="ts"> export let classNames = ""; </script> <svg xmlns="http://www.w3.org/2000/svg" class={classNames} width="1em" height="1em" fill="none" viewBox="0 0 32 32" ><path fill="currentColor" fill-rule="evenodd" d="M3.143 20.286h4.286v2.142H3.143A2.143 2.143 0 0 1 1 20.287V3.143A2.143 2.143 0 0 1...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconInternet.svelte
<script lang="ts"> export let classNames = ""; </script> <svg class={classNames} xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" fill="currentColor" preserveAspectRatio="xMidYMid meet" viewBox="0 0 20 20" > ><path fill-rule="evenodd" d="M1.5 1...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconChevron.svelte
<script lang="ts"> export let classNames = ""; </script> <svg width="1em" height="1em" viewBox="0 0 15 6" class={classNames} fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M1.67236 1L7.67236 7L13.6724 1" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" ...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/LogoHuggingFaceBorderless.svelte
<script lang="ts"> export let classNames = ""; </script> <svg class={classNames} xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 95 88" > <path fill="#FFD21E" d="M47.21 76.5a34.75 34.75 0 1 0 0-69.5 34.75 34.75 0 0 0 0 69.5Z" /> <path fill="#FF9D0B" d="M81.96 41.75a34....
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconDazzled.svelte
<script lang="ts"> export let classNames = ""; </script> <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" class={classNames} fill="none" viewBox="0 0 26 23" > <path fill="url(#a)" d="M.93 10.65A10.17 10.17 0 0 1 11.11.48h4.67a9.45 9.45 0 0 1 0 18.89H4.53L1.62 22.2a.38.38 0 0 1-.69-.28V10.65...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconCopy.svelte
<script lang="ts"> export let classNames = ""; </script> <svg class={classNames} xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32" > <path d="M28,10V28H10V10H28m0-2H10a2,2...
0
hf_public_repos/chat-ui/src/lib/components
hf_public_repos/chat-ui/src/lib/components/icons/IconLoading.svelte
<script lang="ts"> export let classNames = ""; </script> <div class={"inline-flex h-8 flex-none items-center gap-1 " + classNames}> <div class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400" style="animation-delay: 0.25s;" /> <div class="h-1 w-1 flex-none animate-bounce rounded-f...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/actions/snapScrollToBottom.ts
import { navigating } from "$app/stores"; import { tick } from "svelte"; import { get } from "svelte/store"; const detachedOffset = 10; /** * @param node element to snap scroll to bottom * @param dependency pass in a dependency to update scroll on changes. */ export const snapScrollToBottom = (node: HTMLElement, d...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/actions/clickOutside.ts
export function clickOutside(element: HTMLElement, callbackFunction: () => void) { function onClick(event: MouseEvent) { if (!element.contains(event.target as Node)) { callbackFunction(); } } document.body.addEventListener("click", onClick); return { update(newCallbackFunction: () => void) { callbackF...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/generateFromDefaultEndpoint.ts
import { smallModel } from "$lib/server/models"; import { MessageUpdateType, type MessageUpdate } from "$lib/types/MessageUpdate"; import type { EndpointMessage } from "./endpoints/endpoints"; export async function* generateFromDefaultEndpoint({ messages, preprompt, generateSettings, }: { messages: EndpointMessage...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/isURLLocal.ts
import { Address6, Address4 } from "ip-address"; import dns from "node:dns"; const dnsLookup = (hostname: string): Promise<{ address: string; family: number }> => { return new Promise((resolve, reject) => { dns.lookup(hostname, (err, address, family) => { if (err) return reject(err); resolve({ address, family...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/sendSlack.ts
import { env } from "$env/dynamic/private"; import { logger } from "$lib/server/logger"; export async function sendSlack(text: string) { if (!env.WEBHOOK_URL_REPORT_ASSISTANT) { logger.warn("WEBHOOK_URL_REPORT_ASSISTANT is not set, tried to send a slack message."); return; } const res = await fetch(env.WEBHOOK...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/database.ts
import { env } from "$env/dynamic/private"; import { GridFSBucket, MongoClient } from "mongodb"; import type { Conversation } from "$lib/types/Conversation"; import type { SharedConversation } from "$lib/types/SharedConversation"; import type { AbortedGeneration } from "$lib/types/AbortedGeneration"; import type { Sett...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/auth.ts
import { Issuer, type BaseClient, type UserinfoResponse, type TokenSet, custom, } from "openid-client"; import { addHours, addWeeks } from "date-fns"; import { env } from "$env/dynamic/private"; import { sha256 } from "$lib/utils/sha256"; import { z } from "zod"; import { dev } from "$app/environment"; import type...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/usageLimits.ts
import { z } from "zod"; import { env } from "$env/dynamic/private"; import JSON5 from "json5"; // RATE_LIMIT is the legacy way to define messages per minute limit export const usageLimitsSchema = z .object({ conversations: z.coerce.number().optional(), // how many conversations messages: z.coerce.number().option...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/sentenceSimilarity.ts
import { dot } from "@huggingface/transformers"; import type { EmbeddingBackendModel } from "$lib/server/embeddingModels"; import type { Embedding } from "$lib/server/embeddingEndpoints/embeddingEndpoints"; // see here: https://github.com/nmslib/hnswlib/blob/359b2ba87358224963986f709e593d799064ace6/README.md?plain=1#L...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/models.ts
import { env } from "$env/dynamic/private"; import type { ChatTemplateInput } from "$lib/types/Template"; import { compileTemplate } from "$lib/utils/template"; import { z } from "zod"; import endpoints, { endpointSchema, type Endpoint } from "./endpoints/endpoints"; import { endpointTgi } from "./endpoints/tgi/endpoin...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/logger.ts
import pino from "pino"; import { dev } from "$app/environment"; import { env } from "$env/dynamic/private"; let options: pino.LoggerOptions = {}; if (dev) { options = { transport: { target: "pino-pretty", options: { colorize: true, }, }, }; } export const logger = pino({ ...options, level: env.LO...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/metrics.ts
import { collectDefaultMetrics, Registry, Counter, Summary } from "prom-client"; import express from "express"; import { logger } from "$lib/server/logger"; import { env } from "$env/dynamic/private"; import type { Model } from "$lib/types/Model"; import { onExit } from "./exitHandler"; import { promisify } from "util"...