v2.9.0 (#641)
Co-authored-by: Antoine <33425718+anth2o@users.noreply.github.com> Co-authored-by: Bastien <bastien.baret@gmail.com> Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai> Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com> Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai> Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai> Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com> Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@users.noreply.github.com> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Robin Gullo <robin.gullo@mistral.ai> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
a83c81ecf5
commit
632ea8c032
253 changed files with 13965 additions and 2525 deletions
|
|
@ -15,7 +15,7 @@ from tests.mock.utils import mock_llm_chunk
|
|||
from tests.stubs.fake_backend import FakeBackend
|
||||
from vibe.core.agents.models import BuiltinAgentName
|
||||
from vibe.core.config import VibeConfig
|
||||
from vibe.core.llm.exceptions import BackendErrorBuilder
|
||||
from vibe.core.llm.exceptions import BackendError, BackendErrorBuilder
|
||||
from vibe.core.middleware import (
|
||||
ConversationContext,
|
||||
MiddlewareAction,
|
||||
|
|
@ -26,6 +26,7 @@ from vibe.core.tools.builtins.todo import TodoArgs
|
|||
from vibe.core.types import (
|
||||
ApprovalResponse,
|
||||
AssistantEvent,
|
||||
ContextTooLongError,
|
||||
FunctionCall,
|
||||
LLMMessage,
|
||||
RateLimitError,
|
||||
|
|
@ -474,6 +475,67 @@ async def test_rate_limit(observer_capture) -> None:
|
|||
assert agent.session_logger.save_interaction.await_count == 1
|
||||
|
||||
|
||||
def _build_context_too_long_backend_error() -> BackendError:
|
||||
response = httpx.Response(
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
request=httpx.Request("POST", "http://test"),
|
||||
text='{"message": "Context too long"}',
|
||||
)
|
||||
error = httpx.HTTPStatusError(
|
||||
"context too long", request=response.request, response=response
|
||||
)
|
||||
return BackendErrorBuilder.build_http_error(
|
||||
provider="mistral",
|
||||
endpoint="test",
|
||||
error=error,
|
||||
model="test-model",
|
||||
messages=[],
|
||||
temperature=0.0,
|
||||
has_tools=False,
|
||||
tool_choice=None,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_context_too_long_streaming(observer_capture) -> None:
|
||||
observed, observer = observer_capture
|
||||
backend_error = _build_context_too_long_backend_error()
|
||||
backend = FakeBackend(exception_to_raise=backend_error)
|
||||
agent = build_test_agent_loop(
|
||||
config=make_config(),
|
||||
backend=backend,
|
||||
message_observer=observer,
|
||||
enable_streaming=True,
|
||||
)
|
||||
agent.session_logger.save_interaction = AsyncMock(return_value=None)
|
||||
|
||||
with pytest.raises(ContextTooLongError):
|
||||
[_ async for _ in agent.act("Trigger context too long while streaming")]
|
||||
|
||||
assert [role for role, _ in observed] == [Role.system, Role.user]
|
||||
assert agent.session_logger.save_interaction.await_count == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_context_too_long_non_streaming(observer_capture) -> None:
|
||||
observed, observer = observer_capture
|
||||
backend_error = _build_context_too_long_backend_error()
|
||||
backend = FakeBackend(exception_to_raise=backend_error)
|
||||
agent = build_test_agent_loop(
|
||||
config=make_config(),
|
||||
backend=backend,
|
||||
message_observer=observer,
|
||||
enable_streaming=False,
|
||||
)
|
||||
agent.session_logger.save_interaction = AsyncMock(return_value=None)
|
||||
|
||||
with pytest.raises(ContextTooLongError):
|
||||
[_ async for _ in agent.act("Trigger context too long without streaming")]
|
||||
|
||||
assert [role for role, _ in observed] == [Role.system, Role.user]
|
||||
assert agent.session_logger.save_interaction.await_count == 1
|
||||
|
||||
|
||||
def _snapshot_events(events: list) -> list[tuple[str, str]]:
|
||||
return [
|
||||
(type(e).__name__, e.content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue