Skip to content

Commit c5557d5

Browse files
authored
Merge pull request #377 from Quickchive/develop
Develop to master
2 parents 7cee820 + faf5319 commit c5557d5

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

src/categories/category.service.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -488,55 +488,55 @@ export class CategoryService {
488488
}
489489

490490
async autoCategorizeWithId(user: User, link: string) {
491-
try {
492-
const _categories = await this.categoryRepository.findByUserId(user.id);
493-
if (_categories.length === 0) {
494-
throw new NotFoundException('Categories not found');
495-
}
491+
const _categories = await this.categoryRepository.findByUserId(user.id);
492+
if (_categories.length === 0) {
493+
throw new NotFoundException('Categories not found');
494+
}
496495

497-
const categories = _categories.map((category) => ({
498-
...category,
499-
depth: 0,
500-
}));
496+
const categories = _categories.map((category) => ({
497+
...category,
498+
depth: 0,
499+
}));
501500

502-
categories.map((category, index) => {
503-
categories.slice(index + 1).map((subCategory) => {
504-
if (subCategory.parentId && subCategory.parentId === category.id) {
505-
subCategory.depth = category.depth + 1;
506-
}
507-
});
501+
categories.map((category, index) => {
502+
categories.slice(index + 1).map((subCategory) => {
503+
if (subCategory.parentId && subCategory.parentId === category.id) {
504+
subCategory.depth = category.depth + 1;
505+
}
508506
});
507+
});
509508

510-
const { title, siteName, description } = await getLinkInfo(link);
509+
const { title, siteName, description } = await getLinkInfo(encodeURI(link));
511510

512-
const content = await getLinkContent(link);
511+
const content = await getLinkContent(link);
512+
513+
const question = `You are a machine tasked with auto-categorizing articles based on information obtained through web scraping.
513514
514-
const question = `You are a machine tasked with auto-categorizing articles based on information obtained through web scraping.
515515
You can only answer a single category name. Here is the article's information:
516516
<title>${title && `title: "${title.trim()}"`}</title>
517517
<content>${
518-
content &&
519-
`content: "${content.replace(/\s/g, '').slice(0, 300).trim()}"`
520-
}</content>
518+
content && `content: "${content.replace(/\s/g, '').slice(0, 300).trim()}"`
519+
}</content>
521520
<description>${
522-
description && `description: "${description.trim()}"`
523-
}</description>
521+
description && `description: "${description.trim()}"`
522+
}</description>
524523
<siteName>${siteName && `site name: "${siteName.trim()}"`}</siteName>
525524
526-
Given the following categories, please provide the most suitable category for the article.
525+
Given the categories below, please provide the most suitable category for the article following the rules.
526+
[RULES]
527527
- The deeper the category depth, the more specific the category is.
528528
- If the 1, 2, and 3 depth categories are equally worthy of saving links, then the deeper categories should be recommended more.
529+
- If there's no suitable category, must provide reply with "None".
529530
<categories>${categories
530-
.map((category) =>
531-
JSON.stringify({
532-
id: category.id,
533-
name: category.name,
534-
depth: category.depth,
535-
}),
536-
)
537-
.join('\n')}</categories>
538-
539-
If there's no suitable category, must provide reply with "None".
531+
.map((category) =>
532+
JSON.stringify({
533+
id: category.id,
534+
name: category.name,
535+
depth: category.depth,
536+
}),
537+
)
538+
.join('\n')}</categories>
539+
540540
541541
Present your reply options in JSON format below.
542542
\`\`\`json
@@ -545,8 +545,9 @@ Present your reply options in JSON format below.
545545
"name": "category name"
546546
}
547547
\`\`\`
548-
`;
548+
`;
549549

550+
try {
550551
const response = await this.openaiService.createChatCompletion({
551552
question,
552553
temperature: 0,

src/contents/util/content.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class OGCrawler {
8484
}
8585
}
8686

87-
throw new InternalServerErrorException('An unknown error occurred');
87+
throw new InternalServerErrorException(`An unknown error occurred`);
8888
}
8989
}
9090

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function bootstrap() {
1616
app.useGlobalPipes(new ValidationPipe());
1717
app.setGlobalPrefix('api');
1818

19-
if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'local') {
19+
if (process.env.NODE_ENV !== 'prod') {
2020
const config = new DocumentBuilder()
2121
.setTitle('Quickchive')
2222
.setDescription('The API description')

0 commit comments

Comments
 (0)