@@ -477,11 +477,24 @@ export class CategoryService {
477477
478478 async autoCategorizeWithId ( user : User , link : string ) {
479479 try {
480- const categories = await this . categoryRepository . findByUserId ( user . id ) ;
481- if ( categories . length === 0 ) {
480+ const _categories = await this . categoryRepository . findByUserId ( user . id ) ;
481+ if ( _categories . length === 0 ) {
482482 throw new NotFoundException ( 'Categories not found' ) ;
483483 }
484484
485+ const categories = _categories . map ( ( category ) => ( {
486+ ...category ,
487+ depth : 0 ,
488+ } ) ) ;
489+
490+ categories . map ( ( category , index ) => {
491+ categories . slice ( index + 1 ) . map ( ( subCategory ) => {
492+ if ( subCategory . parentId && subCategory . parentId === category . id ) {
493+ subCategory . depth = category . depth + 1 ;
494+ }
495+ } ) ;
496+ } ) ;
497+
485498 const { title, siteName, description } = await getLinkInfo ( link ) ;
486499
487500 const content = await getLinkContent ( link ) ;
@@ -497,18 +510,22 @@ You can only answer a single category name. Here is the article's information:
497510 description && `description: "${ description . trim ( ) } "`
498511 } </description>
499512<siteName>${ siteName && `site name: "${ siteName . trim ( ) } "` } </siteName>
500- Please provide the most suitable category among the following. Here is Category options: [${ [
501- ...categories ,
502- 'None' ,
503- ] . join ( ', ' ) } ]
504513
505514Given the following categories, please provide the most suitable category for the article.
515+ - The deeper the category depth, the more specific the category is.
516+ - If the 1, 2, and 3 depth categories are equally worthy of saving links, then the deeper categories should be recommended more.
506517<categories>${ categories
507518 . map ( ( category ) =>
508- JSON . stringify ( { id : category . id , name : category . name } ) ,
519+ JSON . stringify ( {
520+ id : category . id ,
521+ name : category . name ,
522+ depth : category . depth ,
523+ } ) ,
509524 )
510525 . join ( '\n' ) } </categories>
511526
527+ If there's no suitable category, must provide reply with "None".
528+
512529Present your reply options in JSON format below.
513530\`\`\`json
514531{
0 commit comments