Skip to content

Commit

Permalink
fix: summary language detect logic
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed May 1, 2024
1 parent 7bc272e commit 90e5a6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 6 additions & 4 deletions apps/core/src/modules/ai/ai.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ export class AiController {
) {}

@Post('/generate-summary')
@AuthButProd()
@Auth()
generateSummary(@Body() body: GenerateAiSummaryDto) {
return this.service.generateSummaryByOpenAI(body.refId, body.lang)
}

@Get('/summaries/ref/:id')
@AuthButProd()
@Auth()
async getSummaryByRefId(@Param() params: MongoIdDto) {
return this.service.getSummariesByRefId(params.id)
}

@Get('/summaries')
@AuthButProd()
@Auth()
async getSummaries(@Query() query: PagerDto) {
return this.service.getAllSummaries(query)
}
Expand All @@ -72,7 +72,9 @@ export class AiController {
@Req() req: FastifyBizRequest,
) {
const acceptLang = req.headers['accept-language']
const finalLang = query.lang || acceptLang || 'zh-CN'
const nextLang = query.lang || acceptLang || 'zh-CN'
const finalLang = nextLang.split('-').shift() || 'zh'

const dbStored = await this.service.getSummaryByArticleId(
params.id,
finalLang,
Expand Down
3 changes: 1 addition & 2 deletions apps/core/src/modules/ai/ai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,13 @@ CONCISE SUMMARY:`,
async getAllSummaries(pager: PagerDto) {
const { page, size } = pager
const summaries = await this.aiSummaryModel.paginate(
{},
{
page,
limit: size,
sort: {
created: -1,
},
},
{
lean: true,
leanWithId: true,
},
Expand Down

0 comments on commit 90e5a6b

Please sign in to comment.