mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-02 08:35:08 +08:00
Fix: reset conversation variables. (#12814)
### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -283,7 +283,8 @@ class Canvas(Graph):
|
|||||||
"sys.query": "",
|
"sys.query": "",
|
||||||
"sys.user_id": tenant_id,
|
"sys.user_id": tenant_id,
|
||||||
"sys.conversation_turns": 0,
|
"sys.conversation_turns": 0,
|
||||||
"sys.files": []
|
"sys.files": [],
|
||||||
|
"sys.history": []
|
||||||
}
|
}
|
||||||
self.variables = {}
|
self.variables = {}
|
||||||
super().__init__(dsl, tenant_id, task_id)
|
super().__init__(dsl, tenant_id, task_id)
|
||||||
@ -294,12 +295,15 @@ class Canvas(Graph):
|
|||||||
self.history = self.dsl["history"]
|
self.history = self.dsl["history"]
|
||||||
if "globals" in self.dsl:
|
if "globals" in self.dsl:
|
||||||
self.globals = self.dsl["globals"]
|
self.globals = self.dsl["globals"]
|
||||||
|
if "sys.history" not in self.globals:
|
||||||
|
self.globals["sys.history"] = []
|
||||||
else:
|
else:
|
||||||
self.globals = {
|
self.globals = {
|
||||||
"sys.query": "",
|
"sys.query": "",
|
||||||
"sys.user_id": "",
|
"sys.user_id": "",
|
||||||
"sys.conversation_turns": 0,
|
"sys.conversation_turns": 0,
|
||||||
"sys.files": []
|
"sys.files": [],
|
||||||
|
"sys.history": []
|
||||||
}
|
}
|
||||||
if "variables" in self.dsl:
|
if "variables" in self.dsl:
|
||||||
self.variables = self.dsl["variables"]
|
self.variables = self.dsl["variables"]
|
||||||
@ -340,19 +344,21 @@ class Canvas(Graph):
|
|||||||
key = k[4:]
|
key = k[4:]
|
||||||
if key in self.variables:
|
if key in self.variables:
|
||||||
variable = self.variables[key]
|
variable = self.variables[key]
|
||||||
if variable["value"]:
|
|
||||||
self.globals[k] = variable["value"]
|
|
||||||
else:
|
|
||||||
if variable["type"] == "string":
|
if variable["type"] == "string":
|
||||||
self.globals[k] = ""
|
self.globals[k] = ""
|
||||||
|
variable["value"] = ""
|
||||||
elif variable["type"] == "number":
|
elif variable["type"] == "number":
|
||||||
self.globals[k] = 0
|
self.globals[k] = 0
|
||||||
|
variable["value"] = 0
|
||||||
elif variable["type"] == "boolean":
|
elif variable["type"] == "boolean":
|
||||||
self.globals[k] = False
|
self.globals[k] = False
|
||||||
|
variable["value"] = False
|
||||||
elif variable["type"] == "object":
|
elif variable["type"] == "object":
|
||||||
self.globals[k] = {}
|
self.globals[k] = {}
|
||||||
|
variable["value"] = {}
|
||||||
elif variable["type"].startswith("array"):
|
elif variable["type"].startswith("array"):
|
||||||
self.globals[k] = []
|
self.globals[k] = []
|
||||||
|
variable["value"] = []
|
||||||
else:
|
else:
|
||||||
self.globals[k] = ""
|
self.globals[k] = ""
|
||||||
else:
|
else:
|
||||||
@ -638,6 +644,7 @@ class Canvas(Graph):
|
|||||||
"created_at": st,
|
"created_at": st,
|
||||||
})
|
})
|
||||||
self.history.append(("assistant", self.get_component_obj(self.path[-1]).output()))
|
self.history.append(("assistant", self.get_component_obj(self.path[-1]).output()))
|
||||||
|
self.globals["sys.history"].append(f"{self.history[-1][0]}: {self.history[-1][1]}")
|
||||||
elif "Task has been canceled" in self.error:
|
elif "Task has been canceled" in self.error:
|
||||||
yield decorate("workflow_finished",
|
yield decorate("workflow_finished",
|
||||||
{
|
{
|
||||||
@ -715,6 +722,7 @@ class Canvas(Graph):
|
|||||||
|
|
||||||
def add_user_input(self, question):
|
def add_user_input(self, question):
|
||||||
self.history.append(("user", question))
|
self.history.append(("user", question))
|
||||||
|
self.globals["sys.history"].append(f"{self.history[-1][0]}: {self.history[-1][1]}")
|
||||||
|
|
||||||
def get_prologue(self):
|
def get_prologue(self):
|
||||||
return self.components["begin"]["obj"]._param.prologue
|
return self.components["begin"]["obj"]._param.prologue
|
||||||
|
|||||||
Reference in New Issue
Block a user