File size: 1,466 Bytes
4b97c3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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")