feat: add OCI GenAI streaming agent foundation

This commit is contained in:
2026-10-10 20:55:44 +00:00
parent 50038cca34
commit 088473a0c8
8 changed files with 1873 additions and 1 deletions

79
tests/test_oci_agent.py Normal file
View File

@@ -0,0 +1,79 @@
import json
import pytest
from voice_assistant.agent.oci import extract_text_delta
def test_extract_text_delta():
payload = {
"index": 0,
"message": {
"role": "ASSISTANT",
"content": [
{
"type": "TEXT",
"text": "Olá",
}
],
},
}
result = extract_text_delta(json.dumps(payload))
assert result == "Olá"
def test_extract_text_delta_preserves_spaces():
payload = {
"message": {
"content": [
{
"type": "TEXT",
"text": " mundo",
}
],
},
}
assert extract_text_delta(json.dumps(payload)) == " mundo"
def test_extract_text_delta_ignores_empty_text():
payload = {
"message": {
"content": [
{
"type": "TEXT",
"text": "",
}
],
},
}
assert extract_text_delta(json.dumps(payload)) is None
def test_extract_text_delta_done():
assert extract_text_delta("[DONE]") is None
def test_extract_text_delta_rejects_invalid_json():
with pytest.raises(ValueError, match="Invalid JSON"):
extract_text_delta("{invalid")
def test_extract_text_delta_ignores_non_text_events():
payload = {
"message": {
"content": [
{
"type": "OTHER",
"text": "ignored",
}
],
},
}
assert extract_text_delta(json.dumps(payload)) is None