feat: add OCI GenAI streaming agent foundation
This commit is contained in:
79
tests/test_oci_agent.py
Normal file
79
tests/test_oci_agent.py
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user