4.8.13 test (#3098)

* perf: loop node refresh

* rename context

* comment

* fix: ts

* perf: push chat log
This commit is contained in:
Archer
2024-11-08 16:02:33 +08:00
committed by archer
parent 0a238845ab
commit c5022654ca
36 changed files with 303 additions and 221 deletions

View File

@@ -2,7 +2,7 @@ import { addLog } from '../../common/system/log';
import { MongoChatItem } from './chatItemSchema';
import { MongoChat } from './chatSchema';
import axios from 'axios';
import { ChatItemType } from '@fastgpt/global/core/chat/type';
import { AIChatItemType, ChatItemType } from '@fastgpt/global/core/chat/type';
export type Metadata = {
[key: string]: {
@@ -81,17 +81,15 @@ const pushChatLogInternal = async ({
metadata?: Metadata;
}) => {
const [chatItemHuman, chatItemAi] = await Promise.all([
MongoChatItem.findById(chatItemIdHuman).lean() as Promise<ChatItem>,
MongoChatItem.findById(chatItemIdAi).lean() as Promise<ChatItem>
MongoChatItem.findById(chatItemIdHuman).lean(),
MongoChatItem.findById(chatItemIdAi).lean() as Promise<AIChatItemType>
]);
const [chat] = (await MongoChat.find({ chatId }).lean()) as {
title: string;
outLinkUid: string | undefined;
tmbId: string;
teamId: string;
metadata: Object;
source: string;
}[];
if (!chatItemHuman || !chatItemAi) {
return;
}
const chat = await MongoChat.findOne({ chatId }).lean();
// addLog.warn('ChatLogDebug', chat);
// addLog.warn('ChatLogDebug', { chatItemHuman, chatItemAi });
@@ -114,10 +112,7 @@ const pushChatLogInternal = async ({
return;
}
const responseData = chatItemAi.responseData;
let responseTime = 0;
responseData.forEach((item) => {
responseTime += item.runningTime;
});
const responseTime = responseData?.reduce((acc, item) => acc + (item?.runningTime ?? 0), 0) || 0;
const chatLog: ChatLog = {
title: chat.title,
@@ -138,6 +133,7 @@ const pushChatLogInternal = async ({
responseTime: responseTime * 1000,
metadata: metadataString,
sourceName: chat.source ?? '-',
// @ts-ignore
createdAt: new Date(chatItemAi.time).getTime(),
sourceId: `crbeer-fastgpt-${appId}`
};

View File

@@ -25,7 +25,7 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
user,
node: { name }
} = props;
const { loopInputArray = [], childrenNodeIdList } = params;
const { loopInputArray = [], childrenNodeIdList = [] } = params;
if (!Array.isArray(loopInputArray)) {
return Promise.reject('Input value is not an array');

View File

@@ -11,7 +11,7 @@ import {
import { TUpdateListItem } from '@fastgpt/global/core/workflow/template/system/variableUpdate/type';
import { ModuleDispatchProps } from '@fastgpt/global/core/workflow/runtime/type';
import { removeSystemVariable, valueTypeFormat } from '../utils';
import { isReferenceValue } from '@fastgpt/global/core/workflow/utils';
import { isValidReferenceValue } from '@fastgpt/global/core/workflow/utils';
type Props = ModuleDispatchProps<{
[NodeInputKeyEnum.updateList]: TUpdateListItem[];
@@ -27,13 +27,17 @@ export const dispatchUpdateVariable = async (props: Props): Promise<Response> =>
const result = updateList.map((item) => {
const variable = item.variable;
if (!isReferenceValue(variable, nodeIds)) {
if (!isValidReferenceValue(variable, nodeIds)) {
return null;
}
const varNodeId = variable[0];
const varKey = variable[1];
if (!varKey) {
return null;
}
const value = (() => {
// If first item is empty, it means it is a input value
if (!item.value?.[0]) {