Skip to content

Commit f2de636

Browse files
committed
fix: prevent exception chunk from being passed to _process in astream
Pop exception from chunks list (like we do for the None sentinel) so _process doesn't receive it. Guard chat_response access in ollama post_processing with .get() for when no valid chunks arrived. Signed-off-by: 0xCUB3 <skula@mit.edu>
1 parent 6f3e131 commit f2de636

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

mellea/backends/ollama.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ async def post_processing(
596596
generate_log.backend = f"ollama::{self._get_ollama_model_id()}"
597597
generate_log.model_options = mot._model_options
598598
generate_log.date = datetime.datetime.now()
599-
generate_log.model_output = mot._meta["chat_response"]
599+
generate_log.model_output = mot._meta.get("chat_response")
600600
generate_log.extra = {
601601
"format": _format,
602602
"thinking": mot._model_options.get(ModelOption.THINKING, None),

mellea/core/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ async def astream(self) -> str:
325325
elif isinstance(chunks[-1], Exception):
326326
# Mark as computed so post_process runs in finally block
327327
self._computed = True
328-
# Store exception to re-raise after cleanup
329-
exception_to_raise = chunks[-1]
328+
# Remove the exception from chunks so _process doesn't receive it
329+
exception_to_raise = chunks.pop()
330330

331331
for chunk in chunks:
332332
assert self._process is not None

0 commit comments

Comments
 (0)