Skip to content

Commit

Permalink
Merge pull request #377 from Quickchive/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
stae1102 authored Jan 12, 2025
2 parents 7cee820 + faf5319 commit c5557d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
71 changes: 36 additions & 35 deletions src/categories/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "${title.trim()}"`}</title>
<content>${
content &&
`content: "${content.replace(/\s/g, '').slice(0, 300).trim()}"`
}</content>
content && `content: "${content.replace(/\s/g, '').slice(0, 300).trim()}"`
}</content>
<description>${
description && `description: "${description.trim()}"`
}</description>
description && `description: "${description.trim()}"`
}</description>
<siteName>${siteName && `site name: "${siteName.trim()}"`}</siteName>
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>${categories
.map((category) =>
JSON.stringify({
id: category.id,
name: category.name,
depth: category.depth,
}),
)
.join('\n')}</categories>
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')}</categories>
Present your reply options in JSON format below.
\`\`\`json
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/contents/util/content.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class OGCrawler {
}
}

throw new InternalServerErrorException('An unknown error occurred');
throw new InternalServerErrorException(`An unknown error occurred`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit c5557d5

Please sign in to comment.