3131# ///
3232from contextlib import contextmanager
3333from pathlib import Path
34- from pathlib import Path
3534import re
3635from statistics import mean , median
37- from typing import Annotated , List , Optional
38- from typing import Dict , List , Tuple , Set , Any
36+ from typing import Annotated , Dict , List , Optional , Tuple
3937import atexit
4038import json
4139import logging
4947import typer
5048
5149sys .path .insert (0 , Path (__file__ ).parent .parent .as_posix ())
52- print ( sys . path )
53- from examples .server .tests .utils import ServerProcess
54- from examples .server .tests .unit .test_tool_call import TIMEOUT_SERVER_START , do_test_calc_result , do_test_hello_world , do_test_weather
50+ if True :
51+ from examples .server .tests .utils import ServerProcess # type: ignore
52+ from examples .server .tests .unit .test_tool_call import TIMEOUT_SERVER_START , do_test_calc_result , do_test_hello_world , do_test_weather # type: ignore
5553
5654
5755@contextmanager
@@ -74,6 +72,7 @@ def stop():
7472
7573app = typer .Typer ()
7674
75+
7776@app .command ()
7877def plot (files : List [Path ], output : Optional [Path ] = None , test_regex : Optional [str ] = None , server_regex : Optional [str ] = None ):
7978
@@ -146,15 +145,13 @@ def plot(files: List[Path], output: Optional[Path] = None, test_regex: Optional[
146145 tests = list (sorted (tests ))
147146 server_names = list (sorted (server_names ))
148147
149-
150148 logger .info (f"Processed { len (lines )} lines" )
151149 logger .info (f"Found { len (data_dict )} valid data points" )
152150 logger .info (f"Models: { models } " )
153151 logger .info (f"Temperatures: { temps } " )
154152 logger .info (f"Tests: { tests } " )
155153 logger .info (f"Servers: { server_names } " )
156154
157-
158155 matrix = []
159156 index = []
160157
@@ -198,6 +195,7 @@ def plot(files: List[Path], output: Optional[Path] = None, test_regex: Optional[
198195 else :
199196 plt .show ()
200197
198+
201199@app .command ()
202200def run (
203201 output : Annotated [Path , typer .Option (help = "Output JSON file" )],
@@ -259,8 +257,10 @@ def run(server: ServerProcess, *, server_name: str, model_id: str, temp: float |
259257 print (f"Running { test_name } ({ server_name } , { model } ): " , file = sys .stderr , flush = True )
260258 for i in range (n ):
261259 start_time = time .time ()
260+
262261 def elapsed ():
263262 return time .time () - start_time
263+
264264 try :
265265 test (server )
266266 success_times .append (elapsed ())
@@ -273,6 +273,8 @@ def elapsed():
273273 failure_count += 1
274274 failure_times .append (elapsed ())
275275 failures .append (str (e ))
276+ # import traceback
277+ # traceback.print_exc()
276278 print ('\n ' , file = sys .stderr , flush = True )
277279 output_file .write (json .dumps ({** output_kwargs , ** dict (
278280 model = model ,
@@ -352,5 +354,6 @@ def elapsed():
352354 ),
353355 )
354356
357+
355358if __name__ == "__main__" :
356- app ()
359+ app ()
0 commit comments