66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
|
|
"""
|
|
Smoke test for DeepAgentsAdapter streaming and context.
|
|
"""
|
|
|
|
import asyncio
|
|
import os
|
|
from contextlib import aclosing
|
|
|
|
from voice_assistant.agent.oci_deep_agent import OCIDeepAgentsAdapter
|
|
|
|
|
|
async def main():
|
|
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
|
|
|
|
if not compartment_id:
|
|
raise RuntimeError("OCI_COMPARTMENT_ID is required.")
|
|
|
|
adapter = OCIDeepAgentsAdapter(
|
|
region="sa-vinhedo-1",
|
|
compartment_id=compartment_id,
|
|
model_id="openai.gpt-4o-mini",
|
|
temperature=0.3,
|
|
max_completion_tokens=256,
|
|
timeout_seconds=60.0,
|
|
)
|
|
|
|
try:
|
|
questions = [
|
|
"Estou planejando visitar o Japão. Lembre desse destino.",
|
|
"Qual país mencionei? Responda somente com o nome.",
|
|
]
|
|
|
|
for turn_id, question in enumerate(questions, 1):
|
|
print(f"\n--- Turn {turn_id} ---")
|
|
print("User:", question)
|
|
|
|
chunks = []
|
|
|
|
async with aclosing(
|
|
adapter.stream(
|
|
session_id="agentvoice-adapter-smoke",
|
|
turn_id=turn_id,
|
|
text=question,
|
|
)
|
|
) as stream:
|
|
async for chunk in stream:
|
|
chunks.append(chunk)
|
|
print(chunk, end="", flush=True)
|
|
|
|
response = "".join(chunks).strip()
|
|
|
|
if not response:
|
|
raise RuntimeError(
|
|
f"Turn {turn_id} returned empty streaming text."
|
|
)
|
|
|
|
print(f"\nChunks: {len(chunks)}")
|
|
|
|
finally:
|
|
await adapter.aclose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|