Skip to content

Commit

Permalink
Fix Doc-Sum stream output format
Browse files Browse the repository at this point in the history
Keep Doc-Sum stream output aligned with v1.1 format

Fix issue:
opea-project/GenAIInfra#753

Signed-off-by: Wang, Xigui <[email protected]>
  • Loading branch information
xiguiw committed Jan 23, 2025
1 parent 0a0e582 commit 95b2a8b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion comps/llms/src/doc-summarization/integrations/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,19 @@ async def generate(self, input: DocSumChatCompletionRequest, client):
if input.stream:

async def stream_generator():
import json
from langserve.serialization import WellKnownLCSerializer

_serializer = WellKnownLCSerializer()
async for chunk in llm_chain.astream_log(docs):
data = _serializer.dumps({"ops": chunk.ops}).decode("utf-8")
chunk_data = _serializer.dumps({"ops": chunk.ops}).decode("utf-8")
parsed_data = json.loads(chunk_data)

# Extract the 'value' items
data = [op['value'] for op in parsed_data['ops'] if 'value' in op]
if isinstance(data, list) and len(data) > 1:
data = data[0]

if logflag:
logger.info(data)
yield f"data: {data}\n\n"
Expand Down

0 comments on commit 95b2a8b

Please sign in to comment.