-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AI 분류 시 PostKeyword 데이터도 같이 생성 및 적용 #60
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
31582b3
chore: apply auto organize
Marades 4a8cdce
chore: add discord alarm
Marades 6ca291e
chore: add createdAt to post list
Marades 979b5bb
feat: Add post keywords by ai classification
Marades 62dcd91
feat: discord 알림 추가
Marades 2fb40c1
feat: 커스텀 폴더 및 post 초기화
Marades 442fde6
feat: AI 요약 시 추출 keyword 저장 및 리팩토링
Marades 48ee0f1
feat: post 조회 시 keyword 도 같이 반환
Marades 1395eb1
feat: post 리턴 시 keyword붙이기 편하게 리팩토링
Marades 409f934
feat: 폴더 내 링크 목록 정렬 적용
Marades 6a6b692
chore: 로컬에서 에러 알림 제외
Marades 0f8f169
chore: 로컬에서 디코 알림 제외
Marades f96f2e6
Merge branch 'develop' into feat/apply-post-keywords
Marades 96fe6ed
chore: 폴더 리스폰스에 키워드 추가 작업 최신 브랜치 작업본에 반영
Marades b270fcd
feat: 폴더 삭제 시 post 삭제 로직 추가
JonghunAn 6d38e33
refactor: 커스텀 폴더 전체 삭제 시 folderIdList 반환으로 변경
JonghunAn eda33ec
refactor: classification service export
JonghunAn b3a2a3b
refactor: classification module forwardRef
JonghunAn 12d066c
feat: add delete classificationList at suggestedFolder delete
JonghunAn 130b4af
feat: soft-delete classification rows
JonghunAn a21719d
Merge branch 'develop' into feat/apply-post-keywords
Marades File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": "explicit" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,36 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from '@src/app.module'; | ||
import { AiService } from '@src/infrastructure/ai/ai.service'; | ||
import { PostAiStatus } from '@src/modules/posts/posts.constant'; | ||
import { Handler } from 'aws-lambda'; | ||
import { LambdaEventPayload } from './infrastructure/aws-lambda/type'; | ||
import { ClassficiationRepository } from './modules/classification/classification.repository'; | ||
import { MetricsRepository } from './modules/metrics/metrics.repository'; | ||
import { PostsRepository } from './modules/posts/posts.repository'; | ||
import { DatabaseModule } from './infrastructure'; | ||
import { AiClassificationPayload } from './infrastructure/aws-lambda/type'; | ||
import { AiClassificationModule } from './modules/ai-classification/ai-classification.module'; | ||
import { AiClassificationService } from './modules/ai-classification/ai-classification.service'; | ||
|
||
export const handler: Handler = async (event: LambdaEventPayload) => { | ||
const app = await NestFactory.create(AppModule); | ||
const aiService = app.get(AiService); | ||
const classificationRepository = app.get(ClassficiationRepository); | ||
const postRepository = app.get(PostsRepository); | ||
const metricsRepository = app.get(MetricsRepository); | ||
@Module({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
isGlobal: true, | ||
cache: true, | ||
envFilePath: `.env.${process.env.NODE_ENV || 'local'}`, | ||
}), | ||
DatabaseModule, | ||
AiClassificationModule, | ||
], | ||
providers: [AiClassificationService], | ||
}) | ||
class WorkerModule {} | ||
|
||
// Map - (Folder Name):(Folder ID) | ||
const folderMapper = {}; | ||
// Build foldeMapper | ||
event.folderList.forEach((folder) => { | ||
folderMapper[folder.name] = folder.id; | ||
}); | ||
|
||
// NOTE: AI 요약 요청 | ||
const start = process.hrtime(); | ||
const summarizeUrlContent = await aiService.summarizeLinkContent( | ||
event.postContent, | ||
Object.keys(folderMapper), // 중복성 줄이기 위해 | ||
); | ||
const end = process.hrtime(start); | ||
const timeSecond = end[0] + end[1] / 1e9; | ||
|
||
const postId = event.postId; | ||
let classificationId = null; | ||
let postAiStatus = PostAiStatus.FAIL; | ||
export const handler: Handler = async (event: AiClassificationPayload) => { | ||
const app = await NestFactory.create(WorkerModule); | ||
const aiClassificationService = app.get(AiClassificationService); | ||
|
||
// NOTE : 요약 성공 시 classification 생성, post 업데이트 | ||
if (summarizeUrlContent.success) { | ||
const folderId = folderMapper[summarizeUrlContent.response.category]; | ||
const post = await postRepository.findPostByIdForAIClassification(postId); | ||
const classification = await classificationRepository.createClassification( | ||
post.url, | ||
summarizeUrlContent.response.summary, | ||
summarizeUrlContent.response.keywords, | ||
folderId, | ||
); | ||
// Save metrics | ||
await metricsRepository.createMetrics( | ||
summarizeUrlContent.success, | ||
timeSecond, | ||
post.url, | ||
post._id.toString(), | ||
); | ||
classificationId = classification._id.toString(); | ||
postAiStatus = PostAiStatus.SUCCESS; | ||
} | ||
await postRepository.updatePostClassificationForAIClassification( | ||
postAiStatus, | ||
postId, | ||
classificationId, | ||
summarizeUrlContent.response.summary, | ||
); | ||
const result = await aiClassificationService.execute(event); | ||
|
||
// NOTE: cloud-watch 로그 확인용 | ||
console.log({ | ||
result: summarizeUrlContent.success ? 'success' : 'fail', | ||
result: result.success ? 'success' : 'fail', | ||
event: JSON.stringify(event, null, 2), | ||
summarizeUrlContent: summarizeUrlContent, | ||
summarizeUrlContent: result, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const IS_LOCAL = process.env.NODE_ENV === 'local'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export type LambdaEventPayload = { | ||
export type AiClassificationPayload = { | ||
postContent: string; | ||
folderList: { id: string; name: string }[]; | ||
userId: string; | ||
postId: string; | ||
url: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { DiscordWebhookProvider } from './discord-webhook.provider'; | ||
|
||
@Injectable() | ||
export class DiscordAIWebhookProvider extends DiscordWebhookProvider { | ||
protected readonly webhookUrl: string; | ||
|
||
constructor(private readonly configService: ConfigService) { | ||
super(); | ||
this.webhookUrl = this.configService.get('DISCORD_AI_WEBHOOK_URL'); | ||
} | ||
|
||
public async send(content: string) { | ||
await super.send(this.webhookUrl, content); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/infrastructure/discord/discord-error-webhook.provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { DiscordWebhookProvider } from './discord-webhook.provider'; | ||
|
||
@Injectable() | ||
export class DiscordErrorWebhookProvider extends DiscordWebhookProvider { | ||
protected webhookUrl: string; | ||
|
||
constructor(private readonly configService: ConfigService) { | ||
super(); | ||
this.webhookUrl = this.configService.get('DISCORD_ERROR_WEBHOOK_URL'); | ||
} | ||
|
||
public async send(content: string) { | ||
await super.send(this.webhookUrl, content); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋아용~~!!