Spaces:
Running
Running
import { Language } from "@/components/form"; | |
export const formatInformations = ( | |
user: any, | |
spaces: any, | |
models: any, | |
collections: any, | |
spacesLikes: number, | |
modelsLikes: number, | |
collectionsUpvotes: number | |
) => { | |
const datas = { | |
name: user.fullname, | |
bio: user.details, | |
organizations: user.orgs?.map((org: any) => ({ | |
name: org.fullname, | |
})), | |
followers: user.numFollowers, | |
following: user.numFollowing, | |
total_spaces_likes: spacesLikes, | |
total_models_likes: modelsLikes, | |
total_collections_likes: collectionsUpvotes, | |
last_5_spaces: spaces | |
.map((space: any) => ({ | |
name: space?.cardData?.title ?? space.id?.split("/")[1], | |
description: space?.cardData?.short_description, | |
likes_count: space.likes, | |
last_modified: space.lastModified, | |
created_at: space.createdAt, | |
})) | |
.slice(0, 5), | |
last_5_models: models | |
.map((model: any) => ({ | |
name: model.id?.split("/")[1], | |
has_inference: model.inference, | |
likes_count: model.likes, | |
downloads_count: model.downloads, | |
pipeline_tag: model.pipeline_tag, | |
last_modified: model.lastModified, | |
created_at: model.createdAt, | |
})) | |
.slice(0, 5), | |
last_5_collections: collections | |
.map((collection: any) => ({ | |
name: collection.title, | |
description: collection.description, | |
upvotes_count: collection.upvotes, | |
})) | |
.slice(0, 5), | |
}; | |
return datas; | |
}; | |
export const transformForInference = ( | |
datas: Record<string, any>, | |
language: Language, | |
username: string | |
) => { | |
let user_content = `write a short and very sweet review with slang compliments for the following Hugging Face profile in english: ${username}. Here are the details: "${JSON.stringify( | |
datas | |
)}"`; | |
switch (language) { | |
case "fr": | |
user_content = `fais une courte et très gentille critique avec des compliments en argot pour le profil Hugging Face suivant en français: ${username}. Voici les détails: "${JSON.stringify( | |
datas | |
)}"`; | |
break; | |
case "es": | |
user_content = `redactar una reseña breve y dulce con piropos en argot para el siguiente perfil de Hugging Face : ${username}. Aquí están los detalles: "${JSON.stringify( | |
datas | |
)}"`; | |
break; | |
} | |
const chat = [ | |
{ | |
role: "assistant", | |
content: | |
"You give some love and compliment hugging face account based on their bio, name, spaces, and models as lovely and sweet as possible, and keep it short, and try to format it as beautiful as possible.", | |
}, | |
{ role: "user", content: user_content }, | |
]; | |
return chat; | |
}; | |