mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-17 19:21:43 +08:00
feat: conversation support show thought
This commit is contained in:
@ -15,6 +15,5 @@ export async function POST(request: NextRequest, { params }: {
|
|||||||
|
|
||||||
// auto generate name
|
// auto generate name
|
||||||
const { data } = await client.renameConversation(conversationId, name, user, auto_generate)
|
const { data } = await client.renameConversation(conversationId, name, user, auto_generate)
|
||||||
console.log(conversationId, name, user, auto_generate)
|
|
||||||
return NextResponse.json(data)
|
return NextResponse.json(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import { replaceVarWithValues, userInputsFormToPromptVariables } from '@/utils/p
|
|||||||
import AppUnavailable from '@/app/components/app-unavailable'
|
import AppUnavailable from '@/app/components/app-unavailable'
|
||||||
import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config'
|
import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config'
|
||||||
import type { Annotation as AnnotationType } from '@/types/log'
|
import type { Annotation as AnnotationType } from '@/types/log'
|
||||||
|
import { addFileInfos, sortAgentSorts } from '@/utils/tools'
|
||||||
|
|
||||||
const Main: FC = () => {
|
const Main: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -130,13 +131,16 @@ const Main: FC = () => {
|
|||||||
id: `question-${item.id}`,
|
id: `question-${item.id}`,
|
||||||
content: item.query,
|
content: item.query,
|
||||||
isAnswer: false,
|
isAnswer: false,
|
||||||
message_files: item.message_files,
|
message_files: item.message_files?.filter((file: any) => file.belongs_to === 'user') || [],
|
||||||
|
|
||||||
})
|
})
|
||||||
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),
|
||||||
feedback: item.feedback,
|
feedback: item.feedback,
|
||||||
isAnswer: true,
|
isAnswer: true,
|
||||||
|
message_files: item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
setChatList(newChatList)
|
setChatList(newChatList)
|
||||||
|
|||||||
26
utils/tools.ts
Normal file
26
utils/tools.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import type { ThoughtItem } from '@/app/components/chat/type'
|
||||||
|
import type { VisionFile } from '@/types/app'
|
||||||
|
|
||||||
|
export const sortAgentSorts = (list: ThoughtItem[]) => {
|
||||||
|
if (!list)
|
||||||
|
return list
|
||||||
|
if (list.some(item => item.position === undefined))
|
||||||
|
return list
|
||||||
|
const temp = [...list]
|
||||||
|
temp.sort((a, b) => a.position - b.position)
|
||||||
|
return temp
|
||||||
|
}
|
||||||
|
|
||||||
|
export const addFileInfos = (list: ThoughtItem[], messageFiles: VisionFile[]) => {
|
||||||
|
if (!list || !messageFiles)
|
||||||
|
return list
|
||||||
|
return list.map((item) => {
|
||||||
|
if (item.files && item.files?.length > 0) {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
message_files: item.files.map(fileId => messageFiles.find(file => file.id === fileId)) as VisionFile[],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user