Skip to content

Commit 9f3a758

Browse files
authored
Merge pull request #193 from import-ai/feat/open_tag
feat(tag): Add tag support when create resource via open api
2 parents 06698a8 + 40828a2 commit 9f3a758

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

src/namespace-resources/open.resource.controller.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { FileInterceptor } from '@nestjs/platform-express';
1818
import { UserId } from 'omniboxd/decorators/user-id.decorator';
1919
import { OpenCreateResourceDto } from 'omniboxd/namespace-resources/dto/open.create-resource.dto';
2020
import { ResourceType } from 'omniboxd/resources/entities/resource.entity';
21+
import { isEmpty } from 'omniboxd/utils/is-empty';
2122

2223
@Controller('open/api/v1/resources')
2324
export class OpenResourcesController {
@@ -59,13 +60,23 @@ export class OpenResourcesController {
5960
resourceData,
6061
);
6162

62-
if (!newResource.name || newResource.name.trim() === '') {
63-
await this.wizardTaskService.createGenerateTitleTask(
64-
userId,
65-
apiKey.namespaceId,
66-
{ resource_id: newResource.id },
67-
{ text: data.content },
68-
);
63+
if (!isEmpty(newResource.content?.trim())) {
64+
if (isEmpty(newResource.name?.trim())) {
65+
await this.wizardTaskService.createGenerateTitleTask(
66+
userId,
67+
apiKey.namespaceId,
68+
{ resource_id: newResource.id },
69+
{ text: data.content },
70+
);
71+
}
72+
if (isEmpty(newResource.tagIds)) {
73+
await this.wizardTaskService.createExtractTagsTask(
74+
userId,
75+
newResource.id,
76+
apiKey.namespaceId,
77+
newResource.content,
78+
);
79+
}
6980
}
7081

7182
return { id: newResource.id, name: newResource.name };

src/tasks/wizard-task.service.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,32 @@ export class WizardTaskService {
6666
);
6767
}
6868

69-
async createExtractTagsTask(parentTask: Task, repo?: Repository<Task>) {
69+
async createExtractTagsTask(
70+
userId: string,
71+
resourceId: string,
72+
namespaceId: string,
73+
text: string,
74+
repo?: Repository<Task>,
75+
) {
76+
const lang = await this.getUserLanguage(userId);
77+
return this.create(
78+
{
79+
function: 'extract_tags',
80+
input: { text, lang },
81+
namespaceId,
82+
payload: {
83+
resource_id: resourceId,
84+
},
85+
userId,
86+
},
87+
repo,
88+
);
89+
}
90+
91+
async createExtractTagsTaskFromTask(
92+
parentTask: Task,
93+
repo?: Repository<Task>,
94+
) {
7095
const lang = await this.getUserLanguage(parentTask.userId);
7196
return this.create(
7297
{

src/wizard/wizard.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class WizardService {
216216
private async triggerExtractTags(parentTask: Task): Promise<void> {
217217
try {
218218
const extractTagsTask =
219-
await this.wizardTaskService.createExtractTagsTask(parentTask);
219+
await this.wizardTaskService.createExtractTagsTaskFromTask(parentTask);
220220

221221
this.logger.debug(
222222
`Triggered extract_tags task ${extractTagsTask.id} for parent task ${parentTask.id}`,

0 commit comments

Comments
 (0)