Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: variable in opener (#2437)

zxhlyh0850c953b320
diff --git a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx
index a8a58b55f66..85db8ae438e 100644
--- a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx
+++ b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx
@@ -36,8 +36,9 @@ const ChatWrapper = () => {
return {
...config,
supportFeedback: true,
+ opening_statement: currentConversationId ? currentConversationItem?.introduction : (config as any).opening_statement,
} as ChatConfig
- }, [appParams])
+ }, [appParams, currentConversationItem?.introduction, currentConversationId])
const {
chatList,
handleSend,
@@ -46,7 +47,10 @@ const ChatWrapper = () => {
suggestedQuestions,
} = useChat(
appConfig,
- undefined,
+ {
+ inputs: (currentConversationId ? currentConversationItem?.inputs : newConversationInputs) as any,
+ promptVariables: inputsForms,
+ },
appPrevChatList,
taskId => stopChatMessageResponding('', taskId, isInstalledApp, appId),
)
diff --git a/web/app/components/base/chat/chat/hooks.ts b/web/app/components/base/chat/chat/hooks.ts
index c056e35f3f7..896ef743695 100644
--- a/web/app/components/base/chat/chat/hooks.ts
+++ b/web/app/components/base/chat/chat/hooks.ts
@@ -100,7 +100,7 @@ export const useChat = (
const handleUpdateChatList = useCallback((newChatList: ChatItem[]) => {
setChatList(newChatList)
chatListRef.current = newChatList
- }, [setChatList])
+ }, [])
const handleResponsing = useCallback((isResponsing: boolean) => {
setIsResponsing(isResponsing)
isResponsingRef.current = isResponsing
@@ -110,19 +110,29 @@ export const useChat = (
return replaceStringWithValues(str, promptVariablesConfig?.promptVariables || [], promptVariablesConfig?.inputs || {})
}, [promptVariablesConfig?.inputs, promptVariablesConfig?.promptVariables])
useEffect(() => {
- if (config?.opening_statement && chatListRef.current.filter(item => item.isOpeningStatement).length === 0) {
- handleUpdateChatList([
- {
- id: `${Date.now()}`,
- content: getIntroduction(config.opening_statement),
- isAnswer: true,
- isOpeningStatement: true,
- suggestedQuestions: config.suggested_questions,
- },
- ...chatListRef.current,
- ])
+ if (config?.opening_statement) {
+ handleUpdateChatList(produce(chatListRef.current, (draft) => {
+ const index = draft.findIndex(item => item.isOpeningStatement)
+
+ if (index > -1) {
+ draft[index] = {
+ ...draft[index],
+ content: getIntroduction(config.opening_statement),
+ suggestedQuestions: config.suggested_questions,
+ }
+ }
+ else {
+ draft.unshift({
+ id: `${Date.now()}`,
+ content: getIntroduction(config.opening_statement),
+ isAnswer: true,
+ isOpeningStatement: true,
+ suggestedQuestions: config.suggested_questions,
+ })
+ }
+ }))
}
- }, [])
+ }, [config?.opening_statement, getIntroduction, config?.suggested_questions, handleUpdateChatList])
const handleStop = useCallback(() => {
hasStopResponded.current = true