import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; import { File } from "./type"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export const ALLOWED_DOMAINS = [ "huggingface.co", "deepsite.hf.co", "localhost", "enzostvs-deepsite-v4-demo.hf.space", ]; export const COLORS = [ "red", "blue", "green", "yellow", "purple", "pink", "gray", ]; export const EMOJIS_FOR_SPACE = [ "🚀", "🔥", "✨", "💡", "🤖", "🌟", "🎉", "💎", "⚡", "🎨", "🧠", "📦", "🛠️", "🚧", "🌈", "📚", "🧩", "🔧", "🖥️", "📱", ]; export const getMentionsFromPrompt = async (prompt: string) => { const mentions = prompt.match(/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+/g); const validMentions = await Promise.all( mentions?.map(async (mention) => { let type = "model"; let response = await fetch( `https://huggingface.co/api/models/${mention}` ); if (!response.ok) { type = "dataset"; response = await fetch( `https://huggingface.co/api/datasets/${mention}` ); if (!response.ok) { return null; } } const readme = await fetch( `https://huggingface.co/${ type === "model" ? "" : "datasets/" }${mention}/raw/main/README.md` ); const readmeContent = await readme.text(); const data = await response.json(); return { library_name: data?.library_name ?? data?.cardData?.library_name, pipeline_tag: data?.pipeline_tag ?? data?.cardData?.pipeline_tag, model_id: data.id, readme: readmeContent ?? "", }; }) ?? [] ); return validMentions?.filter((mention) => mention !== null) ?? []; }; export const getContextFilesFromPrompt = async ( prompt: string, currentFiles: File[] ) => { const mentions = prompt.match(/file:\/[a-zA-Z0-9-_.\/]+/g); const filesToUseAsContext: File[] = []; if (currentFiles.length === 0) return currentFiles; if (!mentions || mentions.length === 0) return currentFiles; mentions?.forEach((mention) => { const filePath = mention.replace("file:/", ""); const matchedFile = currentFiles.find((file) => file.path === filePath); if (matchedFile) { filesToUseAsContext.push(matchedFile); } }); return filesToUseAsContext; }; export const defaultHTML = `