Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai>
Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai>
Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai>
Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai>
Co-Authored-By: Clément Siriex <clement.sirieix@mistral.ai>
Co-Authored-By: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-Authored-By: Thaddee Tyl <thaddee.tyl@gmail.com>
Co-Authored-By: David Brochart <david.brochart@gmail.com>
Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com>
Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com>
Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
This commit is contained in:
Mathias Gesbert 2026-01-27 16:39:30 +01:00 committed by Mathias Gesbert
parent 79f215d91c
commit d33db9fff8
217 changed files with 16911 additions and 4305 deletions

View file

@ -1,8 +1,16 @@
from __future__ import annotations
from collections.abc import AsyncGenerator
import json
from vibe.core.types import LLMChunk, LLMMessage, LLMUsage, Role, ToolCall
from vibe.core.types import (
LLMChunk,
LLMMessage,
LLMUsage,
Role,
ToolCall,
ToolStreamEvent,
)
MOCK_DATA_ENV_VAR = "VIBE_MOCK_LLM_DATA"
@ -39,4 +47,15 @@ def get_mocking_env(mock_chunks: list[LLMChunk] | None = None) -> dict[str, str]
mock_data = [LLMChunk.model_dump(mock_chunk) for mock_chunk in mock_chunks]
return {MOCK_DATA_ENV_VAR: json.dumps(mock_data)}
return {MOCK_DATA_ENV_VAR: json.dumps(mock_data, ensure_ascii=False)}
async def collect_result[T](gen: AsyncGenerator[ToolStreamEvent | T, None]) -> T:
"""Collect the final result from an AsyncGenerator, filtering out stream events."""
result = None
async for item in gen:
if not isinstance(item, ToolStreamEvent):
result = item
if result is None:
raise RuntimeError("Generator did not yield a result")
return result