#!/usr/bin/env python3 """ TokioAI Engine -- OpenAI Client Example Shows how to use TokioAI Engine as a drop-in replacement for OpenAI API. Prerequisites: pip install tokioai-engine openai python -m engine serve --model qwen3-coder --port 8080 """ from openai import OpenAI # Connect to TokioAI Engine (same API as OpenAI) client = OpenAI( base_url="http://localhost:8080/v1", api_key="not-needed", # Engine doesn't require auth ) # --- Tool calling --- print("--- Tool Calling ---") response = client.chat.completions.create( model="tokioai-engine", messages=[{"role": "user", "content": "check what processes are using the most memory"}], ) msg = response.choices[0].message if msg.tool_calls: for tc in msg.tool_calls: print(f"Tool: {tc.function.name}") print(f"Arguments: {tc.function.arguments}") else: print(f"Response: {msg.content}") print() # --- Text response --- print("--- Text Response ---") response = client.chat.completions.create( model="tokioai-engine", messages=[{"role": "user", "content": "explain the TCP 3-way handshake in one paragraph"}], ) print(f"Response: {response.choices[0].message.content}") print() # --- Engine metadata --- if hasattr(response, "engine_metadata"): print(f"Intent: {response.engine_metadata['intent']}") print(f"Confidence: {response.engine_metadata['confidence']}") print(f"Latency: {response.engine_metadata['latency_ms']}ms")