Team Ai
Modelpublic

MrMoz33/tokioai-coder-iot

sourceHugging Facemitupdated 7d agoView on Hugging Face
0likes
openai_client.py52 linesDownload Raw Back to examples
1#!/usr/bin/env python32"""3TokioAI Engine -- OpenAI Client Example4 5Shows how to use TokioAI Engine as a drop-in replacement for OpenAI API.6 7Prerequisites:8  pip install tokioai-engine openai9  python -m engine serve --model qwen3-coder --port 808010"""11 12from openai import OpenAI13 14# Connect to TokioAI Engine (same API as OpenAI)15client = OpenAI(16    base_url="http://localhost:8080/v1",17    api_key="not-needed",  # Engine doesn't require auth18)19 20# --- Tool calling ---21print("--- Tool Calling ---")22response = client.chat.completions.create(23    model="tokioai-engine",24    messages=[{"role": "user", "content": "check what processes are using the most memory"}],25)26 27msg = response.choices[0].message28if msg.tool_calls:29    for tc in msg.tool_calls:30        print(f"Tool:      {tc.function.name}")31        print(f"Arguments: {tc.function.arguments}")32else:33    print(f"Response: {msg.content}")34 35print()36 37# --- Text response ---38print("--- Text Response ---")39response = client.chat.completions.create(40    model="tokioai-engine",41    messages=[{"role": "user", "content": "explain the TCP 3-way handshake in one paragraph"}],42)43 44print(f"Response: {response.choices[0].message.content}")45print()46 47# --- Engine metadata ---48if hasattr(response, "engine_metadata"):49    print(f"Intent:     {response.engine_metadata['intent']}")50    print(f"Confidence: {response.engine_metadata['confidence']}")51    print(f"Latency:    {response.engine_metadata['latency_ms']}ms")52