mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-13 01:06:03 +00:00
fix(agent-runner): stabilize event context and streams
This commit is contained in:
committed by
huanghuoguoguo
parent
9bdebcdc5a
commit
a2b38f5bf2
@@ -7,6 +7,7 @@ only the necessary dependencies.
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
import pytest
|
||||
import openai # Import real openai package
|
||||
@@ -140,6 +141,36 @@ class TestInvokeLLMErrorHandling:
|
||||
|
||||
assert '频繁' in str(exc.value) or '余额' in str(exc.value)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_skips_choice_with_none_delta(self, requester_with_mocked_client, mock_model):
|
||||
"""OpenAI-compatible streams may include choice frames with delta=None."""
|
||||
|
||||
async def fake_req_stream(args, extra_body=None):
|
||||
yield SimpleNamespace(choices=[SimpleNamespace(delta=None, finish_reason=None)])
|
||||
yield SimpleNamespace(
|
||||
choices=[
|
||||
SimpleNamespace(
|
||||
delta=SimpleNamespace(model_dump=lambda: {'role': 'assistant', 'content': 'OK'}),
|
||||
finish_reason='stop',
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
requester_with_mocked_client._req_stream = fake_req_stream
|
||||
|
||||
chunks = [
|
||||
chunk
|
||||
async for chunk in requester_with_mocked_client._closure_stream(
|
||||
query=None,
|
||||
req_messages=[{'role': 'user', 'content': 'hello'}],
|
||||
use_model=mock_model,
|
||||
)
|
||||
]
|
||||
|
||||
assert len(chunks) == 1
|
||||
assert chunks[0].content == 'OK'
|
||||
assert chunks[0].is_final is True
|
||||
|
||||
|
||||
class TestInvokeEmbeddingErrorHandling:
|
||||
"""Tests for invoke_embedding error handling."""
|
||||
|
||||
Reference in New Issue
Block a user