Team Ai
Modelpublic

MrMoz33/tokioai-coder-iot

sourceHugging Facemitupdated 5d agoView on Hugging Face
0likes
basic_usage.py73 linesDownload Raw Back to examples
1#!/usr/bin/env python32"""3TokioAI Engine -- Basic Usage Example4 5Prerequisites:6  pip install tokioai-engine7  ollama serve &8  ollama pull qwen3-coder9"""10 11from engine.pipeline import Pipeline, EngineConfig12 13# Create engine with default config (connects to local Ollama)14config = EngineConfig(15    model_name="qwen3-coder",          # Any Ollama model16    ollama_host="http://localhost:11434",17    max_retries=2,                      # Retry on bad output18    use_guided_gen=True,                # Force valid JSON for tool calls19    use_memory=True,                    # Learn from successful interactions20    verbose=True,                       # Show engine internals21)22 23engine = Pipeline(config)24 25# --- Tool Call Example ---26print("=" * 60)27print("TOOL CALL: 'check disk space'")28print("=" * 60)29 30result = engine.process("check disk space")31print(f"Intent:  {result.intent}")32print(f"Type:    {result.output_type}")33print(f"Calls:   {result.tool_calls}")34print(f"Latency: {result.latency_ms}ms")35print(f"Retries: {result.attempts}")36print()37 38# --- Text Response Example ---39print("=" * 60)40print("TEXT: 'what is SQL injection'")41print("=" * 60)42 43engine.reset()44result = engine.process("what is SQL injection")45print(f"Intent:  {result.intent}")46print(f"Type:    {result.output_type}")47print(f"Text:    {result.text[:200]}")48print(f"Latency: {result.latency_ms}ms")49print()50 51# --- Decision Example ---52print("=" * 60)53print("DECISION: 'is docker running'")54print("=" * 60)55 56engine.reset()57result = engine.process("is docker running")58print(f"Intent:  {result.intent}")59print(f"Type:    {result.output_type}")60if result.tool_calls:61    print(f"Calls:   {result.tool_calls}")62else:63    print(f"Text:    {result.text[:200]}")64print(f"Latency: {result.latency_ms}ms")65print()66 67# --- Stats ---68print("=" * 60)69print("ENGINE STATS")70print("=" * 60)71import json72print(json.dumps(engine.get_stats(), indent=2))73