Skip to content

Commit

Permalink
feat: conversation support show thought
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjoel committed Jan 29, 2024
1 parent b62e34c commit 8369599
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/api/conversations/[conversationId]/name/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ export async function POST(request: NextRequest, { params }: {

// auto generate name
const { data } = await client.renameConversation(conversationId, name, user, auto_generate)
console.log(conversationId, name, user, auto_generate)
return NextResponse.json(data)
}
6 changes: 5 additions & 1 deletion app/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { replaceVarWithValues, userInputsFormToPromptVariables } from '@/utils/p
import AppUnavailable from '@/app/components/app-unavailable'
import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config'
import type { Annotation as AnnotationType } from '@/types/log'
import { addFileInfos, sortAgentSorts } from '@/utils/tools'

const Main: FC = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -130,13 +131,16 @@ const Main: FC = () => {
id: `question-${item.id}`,
content: item.query,
isAnswer: false,
message_files: item.message_files,
message_files: item.message_files?.filter((file: any) => file.belongs_to === 'user') || [],

})
newChatList.push({
id: item.id,
content: item.answer,
agent_thoughts: addFileInfos(item.agent_thoughts ? sortAgentSorts(item.agent_thoughts) : item.agent_thoughts, item.message_files),
feedback: item.feedback,
isAnswer: true,
message_files: item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [],
})
})
setChatList(newChatList)
Expand Down
26 changes: 26 additions & 0 deletions utils/tools.ts
Original file line number Diff line number Diff line change
@@ -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
})
}

0 comments on commit 8369599

Please sign in to comment.