mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-19 20:16:49 +08:00
Fix: duplicate output by async_chat_streamly (#11842)
### What problem does this PR solve? Fix: duplicate output by async_chat_streamly Refact: revert manual modification ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Refactoring --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
@ -219,15 +219,13 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _normalize_section(section):
|
def _normalize_section(section):
|
||||||
# Pad/normalize to (txt, layout, positions)
|
# pad section to length 3: (txt, sec_id, poss)
|
||||||
if not isinstance(section, (list, tuple)):
|
if len(section) == 1:
|
||||||
section = (section, "", [])
|
|
||||||
elif len(section) == 1:
|
|
||||||
section = (section[0], "", [])
|
section = (section[0], "", [])
|
||||||
elif len(section) == 2:
|
elif len(section) == 2:
|
||||||
section = (section[0], "", section[1])
|
section = (section[0], "", section[1])
|
||||||
else:
|
elif len(section) != 3:
|
||||||
section = (section[0], section[1], section[2])
|
raise ValueError(f"Unexpected section length: {len(section)} (value={section!r})")
|
||||||
|
|
||||||
txt, layoutno, poss = section
|
txt, layoutno, poss = section
|
||||||
if isinstance(poss, str):
|
if isinstance(poss, str):
|
||||||
@ -238,12 +236,9 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,
|
|||||||
if isinstance(pn, list) and pn:
|
if isinstance(pn, list) and pn:
|
||||||
pn = pn[0] # [pn] -> pn
|
pn = pn[0] # [pn] -> pn
|
||||||
poss[0] = (pn, *first[1:])
|
poss[0] = (pn, *first[1:])
|
||||||
if not poss:
|
|
||||||
poss = []
|
|
||||||
|
|
||||||
return (txt, layoutno, poss)
|
return (txt, layoutno, poss)
|
||||||
|
|
||||||
|
|
||||||
sections = [_normalize_section(sec) for sec in sections]
|
sections = [_normalize_section(sec) for sec in sections]
|
||||||
|
|
||||||
if not sections and not tbls:
|
if not sections and not tbls:
|
||||||
|
|||||||
@ -146,7 +146,6 @@ class Base(ABC):
|
|||||||
request_kwargs["stop"] = stop
|
request_kwargs["stop"] = stop
|
||||||
|
|
||||||
response = await self.async_client.chat.completions.create(**request_kwargs)
|
response = await self.async_client.chat.completions.create(**request_kwargs)
|
||||||
|
|
||||||
async for resp in response:
|
async for resp in response:
|
||||||
if not resp.choices:
|
if not resp.choices:
|
||||||
continue
|
continue
|
||||||
@ -161,7 +160,6 @@ class Base(ABC):
|
|||||||
else:
|
else:
|
||||||
reasoning_start = False
|
reasoning_start = False
|
||||||
ans = resp.choices[0].delta.content
|
ans = resp.choices[0].delta.content
|
||||||
|
|
||||||
tol = total_token_count_from_response(resp)
|
tol = total_token_count_from_response(resp)
|
||||||
if not tol:
|
if not tol:
|
||||||
tol = num_tokens_from_string(resp.choices[0].delta.content)
|
tol = num_tokens_from_string(resp.choices[0].delta.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user