diff --git a/src/categories/category.service.ts b/src/categories/category.service.ts index 0426a90..01fd617 100644 --- a/src/categories/category.service.ts +++ b/src/categories/category.service.ts @@ -488,55 +488,55 @@ export class CategoryService { } async autoCategorizeWithId(user: User, link: string) { - try { - const _categories = await this.categoryRepository.findByUserId(user.id); - if (_categories.length === 0) { - throw new NotFoundException('Categories not found'); - } + 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, - })); + 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; - } - }); + 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 { title, siteName, description } = await getLinkInfo(encodeURI(link)); - const content = await getLinkContent(link); + const content = await getLinkContent(link); + + const question = `You are a machine tasked with auto-categorizing articles based on information obtained through web scraping. - const question = `You are a machine tasked with auto-categorizing articles based on information obtained through web scraping. You can only answer a single category name. Here is the article's information: ${title && `title: "${title.trim()}"`} ${ - content && - `content: "${content.replace(/\s/g, '').slice(0, 300).trim()}"` - } + content && `content: "${content.replace(/\s/g, '').slice(0, 300).trim()}"` + } ${ - description && `description: "${description.trim()}"` - } + description && `description: "${description.trim()}"` + } ${siteName && `site name: "${siteName.trim()}"`} -Given the following categories, please provide the most suitable category for the article. +Given the categories below, please provide the most suitable category for the article following the rules. +[RULES] - 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. +- If there's no suitable category, must provide reply with "None". ${categories - .map((category) => - JSON.stringify({ - id: category.id, - name: category.name, - depth: category.depth, - }), - ) - .join('\n')} - -If there's no suitable category, must provide reply with "None". + .map((category) => + JSON.stringify({ + id: category.id, + name: category.name, + depth: category.depth, + }), + ) + .join('\n')} + Present your reply options in JSON format below. \`\`\`json @@ -545,8 +545,9 @@ Present your reply options in JSON format below. "name": "category name" } \`\`\` -`; + `; + try { const response = await this.openaiService.createChatCompletion({ question, temperature: 0, diff --git a/src/contents/util/content.util.ts b/src/contents/util/content.util.ts index ad865e1..40b4ff9 100644 --- a/src/contents/util/content.util.ts +++ b/src/contents/util/content.util.ts @@ -84,7 +84,7 @@ class OGCrawler { } } - throw new InternalServerErrorException('An unknown error occurred'); + throw new InternalServerErrorException(`An unknown error occurred`); } } diff --git a/src/main.ts b/src/main.ts index 65561b3..b34b6ec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ async function bootstrap() { app.useGlobalPipes(new ValidationPipe()); app.setGlobalPrefix('api'); - if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'local') { + if (process.env.NODE_ENV !== 'prod') { const config = new DocumentBuilder() .setTitle('Quickchive') .setDescription('The API description')