1212app = typer .Typer (add_completion = False )
1313
1414
15- def _load_assistant (path : Path ):
15+ def _load_assistant (path : Path , assistant_name : str ):
1616 # Ensure we're working with an absolute path
1717 abs_path = path .absolute ().resolve ()
1818
@@ -35,12 +35,12 @@ def _load_assistant(path: Path):
3535 mod = importlib .util .module_from_spec (spec )
3636 spec .loader .exec_module (mod ) # type: ignore
3737
38- if not hasattr (mod , "assistant" ):
38+ if not hasattr (mod , assistant_name ):
3939 raise typer .BadParameter (
40- f"{ path } must define a global variable `assistant ` "
40+ f"{ path } must define a global variable `{ assistant_name } ` "
4141 f"that is an instance of grafi.assistants.Assistant"
4242 )
43- return mod . assistant
43+ return getattr ( mod , assistant_name )
4444 finally :
4545 # Restore the original sys.path
4646 sys .path = original_sys_path
@@ -51,11 +51,12 @@ def run(
5151 script : Path ,
5252 host : str = "127.0.0.1" ,
5353 port : int = 8080 ,
54+ assistant_name : str = "assistant" ,
5455 open_browser : bool = True ,
5556):
5657 """Run the assistant in *script* and launch the web UI."""
5758 logger .info ("Starting server with %s" , script )
58- assistant = _load_assistant (script )
59+ assistant = _load_assistant (script , assistant_name )
5960 logger .info ("Assistant loaded: %s" , getattr (assistant , "name" , assistant ))
6061
6162 if open_browser :
0 commit comments