Encodes a chunk to a JSON string with a newline.
(chunk: Any)
| 786 | adk_app._tmpl_attrs["artifact_service"] = artifact_service |
| 787 | |
| 788 | def _encode_chunk_to_json(chunk: Any) -> str | None: |
| 789 | """Encodes a chunk to a JSON string with a newline.""" |
| 790 | try: |
| 791 | json_chunk = jsonable_encoder(chunk) |
| 792 | return f"{json.dumps(json_chunk)}\n" |
| 793 | except Exception: |
| 794 | logging.exception("Failed to encode chunk") |
| 795 | return None |
| 796 | |
| 797 | async def json_generator(output: AsyncIterator[Any]) -> AsyncIterator[str]: |
| 798 | async for chunk in output: |