Skip to content

Commit fe2ed26

Browse files
authored
Feature/Custom Assistant Builder (#3631)
* add custom assistant builder * add tools to custom assistant * add save assistant button
1 parent e020452 commit fe2ed26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3129
-216
lines changed

packages/components/nodes/chatmodels/AWSBedrock/AWSChatBedrock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AWSChatBedrock_ChatModels implements INode {
5555
name: 'model',
5656
type: 'asyncOptions',
5757
loadMethod: 'listModels',
58-
default: 'anthropic.claude-3-haiku'
58+
default: 'anthropic.claude-3-haiku-20240307-v1:0'
5959
},
6060
{
6161
label: 'Custom Model Name',

packages/server/src/Interface.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { IAction, ICommonObject, IFileUpload, INode, INodeData as INodeDataFromC
22

33
export type MessageType = 'apiMessage' | 'userMessage'
44

5-
export type ChatflowType = 'CHATFLOW' | 'MULTIAGENT'
5+
export type ChatflowType = 'CHATFLOW' | 'MULTIAGENT' | 'ASSISTANT'
6+
7+
export type AssistantType = 'CUSTOM' | 'OPENAI' | 'AZURE'
68

79
export enum ChatType {
810
INTERNAL = 'INTERNAL',

packages/server/src/controllers/assistants/index.ts

+50-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from 'express'
22
import assistantsService from '../../services/assistants'
33
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
44
import { StatusCodes } from 'http-status-codes'
5+
import { AssistantType } from '../../Interface'
56

67
const createAssistant = async (req: Request, res: Response, next: NextFunction) => {
78
try {
@@ -35,7 +36,8 @@ const deleteAssistant = async (req: Request, res: Response, next: NextFunction)
3536

3637
const getAllAssistants = async (req: Request, res: Response, next: NextFunction) => {
3738
try {
38-
const apiResponse = await assistantsService.getAllAssistants()
39+
const type = req.query.type as AssistantType
40+
const apiResponse = await assistantsService.getAllAssistants(type)
3941
return res.json(apiResponse)
4042
} catch (error) {
4143
next(error)
@@ -78,10 +80,56 @@ const updateAssistant = async (req: Request, res: Response, next: NextFunction)
7880
}
7981
}
8082

83+
const getChatModels = async (req: Request, res: Response, next: NextFunction) => {
84+
try {
85+
const apiResponse = await assistantsService.getChatModels()
86+
return res.json(apiResponse)
87+
} catch (error) {
88+
next(error)
89+
}
90+
}
91+
92+
const getDocumentStores = async (req: Request, res: Response, next: NextFunction) => {
93+
try {
94+
const apiResponse = await assistantsService.getDocumentStores()
95+
return res.json(apiResponse)
96+
} catch (error) {
97+
next(error)
98+
}
99+
}
100+
101+
const getTools = async (req: Request, res: Response, next: NextFunction) => {
102+
try {
103+
const apiResponse = await assistantsService.getTools()
104+
return res.json(apiResponse)
105+
} catch (error) {
106+
next(error)
107+
}
108+
}
109+
110+
const generateAssistantInstruction = async (req: Request, res: Response, next: NextFunction) => {
111+
try {
112+
if (!req.body) {
113+
throw new InternalFlowiseError(
114+
StatusCodes.PRECONDITION_FAILED,
115+
`Error: assistantsController.generateAssistantInstruction - body not provided!`
116+
)
117+
}
118+
const apiResponse = await assistantsService.generateAssistantInstruction(req.body.task, req.body.selectedChatModel)
119+
return res.json(apiResponse)
120+
} catch (error) {
121+
next(error)
122+
}
123+
}
124+
81125
export default {
82126
createAssistant,
83127
deleteAssistant,
84128
getAllAssistants,
85129
getAssistantById,
86-
updateAssistant
130+
updateAssistant,
131+
getChatModels,
132+
getDocumentStores,
133+
getTools,
134+
generateAssistantInstruction
87135
}

packages/server/src/controllers/documentstore/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,24 @@ const refreshDocStoreMiddleware = async (req: Request, res: Response, next: Next
410410
}
411411
}
412412

413+
const generateDocStoreToolDesc = async (req: Request, res: Response, next: NextFunction) => {
414+
try {
415+
if (typeof req.params.id === 'undefined' || req.params.id === '') {
416+
throw new InternalFlowiseError(
417+
StatusCodes.PRECONDITION_FAILED,
418+
`Error: documentStoreController.generateDocStoreToolDesc - storeId not provided!`
419+
)
420+
}
421+
if (typeof req.body === 'undefined') {
422+
throw new Error('Error: documentStoreController.generateDocStoreToolDesc - body not provided!')
423+
}
424+
const apiResponse = await documentStoreService.generateDocStoreToolDesc(req.params.id, req.body.selectedChatModel)
425+
return res.json(apiResponse)
426+
} catch (error) {
427+
next(error)
428+
}
429+
}
430+
413431
export default {
414432
deleteDocumentStore,
415433
createDocumentStore,
@@ -434,5 +452,6 @@ export default {
434452
getRateLimiterMiddleware,
435453
upsertDocStoreMiddleware,
436454
refreshDocStoreMiddleware,
437-
saveProcessingLoader
455+
saveProcessingLoader,
456+
generateDocStoreToolDesc
438457
}

packages/server/src/database/entities/Assistant.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryGeneratedColumn } from 'typeorm'
3-
import { IAssistant } from '../../Interface'
3+
import { AssistantType, IAssistant } from '../../Interface'
44

55
@Entity()
66
export class Assistant implements IAssistant {
@@ -16,6 +16,9 @@ export class Assistant implements IAssistant {
1616
@Column({ nullable: true })
1717
iconSrc?: string
1818

19+
@Column({ nullable: true, type: 'text' })
20+
type?: AssistantType
21+
1922
@Column({ type: 'timestamp' })
2023
@CreateDateColumn()
2124
createdDate: Date
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm'
2+
3+
export class AddTypeToAssistant1733011290987 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
const columnExists = await queryRunner.hasColumn('assistant', 'type')
6+
if (!columnExists) {
7+
await queryRunner.query(`ALTER TABLE \`assistant\` ADD COLUMN \`type\` TEXT;`)
8+
await queryRunner.query(`UPDATE \`assistant\` SET \`type\` = 'OPENAI';`)
9+
}
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<void> {
13+
await queryRunner.query(`ALTER TABLE \`assistant\` DROP COLUMN \`type\`;`)
14+
}
15+
}

packages/server/src/database/migrations/mariadb/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { LongTextColumn1722301395521 } from './1722301395521-LongTextColumn'
2727
import { AddCustomTemplate1725629836652 } from './1725629836652-AddCustomTemplate'
2828
import { AddArtifactsToChatMessage1726156258465 } from './1726156258465-AddArtifactsToChatMessage'
2929
import { AddFollowUpPrompts1726666318346 } from './1726666318346-AddFollowUpPrompts'
30+
import { AddTypeToAssistant1733011290987 } from './1733011290987-AddTypeToAssistant'
3031

3132
export const mariadbMigrations = [
3233
Init1693840429259,
@@ -57,5 +58,6 @@ export const mariadbMigrations = [
5758
LongTextColumn1722301395521,
5859
AddCustomTemplate1725629836652,
5960
AddArtifactsToChatMessage1726156258465,
60-
AddFollowUpPrompts1726666318346
61+
AddFollowUpPrompts1726666318346,
62+
AddTypeToAssistant1733011290987
6163
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm'
2+
3+
export class AddTypeToAssistant1733011290987 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
const columnExists = await queryRunner.hasColumn('assistant', 'type')
6+
if (!columnExists) {
7+
await queryRunner.query(`ALTER TABLE \`assistant\` ADD COLUMN \`type\` TEXT;`)
8+
await queryRunner.query(`UPDATE \`assistant\` SET \`type\` = 'OPENAI';`)
9+
}
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<void> {
13+
await queryRunner.query(`ALTER TABLE \`assistant\` DROP COLUMN \`type\`;`)
14+
}
15+
}

packages/server/src/database/migrations/mysql/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { LongTextColumn1722301395521 } from './1722301395521-LongTextColumn'
2727
import { AddCustomTemplate1725629836652 } from './1725629836652-AddCustomTemplate'
2828
import { AddArtifactsToChatMessage1726156258465 } from './1726156258465-AddArtifactsToChatMessage'
2929
import { AddFollowUpPrompts1726666302024 } from './1726666302024-AddFollowUpPrompts'
30+
import { AddTypeToAssistant1733011290987 } from './1733011290987-AddTypeToAssistant'
3031

3132
export const mysqlMigrations = [
3233
Init1693840429259,
@@ -57,5 +58,6 @@ export const mysqlMigrations = [
5758
LongTextColumn1722301395521,
5859
AddCustomTemplate1725629836652,
5960
AddArtifactsToChatMessage1726156258465,
60-
AddFollowUpPrompts1726666302024
61+
AddFollowUpPrompts1726666302024,
62+
AddTypeToAssistant1733011290987
6163
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm'
2+
3+
export class AddTypeToAssistant1733011290987 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
const columnExists = await queryRunner.hasColumn('assistant', 'type')
6+
if (!columnExists) {
7+
await queryRunner.query(`ALTER TABLE "assistant" ADD COLUMN "type" TEXT;`)
8+
await queryRunner.query(`UPDATE "assistant" SET "type" = 'OPENAI';`)
9+
}
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<void> {
13+
await queryRunner.query(`ALTER TABLE "assistant" DROP COLUMN "type";`)
14+
}
15+
}

packages/server/src/database/migrations/postgres/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { AddActionToChatMessage1721078251523 } from './1721078251523-AddActionTo
2727
import { AddCustomTemplate1725629836652 } from './1725629836652-AddCustomTemplate'
2828
import { AddArtifactsToChatMessage1726156258465 } from './1726156258465-AddArtifactsToChatMessage'
2929
import { AddFollowUpPrompts1726666309552 } from './1726666309552-AddFollowUpPrompts'
30+
import { AddTypeToAssistant1733011290987 } from './1733011290987-AddTypeToAssistant'
3031

3132
export const postgresMigrations = [
3233
Init1693891895163,
@@ -57,5 +58,6 @@ export const postgresMigrations = [
5758
AddActionToChatMessage1721078251523,
5859
AddCustomTemplate1725629836652,
5960
AddArtifactsToChatMessage1726156258465,
60-
AddFollowUpPrompts1726666309552
61+
AddFollowUpPrompts1726666309552,
62+
AddTypeToAssistant1733011290987
6163
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm'
2+
3+
export class AddTypeToAssistant1733011290987 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
const columnExists = await queryRunner.hasColumn('assistant', 'type')
6+
if (!columnExists) {
7+
await queryRunner.query(`ALTER TABLE "assistant" ADD COLUMN "type" TEXT;`)
8+
await queryRunner.query(`UPDATE "assistant" SET "type" = 'OPENAI';`)
9+
}
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<void> {
13+
await queryRunner.query(`ALTER TABLE "assistant" DROP COLUMN "type";`)
14+
}
15+
}

packages/server/src/database/migrations/sqlite/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { AddActionToChatMessage1721078251523 } from './1721078251523-AddActionTo
2626
import { AddArtifactsToChatMessage1726156258465 } from './1726156258465-AddArtifactsToChatMessage'
2727
import { AddCustomTemplate1725629836652 } from './1725629836652-AddCustomTemplate'
2828
import { AddFollowUpPrompts1726666294213 } from './1726666294213-AddFollowUpPrompts'
29+
import { AddTypeToAssistant1733011290987 } from './1733011290987-AddTypeToAssistant'
2930

3031
export const sqliteMigrations = [
3132
Init1693835579790,
@@ -55,5 +56,6 @@ export const sqliteMigrations = [
5556
AddActionToChatMessage1721078251523,
5657
AddArtifactsToChatMessage1726156258465,
5758
AddCustomTemplate1725629836652,
58-
AddFollowUpPrompts1726666294213
59+
AddFollowUpPrompts1726666294213,
60+
AddTypeToAssistant1733011290987
5961
]

packages/server/src/routes/assistants/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ router.put(['/', '/:id'], assistantsController.updateAssistant)
1616
// DELETE
1717
router.delete(['/', '/:id'], assistantsController.deleteAssistant)
1818

19+
router.get('/components/chatmodels', assistantsController.getChatModels)
20+
router.get('/components/docstores', assistantsController.getDocumentStores)
21+
router.get('/components/tools', assistantsController.getTools)
22+
23+
// Generate Assistant Instruction
24+
router.post('/generate/instruction', assistantsController.generateAssistantInstruction)
25+
1926
export default router

packages/server/src/routes/documentstore/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ router.get('/components/recordmanager', documentStoreController.getRecordManager
6161
// update the selected vector store from the playground
6262
router.post('/vectorstore/update', documentStoreController.updateVectorStoreConfigOnly)
6363

64+
// generate docstore tool description
65+
router.post('/generate-tool-desc/:id', documentStoreController.generateDocStoreToolDesc)
66+
6467
export default router

0 commit comments

Comments
 (0)