import json
import sys
import requests
BASE = "http://localhost:8080/openai/v1/chat/completions"
HEADERS = {"Content-Type": "application/json", "Authorization": "Bearer not-needed"}
def call(turn_index: int) -> None:
body = {
"model": "gpt-5",
"messages": [
{"role": "user", "content": f"turn {turn_index}"},
],
}
resp = requests.post(BASE, headers=HEADERS, data=json.dumps(body), timeout=10)
print(f"=== Turn {turn_index} (HTTP {resp.status_code}) ===")
data = resp.json()
if resp.status_code != 200:
print(f" error: {data.get('error', {}).get('message')}")
return
choice = data["choices"][0]
msg = choice["message"]
finish = choice.get("finish_reason")
print(f" finish_reason: {finish}")
if msg.get("content"):
print(f" content: {msg['content']!r}")
for tc in msg.get("tool_calls") or []:
fn = tc["function"]
print(f" tool_call id={tc['id']} name={fn['name']} args={fn['arguments']}")
def main() -> int:
for i in range(5):
call(i)
return 0
if __name__ == "__main__":
sys.exit(main())