Skip to content

Commit

Permalink
模板页面小BUG修复+后端数据库字段改为longtext
Browse files Browse the repository at this point in the history
  • Loading branch information
DazingBusing committed Jan 5, 2024
1 parent b10ac24 commit 7233c5e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/database/entities/ChatFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ChatFlow implements IChatFlow {
@Column()
name: string

@Column({ type: 'text' })
@Column({ type: 'longtext' })
flowData: string

@Column({ nullable: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Init1693840429259 implements MigrationInterface {
\`createdBy\` varchar(255) NOT NULL,
\`orgId\` varchar(255) NOT NULL,
\`name\` varchar(255) NOT NULL,
\`flowData\` text NOT NULL,
\`flowData\` longtext NOT NULL,
\`deployed\` tinyint DEFAULT NULL,
\`isPublic\` tinyint DEFAULT NULL,
\`apikeyid\` varchar(255) DEFAULT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Init1693891895163 implements MigrationInterface {
"createdBy" varchar NOT NULL,
"orgId" varchar NOT NULL,
"name" varchar NOT NULL,
"flowData" text NOT NULL,
"flowData" longtext NOT NULL,
deployed bool NULL,
"isPublic" bool NULL,
apikeyid varchar NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'
export class Init1693835579790 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS "chat_flow" ("id" varchar PRIMARY KEY NOT NULL,"createdBy" varchar NOT NULL,"orgId" varchar NOT NULL,"name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));`
`CREATE TABLE IF NOT EXISTS "chat_flow" ("id" varchar PRIMARY KEY NOT NULL,"createdBy" varchar NOT NULL,"orgId" varchar NOT NULL,"name" varchar NOT NULL, "flowData" longtext NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));`
)
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS "chat_message" ("id" varchar PRIMARY KEY NOT NULL,"createdBy" varchar NOT NULL, "orgId" varchar NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'
export class ModifyChatFlow1693920824108 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "temp_chat_flow" ("id" varchar PRIMARY KEY NOT NULL,"createdBy" varchar NOT NULL, "orgId" varchar NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));`
`CREATE TABLE "temp_chat_flow" ("id" varchar PRIMARY KEY NOT NULL,"createdBy" varchar NOT NULL, "orgId" varchar NOT NULL, "name" varchar NOT NULL, "flowData" longtext NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));`
)
await queryRunner.query(
`INSERT INTO "temp_chat_flow" ("id","createdBy","orgId", "name", "flowData", "deployed", "isPublic", "apikeyid", "chatbotConfig", "createdDate", "updatedDate") SELECT "id", "createdBy","orgId","name", "flowData", "deployed", "isPublic", "apikeyid", "chatbotConfig", "createdDate", "updatedDate" FROM "chat_flow";`
Expand Down
21 changes: 7 additions & 14 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,16 @@ export class App {
const body = req.body
const updateChatFlow = new ChatFlow()
Object.assign(updateChatFlow, body)

updateChatFlow.id = chatflow.id
createRateLimiter(updateChatFlow)

this.AppDataSource.getRepository(ChatFlow).merge(chatflow, updateChatFlow)
const result = await this.AppDataSource.getRepository(ChatFlow).save(chatflow)

// chatFlowPool is initialized only when a flow is opened
// if the user attempts to rename/update category without opening any flow, chatFlowPool will be undefined
if (this.chatflowPool) {
// Update chatflowpool inSync to false, to build Langchain again because data has been changed
this.chatflowPool.updateInSync(chatflow.id, false)
}

return res.json(result)
})

Expand Down Expand Up @@ -1274,6 +1270,7 @@ export class App {

// Send input message and get prediction result (Internal)
this.app.post('/api/v1/internal-prediction/:id', async (req: Request, res: Response) => {
console.log('123321')
await this.buildChatflow(req, res, socketIO, true)
})

Expand Down Expand Up @@ -1522,17 +1519,14 @@ export class App {
id: chatflowid
})
if (!chatflow) return res.status(404).send(`Chatflow ${chatflowid} not found`)

const chatId = incomingInput.chatId ?? incomingInput.overrideConfig?.sessionId ?? uuidv4()
const userMessageDateTime = new Date()

if (!isInternal) {
const isKeyValidated = await this.validateKey(req, chatflow)
if (!isKeyValidated) return res.status(401).send('Unauthorized')
}

let isStreamValid = false

const files = (req.files as any[]) || []

if (files.length) {
Expand All @@ -1556,7 +1550,6 @@ export class App {
stopNodeId: req.body.stopNodeId
}
}

/*** Get chatflows and prepare data ***/
const flowData = chatflow.flowData
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
Expand Down Expand Up @@ -1585,7 +1578,6 @@ export class App {
!isUpsert
)
}

if (isFlowReusable()) {
nodeToExecuteData = this.chatflowPool.activeChatflows[chatflowid].endingNodeData as INodeData
isStreamValid = isFlowValidForStream(nodes, nodeToExecuteData)
Expand Down Expand Up @@ -1703,7 +1695,7 @@ export class App {

this.chatflowPool.add(chatflowid, nodeToExecuteData, startingNodes, incomingInput?.overrideConfig)
}

console.log('第六步')
const nodeInstanceFilePath = this.nodesPool.componentNodes[nodeToExecuteData.name].filePath as string
const nodeModule = await import(nodeInstanceFilePath)
const nodeInstance = new nodeModule.nodeClass()
Expand All @@ -1712,15 +1704,15 @@ export class App {

let sessionId = undefined
if (nodeToExecuteData.instance) sessionId = checkMemorySessionId(nodeToExecuteData.instance, chatId)

console.log('第七步')
const memoryNode = this.findMemoryLabel(nodes, edges)
const memoryType = memoryNode?.data.label

console.log('第八步')
let chatHistory: IMessage[] | string = incomingInput.history
if (memoryNode && !incomingInput.history && (incomingInput.chatId || incomingInput.overrideConfig?.sessionId)) {
chatHistory = await replaceChatHistory(memoryNode, incomingInput, this.AppDataSource, databaseEntities, logger)
}

console.log('第九步')
let result = isStreamValid
? await nodeInstance.run(nodeToExecuteData, incomingInput.question, {
chatflowid,
Expand Down Expand Up @@ -1789,9 +1781,10 @@ export class App {

// Only return ChatId when its Internal OR incoming input has ChatId, to avoid confusion when calling API
if (incomingInput.chatId || isInternal) result.chatId = chatId

console.log('终于成功了')
return res.json(result)
} catch (e: any) {
console.log('报错了')
logger.error('[server]: Error:', e)
return res.status(500).send(e.message)
}
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/layout/MainLayout/Main.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

.Main .Content {
flex: 18;
height: 90vh;
overflow: auto;
}

.Main .Modal {
Expand All @@ -33,6 +35,7 @@
top: 0;
left: 0;
overflow: hidden;
z-index: 999;
}

.Main .Modal .ModalContent {
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/layout/MainLayout/Main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
}
.Content {
flex: 18;
height: 90vh;
overflow: auto;
}
.Modal {
width: 100%;
Expand All @@ -27,6 +29,7 @@
top: 0;
left: 0;
overflow: hidden;
z-index: 999;
.ModalContent {
width: 70%;
height: 90%;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/views/chatflows/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const Chatflows = () => {
alt='WorkflowEmptySVG'
/>
</Box>
<div style={{ fontSize: '12px' }}>No Chatflows Yet</div>
<div style={{ fontSize: '12px' }}>还没有创建智能体</div>
</Stack>
)}
<LoginDialog show={loginDialogOpen} dialogProps={loginDialogProps} onConfirm={onLoginClick} />
Expand Down
14 changes: 7 additions & 7 deletions packages/ui/src/views/chatmessage/ChatPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export const ChatPopUp = ({ chatflowid }) => {

const clearChat = async () => {
const confirmPayload = {
title: `Clear Chat History`,
description: `Are you sure you want to clear all chat history?`,
confirmButtonName: 'Clear',
cancelButtonName: 'Cancel'
title: `清空聊天记录`,
description: `你确定你要删除所有的聊天记录吗?`,
confirmButtonName: '清空',
cancelButtonName: '取消'
}
const isConfirmed = await confirm(confirmPayload)

Expand Down Expand Up @@ -139,7 +139,7 @@ export const ChatPopUp = ({ chatflowid }) => {
size='small'
color='secondary'
aria-label='chat'
title='Chat'
title='聊天'
onClick={handleToggle}
>
{open ? <IconX /> : <IconMessage />}
Expand All @@ -151,7 +151,7 @@ export const ChatPopUp = ({ chatflowid }) => {
size='small'
color='error'
aria-label='clear'
title='Clear Chat History'
title='清空聊天记录'
>
<IconEraser />
</StyledFab>
Expand All @@ -163,7 +163,7 @@ export const ChatPopUp = ({ chatflowid }) => {
size='small'
color='primary'
aria-label='expand'
title='Expand Chat'
title='展开聊天窗口'
>
<IconArrowsMaximize />
</StyledFab>
Expand Down

0 comments on commit 7233c5e

Please sign in to comment.