|
|
|
@ -16,7 +16,6 @@ import timezone from 'dayjs/plugin/timezone'
|
|
|
|
import { createContext, useContext } from 'use-context-selector'
|
|
|
|
import { createContext, useContext } from 'use-context-selector'
|
|
|
|
import { useShallow } from 'zustand/react/shallow'
|
|
|
|
import { useShallow } from 'zustand/react/shallow'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { UUID_NIL } from '../../base/chat/constants'
|
|
|
|
|
|
|
|
import type { ChatItemInTree } from '../../base/chat/types'
|
|
|
|
import type { ChatItemInTree } from '../../base/chat/types'
|
|
|
|
import VarPanel from './var-panel'
|
|
|
|
import VarPanel from './var-panel'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
@ -84,14 +83,25 @@ const PARAM_MAP = {
|
|
|
|
frequency_penalty: 'Frequency Penalty',
|
|
|
|
frequency_penalty: 'Frequency Penalty',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function appendQAToChatList(newChatList: IChatItem[], item: any, conversationId: string, timezone: string, format: string) {
|
|
|
|
const getFormattedChatList = (messages: ChatMessage[], conversationId: string, timezone: string, format: string) => {
|
|
|
|
|
|
|
|
const newChatList: IChatItem[] = []
|
|
|
|
|
|
|
|
messages.forEach((item: ChatMessage) => {
|
|
|
|
|
|
|
|
const questionFiles = item.message_files?.filter((file: any) => file.belongs_to === 'user') || []
|
|
|
|
|
|
|
|
newChatList.push({
|
|
|
|
|
|
|
|
id: `question-${item.id}`,
|
|
|
|
|
|
|
|
content: item.inputs.query || item.inputs.default_input || item.query, // text generation: item.inputs.query; chat: item.query
|
|
|
|
|
|
|
|
isAnswer: false,
|
|
|
|
|
|
|
|
message_files: getProcessedFilesFromResponse(questionFiles.map((item: any) => ({ ...item, related_id: item.id }))),
|
|
|
|
|
|
|
|
parentMessageId: item.parent_message_id || undefined,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const answerFiles = item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || []
|
|
|
|
const answerFiles = item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || []
|
|
|
|
newChatList.push({
|
|
|
|
newChatList.push({
|
|
|
|
id: item.id,
|
|
|
|
id: item.id,
|
|
|
|
content: item.answer,
|
|
|
|
content: item.answer,
|
|
|
|
agent_thoughts: addFileInfos(item.agent_thoughts ? sortAgentSorts(item.agent_thoughts) : item.agent_thoughts, item.message_files),
|
|
|
|
agent_thoughts: addFileInfos(item.agent_thoughts ? sortAgentSorts(item.agent_thoughts) : item.agent_thoughts, item.message_files),
|
|
|
|
feedback: item.feedbacks.find((item: any) => item.from_source === 'user'), // user feedback
|
|
|
|
feedback: item.feedbacks.find(item => item.from_source === 'user'), // user feedback
|
|
|
|
adminFeedback: item.feedbacks.find((item: any) => item.from_source === 'admin'), // admin feedback
|
|
|
|
adminFeedback: item.feedbacks.find(item => item.from_source === 'admin'), // admin feedback
|
|
|
|
feedbackDisabled: false,
|
|
|
|
feedbackDisabled: false,
|
|
|
|
isAnswer: true,
|
|
|
|
isAnswer: true,
|
|
|
|
message_files: getProcessedFilesFromResponse(answerFiles.map((item: any) => ({ ...item, related_id: item.id }))),
|
|
|
|
message_files: getProcessedFilesFromResponse(answerFiles.map((item: any) => ({ ...item, related_id: item.id }))),
|
|
|
|
@ -106,7 +116,7 @@ function appendQAToChatList(newChatList: IChatItem[], item: any, conversationId:
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
]
|
|
|
|
: []),
|
|
|
|
: []),
|
|
|
|
],
|
|
|
|
] as IChatItem['log'],
|
|
|
|
workflow_run_id: item.workflow_run_id,
|
|
|
|
workflow_run_id: item.workflow_run_id,
|
|
|
|
conversationId,
|
|
|
|
conversationId,
|
|
|
|
input: {
|
|
|
|
input: {
|
|
|
|
@ -141,38 +151,8 @@ function appendQAToChatList(newChatList: IChatItem[], item: any, conversationId:
|
|
|
|
})(),
|
|
|
|
})(),
|
|
|
|
parentMessageId: `question-${item.id}`,
|
|
|
|
parentMessageId: `question-${item.id}`,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const questionFiles = item.message_files?.filter((file: any) => file.belongs_to === 'user') || []
|
|
|
|
|
|
|
|
newChatList.push({
|
|
|
|
|
|
|
|
id: `question-${item.id}`,
|
|
|
|
|
|
|
|
content: item.inputs.query || item.inputs.default_input || item.query, // text generation: item.inputs.query; chat: item.query
|
|
|
|
|
|
|
|
isAnswer: false,
|
|
|
|
|
|
|
|
message_files: getProcessedFilesFromResponse(questionFiles.map((item: any) => ({ ...item, related_id: item.id }))),
|
|
|
|
|
|
|
|
parentMessageId: item.parent_message_id || undefined,
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return newChatList
|
|
|
|
|
|
|
|
|
|
|
|
const getFormattedChatList = (messages: ChatMessage[], conversationId: string, timezone: string, format: string) => {
|
|
|
|
|
|
|
|
const newChatList: IChatItem[] = []
|
|
|
|
|
|
|
|
let nextMessageId = null
|
|
|
|
|
|
|
|
for (const item of messages) {
|
|
|
|
|
|
|
|
if (!item.parent_message_id) {
|
|
|
|
|
|
|
|
appendQAToChatList(newChatList, item, conversationId, timezone, format)
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!nextMessageId) {
|
|
|
|
|
|
|
|
appendQAToChatList(newChatList, item, conversationId, timezone, format)
|
|
|
|
|
|
|
|
nextMessageId = item.parent_message_id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (item.id === nextMessageId || nextMessageId === UUID_NIL) {
|
|
|
|
|
|
|
|
appendQAToChatList(newChatList, item, conversationId, timezone, format)
|
|
|
|
|
|
|
|
nextMessageId = item.parent_message_id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return newChatList.reverse()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// const displayedParams = CompletionParams.slice(0, -2)
|
|
|
|
// const displayedParams = CompletionParams.slice(0, -2)
|
|
|
|
|