Skip to content

Commit

Permalink
Merge pull request #368 from Quickchive/feat/change-category-recommen…
Browse files Browse the repository at this point in the history
…dation-prompt

feat: change category recommendation prompt
  • Loading branch information
stae1102 authored Jan 12, 2025
2 parents 8418434 + 455ae67 commit 991792b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/categories/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,24 @@ export class CategoryService {

async autoCategorizeWithId(user: User, link: string) {
try {
const categories = await this.categoryRepository.findByUserId(user.id);
if (categories.length === 0) {
const _categories = await this.categoryRepository.findByUserId(user.id);
if (_categories.length === 0) {
throw new NotFoundException('Categories not found');
}

const categories = _categories.map((category) => ({
...category,
depth: 0,
}));

categories.map((category, index) => {
categories.slice(index + 1).map((subCategory) => {
if (subCategory.parentId && subCategory.parentId === category.id) {
subCategory.depth = category.depth + 1;
}
});
});

const { title, siteName, description } = await getLinkInfo(link);

const content = await getLinkContent(link);
Expand All @@ -497,15 +510,17 @@ You can only answer a single category name. Here is the article's information:
description && `description: "${description.trim()}"`
}</description>
<siteName>${siteName && `site name: "${siteName.trim()}"`}</siteName>
Please provide the most suitable category among the following. Here is Category options: [${[
...categories,
'None',
].join(', ')}]
Given the following categories, please provide the most suitable category for the article.
- The deeper the category depth, the more specific the category is.
- If the 1, 2, and 3 depth categories are equally worthy of saving links, then the deeper categories should be recommended more.
<categories>${categories
.map((category) =>
JSON.stringify({ id: category.id, name: category.name }),
JSON.stringify({
id: category.id,
name: category.name,
depth: category.depth,
}),
)
.join('\n')}</categories>
Expand Down

0 comments on commit 991792b

Please sign in to comment.