File size: 2,128 Bytes
d5b2300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Measure whether the local model is usable on this machine.

The agent makes two model calls per conversational turn (intent parse, then
response generation), so per-turn latency is roughly the sum of the two. Run:

    uv run scripts/benchmark_model.py
"""

import time

from flight_agent.config import MODEL_NAME
from flight_agent.llm import LocalQwen

PROMPTS = [
    "Find flights from JFK to LAX on 2026-09-15",
    "Show my bookings",
    "Remember that my home airport is Boston",
]

CONTEXT = {
    "flight_results": [
        {"id": "F000101", "origin": "JFK", "destination": "LAX",
         "departure_date": "2026-09-15", "departure_time": "08:20",
         "arrival_time": "11:25", "base_price": 149.0},
    ],
    "preferences": {"home_airport": "BOS"},
    "intent": {"intent": "search_flights"},
}


def main() -> None:
    print(f"Model: {MODEL_NAME}")
    t0 = time.perf_counter()
    llm = LocalQwen()
    load_s = time.perf_counter() - t0
    print(f"Load: {load_s:.1f}s\n")

    tok = llm.tokenizer
    intent_times = []

    print("--- intent parsing ---")
    for prompt in PROMPTS:
        t0 = time.perf_counter()
        intent = llm.parse_intent(prompt)
        dt = time.perf_counter() - t0
        intent_times.append(dt)
        print(f"  {dt:6.1f}s  {prompt!r}")
        print(f"           -> {intent.intent} "
              f"{intent.origin or ''}->{intent.destination or ''} {intent.date or ''}")

    print("\n--- response generation ---")
    t0 = time.perf_counter()
    text = llm.respond(CONTEXT)
    respond_s = time.perf_counter() - t0
    n_tokens = len(tok(text)["input_ids"])
    print(f"  {respond_s:.1f}s for {n_tokens} tokens "
          f"({n_tokens / respond_s:.1f} tok/s)")
    print(f"  {text[:400]!r}")

    avg_intent = sum(intent_times) / len(intent_times)
    print("\n--- summary ---")
    print(f"  model load          {load_s:6.1f}s (once per process)")
    print(f"  intent parse (avg)  {avg_intent:6.1f}s")
    print(f"  response generate   {respond_s:6.1f}s")
    print(f"  => per chat turn    {avg_intent + respond_s:6.1f}s")


if __name__ == "__main__":
    main()