-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agent.py
More file actions
30 lines (24 loc) · 973 Bytes
/
Copy pathtest_agent.py
File metadata and controls
30 lines (24 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# test_agent.py — sends a chat message to the running agent and prints the reply.
#
# The agent server must already be running before you execute this:
# uv run uvicorn main:app --host 0.0.0.0 --port 8000
import httpx
BASE_URL = "http://localhost:8000"
# The message to send. Formatted as a Chat Completions messages list so it
# matches exactly what the endpoint expects.
messages = [
{"role": "user", "content": "What are the BBC headlines today?"}
]
# POST to the agent's chat completions endpoint.
# timeout=60 because the agent may need to call web_search before responding.
response = httpx.post(
f"{BASE_URL}/v1/chat/completions",
json={"messages": messages},
timeout=60,
)
if not response.is_success:
print(f"Error {response.status_code}:", response.text)
raise SystemExit(1)
# The reply is in choices[0].message.content — standard Chat Completions shape.
reply = response.json()["choices"][0]["message"]["content"]
print(reply)