mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-14 23:22:22 +00:00
fix: reference history format;perf: add error to chat log (#5153)
* perf: add error to chat log * fix: reference history format
This commit is contained in:
@@ -120,7 +120,7 @@ const Logs = () => {
|
||||
refreshDeps: [chatSources, logTitle]
|
||||
}
|
||||
);
|
||||
console.log(dateRange, 111);
|
||||
|
||||
return (
|
||||
<Flex
|
||||
flexDirection={'column'}
|
||||
|
@@ -170,7 +170,7 @@ async function handler(
|
||||
),
|
||||
MongoChat.countDocuments(where, { ...readFromSecondary })
|
||||
]);
|
||||
console.log(list);
|
||||
|
||||
const listWithSourceMember = await addSourceMember({
|
||||
list
|
||||
});
|
||||
|
@@ -78,6 +78,7 @@ const scheduleTriggerAppCron = () => {
|
||||
getScheduleTriggerApp();
|
||||
}
|
||||
});
|
||||
getScheduleTriggerApp();
|
||||
};
|
||||
|
||||
export const startCron = () => {
|
||||
|
@@ -22,8 +22,11 @@ import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runti
|
||||
import { type UserChatItemValueItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { saveChat } from '@fastgpt/service/core/chat/saveChat';
|
||||
import { getAppLatestVersion } from '@fastgpt/service/core/app/version/controller';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
|
||||
export const getScheduleTriggerApp = async () => {
|
||||
addLog.info('Schedule trigger app');
|
||||
|
||||
// 1. Find all the app
|
||||
const apps = await retryFn(() => {
|
||||
return MongoApp.find({
|
||||
@@ -35,25 +38,26 @@ export const getScheduleTriggerApp = async () => {
|
||||
// 2. Run apps
|
||||
await Promise.allSettled(
|
||||
apps.map(async (app) => {
|
||||
try {
|
||||
if (!app.scheduledTriggerConfig) return;
|
||||
// random delay 0 ~ 60s
|
||||
await delay(Math.floor(Math.random() * 60 * 1000));
|
||||
const { timezone, externalProvider } = await getUserChatInfoAndAuthTeamPoints(app.tmbId);
|
||||
if (!app.scheduledTriggerConfig) return;
|
||||
const chatId = getNanoid();
|
||||
// random delay 0 ~ 60s
|
||||
await delay(Math.floor(Math.random() * 60 * 1000));
|
||||
const { timezone, externalProvider } = await retryFn(() =>
|
||||
getUserChatInfoAndAuthTeamPoints(app.tmbId)
|
||||
);
|
||||
|
||||
// Get app latest version
|
||||
const { nodes, edges, chatConfig } = await getAppLatestVersion(app._id, app);
|
||||
|
||||
const chatId = getNanoid();
|
||||
const userQuery: UserChatItemValueItemType[] = [
|
||||
{
|
||||
type: ChatItemValueTypeEnum.text,
|
||||
text: {
|
||||
content: app.scheduledTriggerConfig?.defaultPrompt
|
||||
}
|
||||
// Get app latest version
|
||||
const { nodes, edges, chatConfig } = await retryFn(() => getAppLatestVersion(app._id, app));
|
||||
const userQuery: UserChatItemValueItemType[] = [
|
||||
{
|
||||
type: ChatItemValueTypeEnum.text,
|
||||
text: {
|
||||
content: app.scheduledTriggerConfig?.defaultPrompt
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
try {
|
||||
const { flowUsages, assistantResponses, flowResponses, durationSeconds, system_memories } =
|
||||
await retryFn(() => {
|
||||
return dispatchWorkFlow({
|
||||
@@ -82,6 +86,8 @@ export const getScheduleTriggerApp = async () => {
|
||||
});
|
||||
});
|
||||
|
||||
const error = flowResponses[flowResponses.length - 1]?.error;
|
||||
|
||||
// Save chat
|
||||
await saveChat({
|
||||
chatId,
|
||||
@@ -106,7 +112,8 @@ export const getScheduleTriggerApp = async () => {
|
||||
memories: system_memories
|
||||
}
|
||||
],
|
||||
durationSeconds
|
||||
durationSeconds,
|
||||
errorMsg: getErrText(error)
|
||||
});
|
||||
createChatUsage({
|
||||
appName: app.name,
|
||||
@@ -116,15 +123,39 @@ export const getScheduleTriggerApp = async () => {
|
||||
source: UsageSourceEnum.cronJob,
|
||||
flowUsages
|
||||
});
|
||||
|
||||
// update next time
|
||||
app.scheduledTriggerNextTime = getNextTimeByCronStringAndTimezone(
|
||||
app.scheduledTriggerConfig
|
||||
);
|
||||
await app.save();
|
||||
} catch (error) {
|
||||
addLog.warn('Schedule trigger error', { error });
|
||||
addLog.error('Schedule trigger error', error);
|
||||
|
||||
await saveChat({
|
||||
chatId,
|
||||
appId: app._id,
|
||||
teamId: String(app.teamId),
|
||||
tmbId: String(app.tmbId),
|
||||
nodes,
|
||||
appChatConfig: chatConfig,
|
||||
variables: {},
|
||||
isUpdateUseTime: false, // owner update use time
|
||||
newTitle: 'Cron Job',
|
||||
source: ChatSourceEnum.cronJob,
|
||||
content: [
|
||||
{
|
||||
obj: ChatRoleEnum.Human,
|
||||
value: userQuery
|
||||
},
|
||||
{
|
||||
obj: ChatRoleEnum.AI,
|
||||
value: [],
|
||||
[DispatchNodeResponseKeyEnum.nodeResponse]: []
|
||||
}
|
||||
],
|
||||
durationSeconds: 0,
|
||||
errorMsg: getErrText(error)
|
||||
});
|
||||
}
|
||||
|
||||
// update next time
|
||||
app.scheduledTriggerNextTime = getNextTimeByCronStringAndTimezone(app.scheduledTriggerConfig);
|
||||
await app.save().catch();
|
||||
})
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user