@@ -0,0 +1,126 @@ |
| | 1 | +--- |
| | 2 | +dlm_id: 01KQ7XKG7AZ1VGFD2836YHK01V |
| | 3 | +dlm_version: 1 |
| | 4 | +base_model: qwen2.5-coder-1.5b |
| | 5 | +system_prompt: | |
| | 6 | + You are a tool-using assistant. When the user asks for an action that |
| | 7 | + matches one of your available tools, respond with ONLY a single JSON |
| | 8 | + object of the form {"name": "<tool_name>", "arguments": { ... }}. |
| | 9 | + Do not add prose, code fences, or explanations — just the JSON. |
| | 10 | +training: |
| | 11 | + adapter: lora |
| | 12 | + lora_r: 16 |
| | 13 | + lora_alpha: 32 |
| | 14 | + lora_dropout: 0.05 |
| | 15 | + sequence_len: 1024 |
| | 16 | + learning_rate: 2e-4 |
| | 17 | + num_epochs: 3 |
| | 18 | + seed: 42 |
| | 19 | +export: |
| | 20 | + default_quant: Q4_K_M |
| | 21 | + default_temperature: 0.0 |
| | 22 | +--- |
| | 23 | + |
| | 24 | +# Tool-using assistant starter |
| | 25 | + |
| | 26 | +Trains an adapter that always answers tool requests with a strict JSON |
| | 27 | +function-call object — never prose, never markdown. Pair the resulting |
| | 28 | +adapter with sway's `tool_use_fidelity` probe (see the linked sway |
| | 29 | +spec at the end) to measure JSON-schema validity, argument drift, and |
| | 30 | +tool-name hallucination after training. |
| | 31 | + |
| | 32 | +The Q&A blocks below cover the eight tool shapes sway's bundled |
| | 33 | +`tool_use_cases.yaml` fixture exercises: search, file I/O, code |
| | 34 | +execution, shell, HTTP, DB, calendar, and calculator. Replace or |
| | 35 | +extend with the real tool surface your application exposes. |
| | 36 | + |
| | 37 | +::instruction:: |
| | 38 | +### Q |
| | 39 | +Search the web for the largest known prime number. Use the `search_web` tool. |
| | 40 | + |
| | 41 | +### A |
| | 42 | +{"name": "search_web", "arguments": {"query": "largest known prime number"}} |
| | 43 | + |
| | 44 | +### Q |
| | 45 | +Look up recent earthquakes in Japan. Use `search_web` with `max_results=5`. |
| | 46 | + |
| | 47 | +### A |
| | 48 | +{"name": "search_web", "arguments": {"query": "recent earthquakes Japan", "max_results": 5}} |
| | 49 | + |
| | 50 | +### Q |
| | 51 | +Read the contents of /etc/hosts. Use the `read_file` tool. |
| | 52 | + |
| | 53 | +### A |
| | 54 | +{"name": "read_file", "arguments": {"path": "/etc/hosts"}} |
| | 55 | + |
| | 56 | +### Q |
| | 57 | +Read /var/log/syslog as UTF-8. Use the `read_file` tool. |
| | 58 | + |
| | 59 | +### A |
| | 60 | +{"name": "read_file", "arguments": {"path": "/var/log/syslog", "encoding": "utf-8"}} |
| | 61 | + |
| | 62 | +### Q |
| | 63 | +Compute the factorial of 7 using Python. Use the `run_python` tool. |
| | 64 | + |
| | 65 | +### A |
| | 66 | +{"name": "run_python", "arguments": {"code": "import math; print(math.factorial(7))"}} |
| | 67 | + |
| | 68 | +### Q |
| | 69 | +List files in /tmp using a shell command. Use the `run_shell` tool. |
| | 70 | + |
| | 71 | +### A |
| | 72 | +{"name": "run_shell", "arguments": {"command": "ls -la /tmp"}} |
| | 73 | + |
| | 74 | +### Q |
| | 75 | +GET https://example.com/health. Use the `http_fetch` tool. |
| | 76 | + |
| | 77 | +### A |
| | 78 | +{"name": "http_fetch", "arguments": {"url": "https://example.com/health"}} |
| | 79 | + |
| | 80 | +### Q |
| | 81 | +GET https://api.example.com/v1/users with an Authorization header. Use the `http_fetch` tool. |
| | 82 | + |
| | 83 | +### A |
| | 84 | +{"name": "http_fetch", "arguments": {"url": "https://api.example.com/v1/users", "headers": {"Authorization": "Bearer TOKEN"}}} |
| | 85 | + |
| | 86 | +### Q |
| | 87 | +Fetch the user with id=5 from the database. Use the `db_query` tool. |
| | 88 | + |
| | 89 | +### A |
| | 90 | +{"name": "db_query", "arguments": {"sql": "SELECT * FROM users WHERE id = ?", "params": [5]}} |
| | 91 | + |
| | 92 | +### Q |
| | 93 | +Add a calendar event for a sync at 2pm tomorrow titled "Sync". Use `calendar_create_event`. |
| | 94 | + |
| | 95 | +### A |
| | 96 | +{"name": "calendar_create_event", "arguments": {"title": "Sync", "start_iso": "2026-04-28T14:00:00", "duration_minutes": 30}} |
| | 97 | + |
| | 98 | +### Q |
| | 99 | +Compute 137 * 42 with the `calculator` tool. |
| | 100 | + |
| | 101 | +### A |
| | 102 | +{"name": "calculator", "arguments": {"expression": "137 * 42"}} |
| | 103 | + |
| | 104 | +### Q |
| | 105 | +Compute the area of a circle with radius 5 using the `calculator` tool. |
| | 106 | + |
| | 107 | +### A |
| | 108 | +{"name": "calculator", "arguments": {"expression": "3.14159 * 5 * 5"}} |
| | 109 | +::end:: |
| | 110 | + |
| | 111 | +# Sway evaluation |
| | 112 | + |
| | 113 | +After `dlm train` produces an adapter, evaluate tool-call preservation |
| | 114 | +with sway: |
| | 115 | + |
| | 116 | +```bash |
| | 117 | +# install dlm with the sway extra; sway resolves the adapter from the .dlm |
| | 118 | +pip install 'dlm[sway]' |
| | 119 | +sway autogen tool-use-example.dlm -o sway.yaml |
| | 120 | +sway run sway.yaml |
| | 121 | +``` |
| | 122 | + |
| | 123 | +The autogenerated suite includes `tool_use_fidelity` cases derived |
| | 124 | +from this document's INSTRUCTION blocks. Look for the probe row in |
| | 125 | +the sway report — a healthy adapter scores `validity_delta ≥ 0` and |
| | 126 | +`hallucination_rate < 10%` against the tools above. |