### What problem does this PR solve? https://github.com/infiniflow/ragflow/issues/8175 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)tags/v0.19.1
| def run(self, running_hint_text = "is running...🕞", **kwargs): | def run(self, running_hint_text = "is running...🕞", **kwargs): | ||||
| if not running_hint_text or not isinstance(running_hint_text, str): | if not running_hint_text or not isinstance(running_hint_text, str): | ||||
| running_hint_text = "is running...🕞" | running_hint_text = "is running...🕞" | ||||
| bypass_begin = bool(kwargs.get("bypass_begin", False)) | |||||
| if self.answer: | if self.answer: | ||||
| cpn_id = self.answer[0] | cpn_id = self.answer[0] | ||||
| if not self.path: | if not self.path: | ||||
| self.components["begin"]["obj"].run(self.history, **kwargs) | self.components["begin"]["obj"].run(self.history, **kwargs) | ||||
| self.path.append(["begin"]) | self.path.append(["begin"]) | ||||
| if bypass_begin: | |||||
| cpn = self.get_component("begin") | |||||
| downstream = cpn["downstream"] | |||||
| self.path.append(downstream) | |||||
| self.path.append([]) | self.path.append([]) | ||||
| for ii, row in stream.iterrows(): | for ii, row in stream.iterrows(): | ||||
| answer += row.to_dict()["content"] | answer += row.to_dict()["content"] | ||||
| yield {"content": answer} | yield {"content": answer} | ||||
| else: | |||||
| elif stream is not None: | |||||
| for st in stream(): | for st in stream(): | ||||
| res = st | res = st | ||||
| yield st | yield st | ||||
| if self._param.post_answers: | |||||
| if self._param.post_answers and res: | |||||
| res["content"] += random.choice(self._param.post_answers) | res["content"] += random.choice(self._param.post_answers) | ||||
| yield res | yield res | ||||
| if res is None: | |||||
| res = {"content": ""} | |||||
| self.set_output(res) | self.set_output(res) | ||||
| def set_exception(self, e): | def set_exception(self, e): |
| elif q.get("value"): | elif q.get("value"): | ||||
| outs.append(pd.DataFrame([{"content": q["value"]}])) | outs.append(pd.DataFrame([{"content": q["value"]}])) | ||||
| return outs | return outs | ||||
| def get_input(self): | def get_input(self): | ||||
| if self._param.debug_inputs: | if self._param.debug_inputs: | ||||
| return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs if v.get("value")]) | return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs if v.get("value")]) |
| "source": "agent", | "source": "agent", | ||||
| "dsl": cvs.dsl | "dsl": cvs.dsl | ||||
| } | } | ||||
| canvas.messages.append({"role": "user", "content": question, "id": message_id}) | |||||
| canvas.add_user_input(question) | |||||
| API4ConversationService.save(**conv) | API4ConversationService.save(**conv) | ||||
| conv = API4Conversation(**conv) | conv = API4Conversation(**conv) | ||||
| if not conv.message: | |||||
| conv.message = [] | |||||
| conv.message.append({ | |||||
| "role": "user", | |||||
| "content": question, | |||||
| "id": message_id | |||||
| }) | |||||
| if not conv.reference: | |||||
| conv.reference = [] | |||||
| conv.reference.append({"chunks": [], "doc_aggs": []}) | |||||
| # Handle existing session | # Handle existing session | ||||
| else: | else: | ||||
| if stream: | if stream: | ||||
| try: | try: | ||||
| completion_tokens = 0 | completion_tokens = 0 | ||||
| for ans in canvas.run(stream=True): | |||||
| for ans in canvas.run(stream=True, bypass_begin=True): | |||||
| if ans.get("running_status"): | if ans.get("running_status"): | ||||
| completion_tokens += len(tiktokenenc.encode(ans.get("content", ""))) | completion_tokens += len(tiktokenenc.encode(ans.get("content", ""))) | ||||
| yield "data: " + json.dumps( | yield "data: " + json.dumps( | ||||
| else: # Non-streaming mode | else: # Non-streaming mode | ||||
| try: | try: | ||||
| all_answer_content = "" | all_answer_content = "" | ||||
| for answer in canvas.run(stream=False): | |||||
| for answer in canvas.run(stream=False, bypass_begin=True): | |||||
| if answer.get("running_status"): | if answer.get("running_status"): | ||||
| continue | continue | ||||