jan/web/utils/modelSource.ts
Louis d7329c7719
chore: remove hard coded recommendation models and use cortexso featured tags (#4741)
* chore: remove hard coded recommendation models and use cortexso featured tags

* chore: polish model detail page

* chore: fix test
2025-02-26 15:54:06 +07:00

42 lines
1.1 KiB
TypeScript

/**
* This utility is to extract cortexso model description from README.md file
* @returns
*/
export const extractDescription = (text?: string) => {
if (!text) return text
const normalizedText = removeYamlFrontMatter(text)
const overviewPattern = /(?:##\s*Overview\s*\n)([\s\S]*?)(?=\n\s*##|$)/
const matches = normalizedText?.match(overviewPattern)
if (matches && matches[1]) {
return matches[1].trim()
}
return normalizedText?.slice(0, 500).trim()
}
/**
* Remove YAML (HF metadata) front matter from content
* @param content
* @returns
*/
export const removeYamlFrontMatter = (content: string): string => {
return content.replace(/^---\n([\s\S]*?)\n---\n/, '')
}
/**
* Extract model name from repo path, e.g. cortexso/tinyllama -> tinyllama
* @param modelId
* @returns
*/
export const extractModelName = (model?: string) => {
return model?.split('/')[1] ?? model
}
/**
* Extract model name from repo path, e.g. https://huggingface.co/cortexso/tinyllama -> cortexso/tinyllama
* @param modelId
* @returns
*/
export const extractModelRepo = (model?: string) => {
return model?.replace('https://huggingface.co/', '')
}