Skip to content

Commit

Permalink
feat(user): add default assistant when user created (#137)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukáš Janeček <[email protected]>
Co-authored-by: Lukáš Janeček <[email protected]>
  • Loading branch information
xjacka and Lukáš Janeček authored Dec 13, 2024
1 parent 05a59d9 commit 328c8de
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ import { OrganizationUserRole, ProjectRole } from '@/administration/entities/con
import { Project } from '@/administration/entities/project.entity.js';
import { Organization } from '@/administration/entities/organization.entity.js';
import { IBM_ORGANIZATION_OWNER_ID } from '@/config.js';
import { Assistant } from '@/assistants/assistant.entity.js';
import { Agent, getDefaultModel } from '@/runs/execution/constants.js';
import { SystemTools } from '@/tools/entities/tool-calls/system-call.entity.js';
import { VECTOR_STORE_DEFAULT_MAX_NUM_RESULTS } from '@/vector-stores/constants.js';
import { SystemUsage } from '@/tools/entities/tool-usages/system-usage.entity.js';
import { FileSearchUsage } from '@/tools/entities/tool-usages/file-search-usage.entity.js';
import { CodeInterpreterUsage } from '@/tools/entities/tool-usages/code-interpreter-usage.entity.js';

const getUserLogger = (userId: string) => getServiceLogger('user').child({ userId });

Expand Down Expand Up @@ -122,7 +129,26 @@ export async function createUser({
.getReference(organization.id, { wrapped: true });
user.defaultProject = ORM.em.getRepository(Project).getReference(project.id, { wrapped: true });

await ORM.em.persistAndFlush([user, organization, orgUser, project, projectPrincipal]);
const assistant = new Assistant({
model: getDefaultModel(),
agent: Agent.BEE,
tools: [
new SystemUsage({ toolId: SystemTools.WEB_SEARCH }),
new SystemUsage({ toolId: SystemTools.READ_FILE }),
new FileSearchUsage({ maxNumResults: VECTOR_STORE_DEFAULT_MAX_NUM_RESULTS }),
new CodeInterpreterUsage()
],
name: 'Agent Bee',
project: ref(project),
createdBy: ref(projectPrincipal),
description: 'A general purpose agent for everyday tasks',
metadata: {
$ui_color: 'black',
$ui_icon: 'Bee'
}
});

await ORM.em.persistAndFlush([user, organization, orgUser, project, projectPrincipal, assistant]);
getUserLogger(user.id).info({ externalId, metadata }, 'User created');
return toDto(user);
}
Expand Down

0 comments on commit 328c8de

Please sign in to comment.