CoolFace
Apppublic

enzostvs/deepsite

sourceHugging Facemitupdated 8mo agoView on Hugging Face
17klikes
mentions.ts32 linesDownload Raw Back to actions
1"use client";2 3import { File } from "@/lib/type";4 5export const searchMentions = async (query: string) => {6  const promises = [searchModels(query), searchDatasets(query)];7  const results = await Promise.all(promises);8  return { models: results[0], datasets: results[1] };9};10 11const searchModels = async (query: string) => {12  const response = await fetch(13    `https://huggingface.co/api/quicksearch?q=${query}&type=model&limit=3`14  );15  const data = await response.json();16  return data?.models ?? [];17};18 19const searchDatasets = async (query: string) => {20  const response = await fetch(21    `https://huggingface.co/api/quicksearch?q=${query}&type=dataset&limit=3`22  );23  const data = await response.json();24  return data?.datasets ?? [];25};26 27export const searchFilesMentions = async (query: string, files: File[]) => {28  if (!query) return files;29  const lowerQuery = query.toLowerCase();30  return files.filter((file) => file.path.toLowerCase().includes(lowerQuery));31};32