mirror of
https://github.com/Jeuners/astra-vision.git
synced 2026-09-09 15:02:35 +02:00
Lokaler deutscher Sprachagent für Apple Silicon: Pipecat-Pipeline mit Nemotron-ASR (MLX), Qwen über natives Ollama /api/chat, und Pocket TTS. Loopback-only WebRTC-Server mit Origin/Host-Härtung. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LVgSHNHdRx3UNTBodFmhRA
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import json
|
|
from unittest.mock import patch
|
|
|
|
import httpx
|
|
import pytest
|
|
from pipecat.processors.aggregators.llm_context import LLMContext
|
|
|
|
from astra.core import Settings
|
|
from astra.services import NativeOllamaService
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_native_stream_sends_think_false_and_returns_content():
|
|
requests = []
|
|
|
|
def handler(request):
|
|
requests.append(json.loads(request.content))
|
|
return httpx.Response(200, text='{"message":{"content":"Hallo"}}\n{"done":true}\n')
|
|
|
|
client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
|
|
service = NativeOllamaService(Settings(), lambda message: None)
|
|
with patch("astra.services.httpx.AsyncClient", return_value=client):
|
|
stream = await service.get_chat_completions(LLMContext([{"role": "user", "content": "Hi"}]))
|
|
chunks = [chunk async for chunk in stream]
|
|
assert requests[0]["think"] is False
|
|
assert chunks[0].choices[0].delta.content == "Hallo"
|
|
await service._client.close()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"body",
|
|
[
|
|
'{"message":{"thinking":"secret reasoning"}}\n',
|
|
'{"error":"out of memory"}\n',
|
|
'{"message":{"content":"incomplete"}}\n',
|
|
],
|
|
)
|
|
async def test_bad_ollama_streams_fail_explicitly(body):
|
|
client = httpx.AsyncClient(
|
|
transport=httpx.MockTransport(lambda request: httpx.Response(200, text=body))
|
|
)
|
|
service = NativeOllamaService(Settings(), lambda message: None)
|
|
with patch("astra.services.httpx.AsyncClient", return_value=client):
|
|
stream = await service.get_chat_completions(LLMContext([{"role": "user", "content": "Hi"}]))
|
|
with pytest.raises(RuntimeError):
|
|
_ = [chunk async for chunk in stream]
|
|
await service._client.close()
|