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/server/embeddingModels.ts
import { env } from "$env/dynamic/private"; import { z } from "zod"; import { sum } from "$lib/utils/sum"; import { embeddingEndpoints, embeddingEndpointSchema, type EmbeddingEndpoint, } from "$lib/server/embeddingEndpoints/embeddingEndpoints"; import { embeddingEndpointTransformersJS } from "$lib/server/embeddingE...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/abortedGenerations.ts
// Shouldn't be needed if we dove into sveltekit internals, see https://github.com/huggingface/chat-ui/pull/88#issuecomment-1523173850 import { logger } from "$lib/server/logger"; import { collections } from "$lib/server/database"; import { onExit } from "./exitHandler"; export class AbortedGenerations { private sta...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/exitHandler.ts
import { randomUUID } from "$lib/utils/randomUuid"; import { timeout } from "$lib/utils/timeout"; import { logger } from "./logger"; type ExitHandler = () => void | Promise<void>; type ExitHandlerUnsubscribe = () => void; const listeners = new Map<string, ExitHandler>(); export function onExit(cb: ExitHandler): Exit...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/server/isURLLocal.spec.ts
import { isURLLocal } from "./isURLLocal"; import { describe, expect, it } from "vitest"; describe("isURLLocal", async () => { it("should return true for localhost", async () => { expect(await isURLLocal(new URL("http://localhost"))).toBe(true); }); it("should return true for 127.0.0.1", async () => { expect(aw...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints/embeddingEndpoints.ts
import { z } from "zod"; import { embeddingEndpointTei, embeddingEndpointTeiParametersSchema, } from "./tei/embeddingEndpoints"; import { embeddingEndpointTransformersJS, embeddingEndpointTransformersJSParametersSchema, } from "./transformersjs/embeddingEndpoints"; import { embeddingEndpointOpenAI, embeddingEndpo...
0
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints/openai/embeddingEndpoints.ts
import { z } from "zod"; import type { EmbeddingEndpoint, Embedding } from "../embeddingEndpoints"; import { chunk } from "$lib/utils/chunk"; import { env } from "$env/dynamic/private"; export const embeddingEndpointOpenAIParametersSchema = z.object({ weight: z.number().int().positive().default(1), model: z.any(), ...
0
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints/transformersjs/embeddingEndpoints.ts
import { z } from "zod"; import type { EmbeddingEndpoint } from "../embeddingEndpoints"; import type { Tensor, FeatureExtractionPipeline } from "@huggingface/transformers"; import { pipeline } from "@huggingface/transformers"; export const embeddingEndpointTransformersJSParametersSchema = z.object({ weight: z.number(...
0
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints/tei/embeddingEndpoints.ts
import { z } from "zod"; import type { EmbeddingEndpoint, Embedding } from "../embeddingEndpoints"; import { chunk } from "$lib/utils/chunk"; import { env } from "$env/dynamic/private"; import { logger } from "$lib/server/logger"; export const embeddingEndpointTeiParametersSchema = z.object({ weight: z.number().int()...
0
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints
hf_public_repos/chat-ui/src/lib/server/embeddingEndpoints/hfApi/embeddingHfApi.ts
import { z } from "zod"; import type { EmbeddingEndpoint, Embedding } from "../embeddingEndpoints"; import { chunk } from "$lib/utils/chunk"; import { env } from "$env/dynamic/private"; import { logger } from "$lib/server/logger"; export const embeddingEndpointHfApiSchema = z.object({ weight: z.number().int().positiv...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/websearch/update.ts
import type { WebSearchSource } from "$lib/types/WebSearch"; import { MessageUpdateType, MessageWebSearchUpdateType, type MessageWebSearchErrorUpdate, type MessageWebSearchFinishedUpdate, type MessageWebSearchGeneralUpdate, type MessageWebSearchSourcesUpdate, } from "$lib/types/MessageUpdate"; export function ma...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/websearch/runWebSearch.ts
import { defaultEmbeddingModel, embeddingModels } from "$lib/server/embeddingModels"; import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; import type { WebSearch, WebSearchScrapedSource } from "$lib/types/WebSearch"; import type { Assistant } from "$lib/types...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/markdown/tree.ts
import type { SerializedHTMLElement } from "../scrape/types"; import { htmlElementToMarkdownElements, mergeAdjacentElements } from "./fromHtml"; import type { HeaderElement, MarkdownElement } from "./types"; import { MarkdownElementType } from "./types"; import { chunkElements } from "./utils/chunk"; /** * Converts H...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/markdown/fromHtml.ts
import { collapseString, sanitizeString } from "./utils/nlp"; import { stringifyHTMLElements, stringifyHTMLElementsUnformatted } from "./utils/stringify"; import { MarkdownElementType, tagNameMap, type HeaderElement, type MarkdownElement } from "./types"; import type { SerializedHTMLElement } from "../scrape/types"; i...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/markdown/types.ts
/* eslint-disable-next-line no-shadow */ export enum MarkdownElementType { Header = "HEADER", Paragraph = "PARAGRAPH", BlockQuote = "BLOCKQUOTE", CodeBlock = "CODE_BLOCK", UnorderedList = "UNORDERED_LIST", OrderedList = "ORDERED_LIST", UnorderedListItem = "UNORDERED_LIST_ITEM", OrderedListItem = "ORDERED_LIST_...
0
hf_public_repos/chat-ui/src/lib/server/websearch/markdown
hf_public_repos/chat-ui/src/lib/server/websearch/markdown/utils/nlp.ts
/** Remove excess whitespace and newlines */ export const sanitizeString = (str: string) => str .split("\n") .map((s) => s.trim()) .filter(Boolean) .join("\n") .replaceAll(/ +/g, " "); /** Collapses a string into a single line */ export const collapseString = (str: string) => sanitizeString(str.replaceAll(/...
0
hf_public_repos/chat-ui/src/lib/server/websearch/markdown
hf_public_repos/chat-ui/src/lib/server/websearch/markdown/utils/stringify.ts
import type { SerializedHTMLElement } from "../../scrape/types"; import { MarkdownElementType, type MarkdownElement } from "../types"; // --- Markdown Elements --- /** Converts markdown element to a string with formatting */ export function stringifyMarkdownElement(elem: MarkdownElement): string { const content = el...
0
hf_public_repos/chat-ui/src/lib/server/websearch/markdown
hf_public_repos/chat-ui/src/lib/server/websearch/markdown/utils/chunk.ts
import { sentences as splitBySentences } from "sbd"; import { MarkdownElementType, type MarkdownElement } from "../types"; export function chunkElements(elements: MarkdownElement[], maxLength: number): MarkdownElement[] { return elements.flatMap((elem) => { // Can't split headers because it would break the tree, an...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/scrape/parser.ts
import type { SerializedHTMLElement } from "./types"; interface DBSCANOptions<T> { dataset: T[]; epsilon?: number; epsilonCompare?: (distance: number, epsilon: number) => boolean; minimumPoints?: number; distanceFunction: (a: T, b: T) => number; } export function spatialParser() { /** * Implementation for dbs...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/scrape/types.ts
export interface SerializedHTMLElement { tagName: string; attributes: Record<string, string>; content: (SerializedHTMLElement | string)[]; }
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/scrape/playwright.ts
import { chromium, devices, type Page, type BrowserContextOptions, type Response, type Browser, } from "playwright"; import { PlaywrightBlocker } from "@cliqz/adblocker-playwright"; import { env } from "$env/dynamic/private"; import { logger } from "$lib/server/logger"; import { onExit } from "$lib/server/exitHan...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/scrape/scrape.ts
import type { WebSearchScrapedSource, WebSearchSource } from "$lib/types/WebSearch"; import type { MessageWebSearchUpdate } from "$lib/types/MessageUpdate"; import { withPage } from "./playwright"; import { spatialParser } from "./parser"; import { htmlToMarkdownTree } from "../markdown/tree"; import { timeout } from ...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints.ts
import { WebSearchProvider, type WebSearchSource } from "$lib/types/WebSearch"; import { env } from "$env/dynamic/private"; import searchSerper from "./endpoints/serper"; import searchSerpApi from "./endpoints/serpApi"; import searchSerpStack from "./endpoints/serpStack"; import searchYouApi from "./endpoints/youApi"; ...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/search/search.ts
import type { WebSearchSource } from "$lib/types/WebSearch"; import type { Message } from "$lib/types/Message"; import type { Assistant } from "$lib/types/Assistant"; import { getWebSearchProvider, searchWeb } from "./endpoints"; import { generateQuery } from "./generateQuery"; import { isURLStringLocal } from "$lib/se...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/search/generateQuery.ts
import type { Message } from "$lib/types/Message"; import { format } from "date-fns"; import type { EndpointMessage } from "../../endpoints/endpoints"; import { generateFromDefaultEndpoint } from "../../generateFromDefaultEndpoint"; import { getReturnFromGenerator } from "$lib/utils/getReturnFromGenerator"; export asy...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/searchApi.ts
import { env } from "$env/dynamic/private"; import type { WebSearchSource } from "$lib/types/WebSearch"; export default async function search(query: string): Promise<WebSearchSource[]> { const response = await fetch( `https://www.searchapi.io/api/v1/search?engine=google&hl=en&gl=us&q=${query}`, { method: "GET"...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/searxng.ts
import { env } from "$env/dynamic/private"; import { logger } from "$lib/server/logger"; import type { WebSearchSource } from "$lib/types/WebSearch"; import { isURL } from "$lib/utils/isUrl"; export default async function searchSearxng(query: string): Promise<WebSearchSource[]> { const abortController = new AbortCont...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/bing.ts
import type { WebSearchSource } from "$lib/types/WebSearch"; import { env } from "$env/dynamic/private"; export default async function search(query: string): Promise<WebSearchSource[]> { // const params = { // q: query, // // You can add other parameters if needed, like 'count', 'offset', etc. // }; cons...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/serpStack.ts
import { env } from "$env/dynamic/private"; import { isURL } from "$lib/utils/isUrl"; import type { WebSearchSource } from "$lib/types/WebSearch"; type SerpStackResponse = { organic_results: { title: string; url: string; snippet?: string; }[]; error?: string; }; export default async function searchSerpStack(...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/webLocal.ts
import { JSDOM, VirtualConsole } from "jsdom"; import { isURL } from "$lib/utils/isUrl"; import type { WebSearchSource } from "$lib/types/WebSearch"; export default async function searchWebLocal(query: string): Promise<WebSearchSource[]> { const abortController = new AbortController(); setTimeout(() => abortControll...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/serper.ts
import { env } from "$env/dynamic/private"; import type { WebSearchSource } from "$lib/types/WebSearch"; export default async function search(query: string): Promise<WebSearchSource[]> { const params = { q: query, hl: "en", gl: "us", }; const response = await fetch("https://google.serper.dev/search", { met...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/youApi.ts
import { env } from "$env/dynamic/private"; import { isURL } from "$lib/utils/isUrl"; import type { WebSearchSource } from "$lib/types/WebSearch"; interface YouWebSearch { hits: YouSearchHit[]; latency: number; } interface YouSearchHit { url: string; title: string; description: string; snippets: string[]; } ex...
0
hf_public_repos/chat-ui/src/lib/server/websearch/search
hf_public_repos/chat-ui/src/lib/server/websearch/search/endpoints/serpApi.ts
import { env } from "$env/dynamic/private"; import { getJson, type GoogleParameters } from "serpapi"; import type { WebSearchSource } from "$lib/types/WebSearch"; import { isURL } from "$lib/utils/isUrl"; type SerpApiResponse = { organic_results: { link: string; }[]; }; export default async function searchWebSerp...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/embed/embed.ts
import { MetricsServer } from "$lib/server/metrics"; import type { WebSearchScrapedSource, WebSearchUsedSource } from "$lib/types/WebSearch"; import type { EmbeddingBackendModel } from "../../embeddingModels"; import { getSentenceSimilarity, innerProduct } from "../../sentenceSimilarity"; import { MarkdownElementType, ...
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/embed/tree.ts
import type { MarkdownElement } from "../markdown/types"; export function flattenTree(elem: MarkdownElement): MarkdownElement[] { if ("children" in elem) return [elem, ...elem.children.flatMap(flattenTree)]; return [elem]; }
0
hf_public_repos/chat-ui/src/lib/server/websearch
hf_public_repos/chat-ui/src/lib/server/websearch/embed/combine.ts
import type { EmbeddingBackendModel } from "$lib/server/embeddingModels"; import { getSentenceSimilarity } from "$lib/server/sentenceSimilarity"; /** * Combines sentences together to reach the maximum character limit of the embedding model * Improves performance considerably when using CPU embedding */ export async...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/files/uploadFile.ts
import type { Conversation } from "$lib/types/Conversation"; import type { MessageFile } from "$lib/types/Message"; import { sha256 } from "$lib/utils/sha256"; import { fileTypeFromBuffer } from "file-type"; import { collections } from "$lib/server/database"; export async function uploadFile(file: File, conv: Conversa...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/files/downloadFile.ts
import { error } from "@sveltejs/kit"; import { collections } from "$lib/server/database"; import type { Conversation } from "$lib/types/Conversation"; import type { SharedConversation } from "$lib/types/SharedConversation"; import type { MessageFile } from "$lib/types/Message"; export async function downloadFile( sh...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/tools/directlyAnswer.ts
import type { ConfigTool } from "$lib/types/Tool"; import { ObjectId } from "mongodb"; const directlyAnswer: ConfigTool = { _id: new ObjectId("00000000000000000000000D"), type: "config", description: "Answer the user's query directly", color: "blue", icon: "chat", displayName: "Directly Answer", isOnByDefault: ...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/tools/index.ts
import { MessageUpdateType } from "$lib/types/MessageUpdate"; import { ToolColor, ToolIcon, ToolOutputComponents, type BackendCall, type BaseTool, type ConfigTool, type ToolInput, } from "$lib/types/Tool"; import type { TextGenerationContext } from "../textGeneration/types"; import { z } from "zod"; import JSON...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/tools/calculator.ts
import type { ConfigTool } from "$lib/types/Tool"; import { ObjectId } from "mongodb"; import vm from "node:vm"; const calculator: ConfigTool = { _id: new ObjectId("00000000000000000000000C"), type: "config", description: "Calculate the result of a mathematical expression", color: "blue", icon: "code", displayNa...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/tools/utils.ts
import { env } from "$env/dynamic/private"; import { Client } from "@gradio/client"; import { SignJWT } from "jose"; import JSON5 from "json5"; import { MessageToolUpdateType, MessageUpdateType, type MessageToolUpdate, } from "$lib/types/MessageUpdate"; import { logger } from "$lib/server/logger"; export async funct...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/tools/outputs.ts
import type { ToolIOType, ToolOutputComponents } from "$lib/types/Tool"; export const ToolOutputPaths: Record< ToolOutputComponents, { type: ToolIOType; path: string; } > = { textbox: { type: "str", path: "$", }, markdown: { type: "str", path: "$", }, number: { type: "float", path: "$", }, im...
0
hf_public_repos/chat-ui/src/lib/server/tools
hf_public_repos/chat-ui/src/lib/server/tools/web/url.ts
import { stringifyMarkdownElementTree } from "$lib/server/websearch/markdown/utils/stringify"; import { scrapeUrl } from "$lib/server/websearch/scrape/scrape"; import type { ConfigTool } from "$lib/types/Tool"; import { ObjectId } from "mongodb"; const fetchUrl: ConfigTool = { _id: new ObjectId("000000000000000000000...
0
hf_public_repos/chat-ui/src/lib/server/tools
hf_public_repos/chat-ui/src/lib/server/tools/web/search.ts
import type { ConfigTool } from "$lib/types/Tool"; import { ObjectId } from "mongodb"; import { runWebSearch } from "../../websearch/runWebSearch"; const websearch: ConfigTool = { _id: new ObjectId("00000000000000000000000A"), type: "config", description: "Search the web for answers to the user's query", color: "b...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/tools.ts
import { ToolResultStatus, type ToolCall, type Tool, type ToolResult } from "$lib/types/Tool"; import { v4 as uuidV4 } from "uuid"; import { getCallMethod, toolFromConfigs, type BackendToolContext } from "../tools"; import { MessageToolUpdateType, MessageUpdateStatus, MessageUpdateType, type MessageUpdate, } from "...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/assistant.ts
import { isURLLocal } from "../isURLLocal"; import { env } from "$env/dynamic/private"; import { collections } from "$lib/server/database"; import type { Assistant } from "$lib/types/Assistant"; import type { ObjectId } from "mongodb"; export async function processPreprompt(preprompt: string) { const urlRegex = /{{\s...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/generate.ts
import type { ToolResult } from "$lib/types/Tool"; import { MessageReasoningUpdateType, MessageUpdateType, type MessageUpdate, } from "$lib/types/MessageUpdate"; import { AbortedGenerations } from "../abortedGenerations"; import type { TextGenerationContext } from "./types"; import type { EndpointMessage } from "../...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/types.ts
import type { ProcessedModel } from "../models"; import type { Endpoint } from "../endpoints/endpoints"; import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; import type { Assistant } from "$lib/types/Assistant"; export interface TextGenerationContext { model...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/reasoning.ts
import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint"; import { getReturnFromGenerator } from "$lib/utils/getReturnFromGenerator"; export async function generateSummaryOfReasoning(buffer: string): Promise<string> { // debug 5s delay await new Promise((resolve) => setTimeout(resolve, 3000)); ...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/title.ts
import { env } from "$env/dynamic/private"; import { generateFromDefaultEndpoint } from "$lib/server/generateFromDefaultEndpoint"; import type { EndpointMessage } from "../endpoints/endpoints"; import { logger } from "$lib/server/logger"; import { MessageUpdateType, type MessageUpdate } from "$lib/types/MessageUpdate";...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/textGeneration/index.ts
import { runWebSearch } from "$lib/server/websearch/runWebSearch"; import { preprocessMessages } from "../endpoints/preprocessMessages"; import { generateTitleForConversation } from "./title"; import { assistantHasDynamicPrompt, assistantHasWebSearch, getAssistantById, processPreprompt, } from "./assistant"; impor...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/endpoints/preprocessMessages.ts
import type { Message } from "$lib/types/Message"; import { format } from "date-fns"; import type { EndpointMessage } from "./endpoints"; import { downloadFile } from "../files/downloadFile"; import type { ObjectId } from "mongodb"; export async function preprocessMessages( messages: Message[], webSearch: Message["w...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/endpoints/document.ts
import type { MessageFile } from "$lib/types/Message"; import { z } from "zod"; export interface FileProcessorOptions<TMimeType extends string = string> { supportedMimeTypes: TMimeType[]; maxSizeInMB: number; } export type ImageProcessor<TMimeType extends string = string> = (file: MessageFile) => Promise<{ file: B...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/endpoints/endpoints.ts
import type { Conversation } from "$lib/types/Conversation"; import type { Message } from "$lib/types/Message"; import type { TextGenerationStreamOutput, TextGenerationStreamToken } from "@huggingface/inference"; import { endpointTgi, endpointTgiParametersSchema } from "./tgi/endpointTgi"; import { z } from "zod"; impo...
0
hf_public_repos/chat-ui/src/lib/server
hf_public_repos/chat-ui/src/lib/server/endpoints/images.ts
import type { Sharp } from "sharp"; import sharp from "sharp"; import type { MessageFile } from "$lib/types/Message"; import { z, type util } from "zod"; export interface ImageProcessorOptions<TMimeType extends string = string> { supportedMimeTypes: TMimeType[]; preferredMimeType: TMimeType; maxSizeInMB: number; m...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/anthropic/endpointAnthropicVertex.ts
import { z } from "zod"; import type { Endpoint } from "../endpoints"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import { createImageProcessorOptionsValidator } from "../images"; import { endpointMessagesToAnthropicMessages } from "./utils"; import type { MessageParam } from "@anthropic-...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/anthropic/utils.ts
import { makeImageProcessor, type ImageProcessorOptions } from "../images"; import { makeDocumentProcessor, type FileProcessorOptions } from "../document"; import type { EndpointMessage } from "../endpoints"; import type { MessageFile } from "$lib/types/Message"; import type { BetaImageBlockParam, BetaMessageParam, ...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/anthropic/endpointAnthropic.ts
import { z } from "zod"; import type { Endpoint } from "../endpoints"; import { env } from "$env/dynamic/private"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import { createImageProcessorOptionsValidator } from "../images"; import { endpointMessagesToAnthropicMessages } from "./utils"; im...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/aws/endpointBedrock.ts
import { z } from "zod"; import type { Endpoint } from "../endpoints"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import { createImageProcessorOptionsValidator, makeImageProcessor } from "../images"; import type { EndpointMessage } from "../endpoints"; import type { MessageFile } from "$l...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/aws/endpointAws.ts
import { buildPrompt } from "$lib/buildPrompt"; import { textGenerationStream } from "@huggingface/inference"; import { z } from "zod"; import type { Endpoint } from "../endpoints"; export const endpointAwsParametersSchema = z.object({ weight: z.number().int().positive().default(1), model: z.any(), type: z.literal(...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/openai/endpointOai.ts
import { z } from "zod"; import { openAICompletionToTextGenerationStream } from "./openAICompletionToTextGenerationStream"; import { openAIChatToTextGenerationStream } from "./openAIChatToTextGenerationStream"; import type { CompletionCreateParamsStreaming } from "openai/resources/completions"; import type { ChatCompl...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/openai/openAIChatToTextGenerationStream.ts
import type { TextGenerationStreamOutput } from "@huggingface/inference"; import type OpenAI from "openai"; import type { Stream } from "openai/streaming"; import type { ToolCall } from "$lib/types/Tool"; type ToolCallWithParameters = { toolCall: ToolCall; parameterJsonString: string; }; function prepareToolCalls(t...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/openai/openAICompletionToTextGenerationStream.ts
import type { TextGenerationStreamOutput } from "@huggingface/inference"; import type OpenAI from "openai"; import type { Stream } from "openai/streaming"; /** * Transform a stream of OpenAI.Completions.Completion into a stream of TextGenerationStreamOutput */ export async function* openAICompletionToTextGenerationS...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/cohere/endpointCohere.ts
import { z } from "zod"; import { env } from "$env/dynamic/private"; import type { Endpoint } from "../endpoints"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import type { Cohere, CohereClient } from "cohere-ai"; import { buildPrompt } from "$lib/buildPrompt"; import { ToolResultStatus, t...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/ollama/endpointOllama.ts
import { buildPrompt } from "$lib/buildPrompt"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import type { Endpoint } from "../endpoints"; import { z } from "zod"; export const endpointOllamaParametersSchema = z.object({ weight: z.number().int().positive().default(1), model: z.any(), ty...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/google/endpointVertex.ts
import { VertexAI, HarmCategory, HarmBlockThreshold, type Content, type TextPart, } from "@google-cloud/vertexai"; import type { Endpoint, TextGenerationStreamOutputWithToolsAndWebSources } from "../endpoints"; import { z } from "zod"; import type { Message } from "$lib/types/Message"; import { createImageProcesso...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/google/endpointGenAI.ts
import { GoogleGenerativeAI, HarmBlockThreshold, HarmCategory } from "@google/generative-ai"; import type { Content, Part, SafetySetting, TextPart } from "@google/generative-ai"; import { z } from "zod"; import type { Message, MessageFile } from "$lib/types/Message"; import type { TextGenerationStreamOutput } from "@hu...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/tgi/endpointTgi.ts
import { env } from "$env/dynamic/private"; import { buildPrompt } from "$lib/buildPrompt"; import { textGenerationStream } from "@huggingface/inference"; import type { Endpoint, EndpointMessage } from "../endpoints"; import { z } from "zod"; import { createImageProcessorOptionsValidator, makeImageProcessor, type Im...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/cloudflare/endpointCloudflare.ts
import { z } from "zod"; import type { Endpoint } from "../endpoints"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import { env } from "$env/dynamic/private"; import { logger } from "$lib/server/logger"; export const endpointCloudflareParametersSchema = z.object({ weight: z.number().int(...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/llamacpp/endpointLlamacpp.ts
import { env } from "$env/dynamic/private"; import { buildPrompt } from "$lib/buildPrompt"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import type { Endpoint } from "../endpoints"; import { z } from "zod"; import { logger } from "$lib/server/logger"; export const endpointLlamacppParamete...
0
hf_public_repos/chat-ui/src/lib/server/endpoints
hf_public_repos/chat-ui/src/lib/server/endpoints/langserve/endpointLangserve.ts
import { buildPrompt } from "$lib/buildPrompt"; import { z } from "zod"; import type { Endpoint } from "../endpoints"; import type { TextGenerationStreamOutput } from "@huggingface/inference"; import { logger } from "$lib/server/logger"; export const endpointLangserveParametersSchema = z.object({ weight: z.number().i...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/chatui/logo.svg
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none"> <path fill="#2063EC" d="M4 15.55C4 9.72 8.72 5 14.55 5h4.11a9.34 9.34 0 1 1 0 18.68H7.58l-2.89 2.8a.41.41 0 0 1-.69-.3V15.55Z" /> </svg>
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/chatui/icon.svg
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 16.7844C1 8.61919 7.61919 2 15.7844 2L17.1989 2C24.4238 2 30.2808 7.85698 30.2808 15.0819C30.2808 22.3069 24.4238 28.1638 17.1989 28.1638L6.01658 28.1638L2.06037 30.1846C2.00283 30.214 1.95147 30.254 1.89847 30.2...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/chatui/favicon.svg
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 16.7844C1 8.61919 7.61919 2 15.7844 2L17.1989 2C24.4238 2 30.2808 7.85698 30.2808 15.0819C30.2808 22.3069 24.4238 28.1638 17.1989 28.1638L6.01658 28.1638L2.06037 30.1846C2.00283 30.214 1.95147 30.254 1.89847 30.2...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/chatui/manifest.json
{ "background_color": "#ffffff", "name": "Chat UI", "short_name": "Chat UI", "display": "standalone", "start_url": "/", "icons": [ { "src": "/chatui/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, { "src": "/chatui/icon-256x256.png", "sizes": "256x256", "type": "image/png" ...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/huggingchat/logo.svg
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none"> <path fill="#FFD21E" d="M4 15.55C4 9.72 8.72 5 14.55 5h4.11a9.34 9.34 0 1 1 0 18.68H7.58l-2.89 2.8a.41.41 0 0 1-.69-.3V15.55Z" /> <path fill="#32343D" d="M19.63 12.48c.37.14.52.9.9.7.71-.38.98-1.27.6-1.98a1.46 1.46 0 0 0-1.98-.61 1.4...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/huggingchat/icon.svg
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 16.7844C1 8.61919 7.61919 2 15.7844 2L17.1989 2C24.4238 2 30.2808 7.85698 30.2808 15.0819C30.2808 22.3069 24.4238 28.1638 17.1989 28.1638L6.01658 28.1638L2.06037 30.1846C2.00283 30.214 1.95147 30.254 1.89847 30.2...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/huggingchat/favicon.svg
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 16.7844C1 8.61919 7.61919 2 15.7844 2L17.1989 2C24.4238 2 30.2808 7.85698 30.2808 15.0819C30.2808 22.3069 24.4238 28.1638 17.1989 28.1638L6.01658 28.1638L2.06037 30.1846C2.00283 30.214 1.95147 30.254 1.89847 30.2...
0
hf_public_repos/chat-ui/static
hf_public_repos/chat-ui/static/huggingchat/manifest.json
{ "background_color": "#ffffff", "name": "HuggingChat", "short_name": "HuggingChat", "display": "standalone", "start_url": "/chat", "icons": [ { "src": "/chat/huggingchat/icon-36x36.png", "sizes": "36x36", "type": "image/png" }, { "src": "/chat/huggingchat/icon-48x48.png", "sizes": "48x48", ...
0
hf_public_repos/chat-ui
hf_public_repos/chat-ui/.vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "command": "npm run dev", "name": "Run development server", "request": "launch", "type": "node-terminal" } ] }
0
hf_public_repos/chat-ui
hf_public_repos/chat-ui/.vscode/settings.json
{ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll": "explicit" }, "eslint.validate": ["javascript", "svelte"], "[svelte]": { "editor.defaultFormatter": "esbenp.prettier-vscode" } }
0
hf_public_repos/chat-ui
hf_public_repos/chat-ui/scripts/updateLocalEnv.ts
import fs from "fs"; import yaml from "js-yaml"; const file = fs.readFileSync("chart/env/prod.yaml", "utf8"); // have to do a weird stringify/parse because of some node error const prod = JSON.parse(JSON.stringify(yaml.load(file))); const vars = prod.envVars as Record<string, string>; let PUBLIC_CONFIG = ""; Object....
0
hf_public_repos/chat-ui
hf_public_repos/chat-ui/scripts/setupTest.ts
import { vi, afterAll } from "vitest"; import dotenv from "dotenv"; import { resolve } from "path"; import fs from "fs"; import { MongoMemoryServer } from "mongodb-memory-server"; let mongoServer: MongoMemoryServer; // Load the .env file const envPath = resolve(__dirname, "../.env"); dotenv.config({ path: envPath }); ...
0
hf_public_repos/chat-ui
hf_public_repos/chat-ui/scripts/populate.ts
import readline from "readline"; import minimist from "minimist"; // @ts-expect-error: vite-node makes the var available but the typescript compiler doesn't see them import { env } from "$env/dynamic/private"; import { faker } from "@faker-js/faker"; import { ObjectId } from "mongodb"; // @ts-expect-error: vite-node...
0
hf_public_repos
hf_public_repos/api-inference-community/setup.cfg
[isort] default_section = FIRSTPARTY ensure_newline_before_comments = True force_grid_wrap = 0 line_length = 88 include_trailing_comma = True known_first_party = main lines_after_imports = 2 multi_line_output = 3 use_parentheses = True [flake8] ignore = E203, E501, E741, W503, W605 max-line-length = 88 per-file-ignore...
0
hf_public_repos
hf_public_repos/api-inference-community/setup.py
from setuptools import setup setup( name="api_inference_community", version="0.0.36", description="A package with helper tools to build an API Inference docker app for Hugging Face API inference using huggingface_hub", long_description=open("README.md", "r", encoding="utf-8").read(), long_descript...
0
hf_public_repos
hf_public_repos/api-inference-community/Makefile
.PHONY: quality style check_dirs := api_inference_community tests docker_images quality: black --check $(check_dirs) isort --check-only $(check_dirs) flake8 $(check_dirs) style: black $(check_dirs) isort $(check_dirs) test: pytest -sv --log-level=DEBUG tests/
0
hf_public_repos
hf_public_repos/api-inference-community/LICENSE
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, ...
0
hf_public_repos
hf_public_repos/api-inference-community/requirements.txt
starlette>=0.14.2 numpy>=1.18.0 pydantic>=2 parameterized>=0.8.1 pillow>=8.2.0 huggingface_hub>=0.20.2 datasets>=2.2 psutil>=6.0.0 pytest httpx uvicorn black isort flake8
0
hf_public_repos
hf_public_repos/api-inference-community/MANIFEST.in
include README.md requirements.txt
0
hf_public_repos
hf_public_repos/api-inference-community/README.md
This repositories enable third-party libraries integrated with [huggingface_hub](https://github.com/huggingface/huggingface_hub/) to create their own docker so that the widgets on the hub can work as the `transformers` one do. The hardware to run the API will be provided by Hugging Face for now. The `docker_images/c...
0
hf_public_repos
hf_public_repos/api-inference-community/build_docker.py
#!/usr/bin/env python import argparse import os import subprocess import sys import uuid def run(command): print(" ".join(command)) p = subprocess.run(command) if p.returncode != 0: sys.exit(p.returncode) def build(framework: str, is_gpu: bool): DEFAULT_HOSTNAME = os.getenv("DEFAULT_HOSTNAME...
0
hf_public_repos
hf_public_repos/api-inference-community/manage.py
#!/usr/bin/env python import argparse import ast import hashlib import os import subprocess import sys import uuid from huggingface_hub import HfApi class cd: """Context manager for changing the current working directory""" def __init__(self, newPath): self.newPath = os.path.expanduser(newPath) ...
0
hf_public_repos
hf_public_repos/api-inference-community/.pre-commit-config.yaml
repos: - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 rev: 5.0.4 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-isort rev: v5.7.0 # Use the revision sha / tag you want to point at hooks: - id...
0
hf_public_repos
hf_public_repos/api-inference-community/build.sh
pip install -U pip build twine python -m build python -m twine upload dist/*
0
hf_public_repos/api-inference-community
hf_public_repos/api-inference-community/api_inference_community/normalizers.py
""" Helper classes to modify pipeline outputs from tensors to expected pipeline output """ from typing import TYPE_CHECKING, Dict, List, Union Classes = Dict[str, Union[str, float]] if TYPE_CHECKING: try: import torch except Exception: pass def speaker_diarization_normalize( tensor: "t...
0
hf_public_repos/api-inference-community
hf_public_repos/api-inference-community/api_inference_community/hub.py
import json import logging import os import pathlib import re from typing import List, Optional from huggingface_hub import ModelCard, constants, hf_api, try_to_load_from_cache from huggingface_hub.file_download import repo_folder_name logger = logging.getLogger(__name__) def _cached_repo_root_path(cache_dir: path...
0
hf_public_repos/api-inference-community
hf_public_repos/api-inference-community/api_inference_community/routes.py
import base64 import io import ipaddress import logging import os import time from typing import Any, Dict import psutil from api_inference_community.validation import ( AUDIO, AUDIO_INPUTS, IMAGE, IMAGE_INPUTS, IMAGE_OUTPUTS, KNOWN_TASKS, ffmpeg_convert, normalize_payload, parse_ac...
0
hf_public_repos/api-inference-community
hf_public_repos/api-inference-community/api_inference_community/validation.py
import json import os import subprocess from base64 import b64decode from io import BytesIO from typing import Any, Dict, List, Optional, Tuple, Union import annotated_types import numpy as np from pydantic import BaseModel, RootModel, Strict, field_validator from typing_extensions import Annotated MinLength = Annot...
0
hf_public_repos/api-inference-community
hf_public_repos/api-inference-community/tests/test_hub.py
import logging import sys from unittest import TestCase from api_inference_community import hub from huggingface_hub import constants, hf_api, snapshot_download logger = logging.getLogger(__name__) logger.level = logging.DEBUG stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) cla...