feat: source id prefix env (#3103)
This commit is contained in:
@@ -80,6 +80,7 @@ const pushChatLogInternal = async ({
|
|||||||
url: string;
|
url: string;
|
||||||
metadata?: Metadata;
|
metadata?: Metadata;
|
||||||
}) => {
|
}) => {
|
||||||
|
try {
|
||||||
const [chatItemHuman, chatItemAi] = await Promise.all([
|
const [chatItemHuman, chatItemAi] = await Promise.all([
|
||||||
MongoChatItem.findById(chatItemIdHuman).lean(),
|
MongoChatItem.findById(chatItemIdHuman).lean(),
|
||||||
MongoChatItem.findById(chatItemIdAi).lean() as Promise<AIChatItemType>
|
MongoChatItem.findById(chatItemIdAi).lean() as Promise<AIChatItemType>
|
||||||
@@ -112,7 +113,10 @@ const pushChatLogInternal = async ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const responseData = chatItemAi.responseData;
|
const responseData = chatItemAi.responseData;
|
||||||
const responseTime = responseData?.reduce((acc, item) => acc + (item?.runningTime ?? 0), 0) || 0;
|
const responseTime =
|
||||||
|
responseData?.reduce((acc, item) => acc + (item?.runningTime ?? 0), 0) || 0;
|
||||||
|
|
||||||
|
const sourceIdPrefix = process.env.SOURCE_ID_PREFIX ?? '';
|
||||||
|
|
||||||
const chatLog: ChatLog = {
|
const chatLog: ChatLog = {
|
||||||
title: chat.title,
|
title: chat.title,
|
||||||
@@ -135,14 +139,17 @@ const pushChatLogInternal = async ({
|
|||||||
sourceName: chat.source ?? '-',
|
sourceName: chat.source ?? '-',
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
createdAt: new Date(chatItemAi.time).getTime(),
|
createdAt: new Date(chatItemAi.time).getTime(),
|
||||||
sourceId: `crbeer-fastgpt-${appId}`
|
sourceId: `${sourceIdPrefix}${appId}`
|
||||||
};
|
};
|
||||||
await axios
|
await axios
|
||||||
.post(url + '/api/chat/push', chatLog)
|
.post(`${url}/api/chat/push`, chatLog)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
addLog.info('[ChatLogPush] push success', res.data);
|
addLog.info('[ChatLogPush] push success', res.data);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
addLog.error('[ChatLogPush] push failed', { e, resData: e.response?.data });
|
addLog.error('[ChatLogPush] push failed', { e, resData: e.response?.data });
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
addLog.error('[ChatLogPush] error', e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,5 +50,7 @@ WORKFLOW_MAX_LOOP_TIMES=50
|
|||||||
|
|
||||||
# 对话日志推送服务
|
# 对话日志推送服务
|
||||||
# URL/INTERVAL 为空时不推送
|
# URL/INTERVAL 为空时不推送
|
||||||
|
# 前缀用于区分不同的对话日志来源
|
||||||
# CHAT_LOG_URL=http://localhost:8080
|
# CHAT_LOG_URL=http://localhost:8080
|
||||||
# CHAT_LOG_INTERVAL=10000
|
# CHAT_LOG_INTERVAL=10000
|
||||||
|
# SOURCE_ID_PREFIX=fastgpt-
|
||||||
|
|||||||
Reference in New Issue
Block a user