-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from DashHub-ai/feature/summarize-projects
Add automated projects summaries
- Loading branch information
Showing
38 changed files
with
730 additions
and
47 deletions.
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
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
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,21 @@ | ||
import 'reflect-metadata'; | ||
|
||
import { pipe } from 'fp-ts/lib/function'; | ||
import { container } from 'tsyringe'; | ||
|
||
import { runTaskAsVoid, tapTaskEitherTE, tryOrThrowTE } from '@llm/commons'; | ||
import { DatabaseConnectionRepo, ElasticsearchRepo } from '~/modules'; | ||
import { ProjectsSummariesService } from '~/modules/projects-summaries'; | ||
|
||
const databaseConnectionRepo = container.resolve(DatabaseConnectionRepo); | ||
const esConnection = container.resolve(ElasticsearchRepo); | ||
|
||
const summariesService = container.resolve(ProjectsSummariesService); | ||
|
||
void pipe( | ||
summariesService.summarizeAllProjects(), | ||
tapTaskEitherTE(() => esConnection.close), | ||
tapTaskEitherTE(() => databaseConnectionRepo.close), | ||
tryOrThrowTE, | ||
runTaskAsVoid, | ||
); |
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
41 changes: 41 additions & 0 deletions
41
apps/backend/src/migrations/0028-add-projects-summarizes.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,41 @@ | ||
import type { Kysely } from 'kysely'; | ||
|
||
import { | ||
addAIGeneratedColumns, | ||
addIdColumn, | ||
addTimestampColumns, | ||
} from './utils'; | ||
|
||
export async function up(db: Kysely<any>): Promise<void> { | ||
await db.schema | ||
.alterTable('projects') | ||
.dropColumn('description') | ||
.execute(); | ||
|
||
await db.schema | ||
.createTable('projects_summaries') | ||
.$call(addIdColumn) | ||
.$call(addTimestampColumns) | ||
.$call(addAIGeneratedColumns('content')) | ||
.addColumn('project_id', 'integer', col => col.notNull().references('projects.id').onDelete('restrict')) | ||
.addColumn('last_summarized_message_id', 'uuid', col => col.references('messages.id').onDelete('restrict')) | ||
.execute(); | ||
|
||
await db | ||
.insertInto('projects_summaries') | ||
.columns(['project_id']) | ||
.expression( | ||
db.selectFrom('projects') | ||
.select(['id as project_id']), | ||
) | ||
.execute(); | ||
} | ||
|
||
export async function down(db: Kysely<any>): Promise<void> { | ||
await db.schema | ||
.alterTable('projects') | ||
.addColumn('description', 'text') | ||
.execute(); | ||
|
||
await db.schema.dropTable('projects_summaries').execute(); | ||
} |
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
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,6 @@ | ||
export * from './projects-summaries.config'; | ||
export * from './projects-summaries.cron'; | ||
export * from './projects-summaries.errors'; | ||
export * from './projects-summaries.repo'; | ||
export * from './projects-summaries.service'; | ||
export * from './projects-summaries.tables'; |
7 changes: 7 additions & 0 deletions
7
apps/backend/src/modules/projects-summaries/projects-summaries.config.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,7 @@ | ||
import { z } from 'zod'; | ||
|
||
export const ProjectsSummariesConfigV = z.object({ | ||
cron: z.string().default('*/20 * * * * *'), | ||
}); | ||
|
||
export type ProjectsSummariesConfigT = z.infer<typeof ProjectsSummariesConfigV>; |
46 changes: 46 additions & 0 deletions
46
apps/backend/src/modules/projects-summaries/projects-summaries.cron.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,46 @@ | ||
import { flow } from 'fp-ts/lib/function'; | ||
import { inject, injectable } from 'tsyringe'; | ||
|
||
import { runTaskAsVoid, tryOrThrowTE } from '@llm/commons'; | ||
import { ConfigService } from '~/modules/config'; | ||
|
||
import { CronJob, CronService } from '../cron'; | ||
import { LoggerService } from '../logger'; | ||
import { ProjectsSummariesService } from './projects-summaries.service'; | ||
|
||
@injectable() | ||
export class ProjectSummariesCronJob extends CronJob { | ||
private readonly logger = LoggerService.of('ProjectSummariesCronJob'); | ||
|
||
constructor( | ||
@inject(CronService) cronService: CronService, | ||
@inject(ConfigService) configService: ConfigService, | ||
@inject(ProjectsSummariesService) private readonly projectsSummariesService: ProjectsSummariesService, | ||
) { | ||
super(cronService, configService); | ||
} | ||
|
||
registerCronJob(): void { | ||
const { logger } = this; | ||
const { cron } = this.config.projectsSummaries; | ||
|
||
if (!cron) { | ||
logger.warn('ProjectSummariesCronJob cron job is disabled!'); | ||
return; | ||
} | ||
|
||
this.cronService.tryRegister( | ||
{ | ||
expression: cron, | ||
skipIfPreviousJobNotDone: true, | ||
}, | ||
flow( | ||
this.projectsSummariesService.summarizeAllProjects, | ||
tryOrThrowTE, | ||
runTaskAsVoid, | ||
), | ||
); | ||
|
||
logger.info('Registered ProjectSummariesCronJob cron job!'); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/backend/src/modules/projects-summaries/projects-summaries.errors.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,7 @@ | ||
import type { SdKSearchMessagesOutputT } from '@llm/sdk'; | ||
|
||
import { TaggedError } from '@llm/commons'; | ||
|
||
export class MissingAIModelInProjectError | ||
extends TaggedError.ofLiteral<SdKSearchMessagesOutputT>()('MissingAIModelInProject') { | ||
} |
Oops, something went wrong.