Skip to content

Commit

Permalink
fix generate error (#1590)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

#1550 #1210 

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
KevinHuSh authored Jul 18, 2024
1 parent 4da3ee4 commit 2b5812d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions api/apps/canvas_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ def run():
except Exception as e:
return server_error_response(e)

assert answer, "Nothing. Is it over?"
assert answer is not None, "Nothing. Is it over?"

if stream:
assert isinstance(answer, partial)
assert isinstance(answer, partial), "Nothing. Is it over?"

def sse():
nonlocal answer, cvs
Expand Down Expand Up @@ -135,12 +135,13 @@ def sse():
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
return resp

final_ans["content"] = "\n".join(answer["content"]) if "content" in answer else ""
canvas.messages.append({"role": "assistant", "content": final_ans["content"]})
if final_ans.get("reference"):
canvas.reference.append(final_ans["reference"])
cvs.dsl = json.loads(str(canvas))
UserCanvasService.update_by_id(req["id"], cvs.to_dict())
return get_json_result(data=req["dsl"])
return get_json_result(data={"answer": final_ans["content"], "reference": final_ans.get("reference", [])})


@manager.route('/reset', methods=['POST'])
Expand Down
2 changes: 1 addition & 1 deletion deepdoc/parser/ppt_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __call__(self, fnm, from_page, to_page, callback=None):
break
texts = []
for shape in sorted(
slide.shapes, key=lambda x: (x.top // 10, x.left)):
slide.shapes, key=lambda x: ((x.top if x.top is not None else 0) // 10, x.left)):
txt = self.__extract(shape)
if txt:
texts.append(txt)
Expand Down
2 changes: 1 addition & 1 deletion graph/component/arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def _run(self, history, **kwargs):

df = pd.DataFrame(arxiv_res)
if DEBUG: print(df, ":::::::::::::::::::::::::::::::::")
return df
return df
5 changes: 4 additions & 1 deletion graph/component/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def _run(self, history, **kwargs):
# prompt = re.sub(r"\{%s\}"%n, re.escape(str(v)), prompt)
prompt = re.sub(r"\{%s\}" % n, str(v), prompt)

if kwargs.get("stream"):
downstreams = self._canvas.get_component(self._id)["downstream"]
if kwargs.get("stream") \
and len(downstreams) == 1 \
and self._canvas.get_component(downstreams[0])["obj"].component_name.lower() == "answer":
return partial(self.stream_output, chat_mdl, prompt, retrieval_res)

if "empty_response" in retrieval_res.columns:
Expand Down

0 comments on commit 2b5812d

Please sign in to comment.