Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1 

2import logging 

3 

4 

5def main(): 

6 # Parse CLI arguments 

7 from askbob.util import make_argument_parser 

8 parser = make_argument_parser() 

9 args = parser.parse_args() 

10 

11 # Parse runtime configuration file values 

12 import configparser 

13 config = configparser.ConfigParser() 

14 

15 if not config.read(args.config): 

16 logging.error( 

17 f"The runtime configuration file {args.config} could not be loaded.") 

18 return False 

19 

20 if args.setup: 

21 # Train and setup the assistant 

22 from .setup import setup 

23 setup(args, config) 

24 else: 

25 if 'Rasa' not in config or 'model' not in config['Rasa']: 

26 logging.error( 

27 "Missing Rasa.model location in the runtime configuration file.") 

28 return False 

29 

30 if args.voice and not args.serve: 

31 logging.error( 

32 "The -v flag must be used in conjunction with the -s flag.") 

33 return False 

34 

35 # Run the voice assistant 

36 from askbob.action.responder import RasaResponseService 

37 responder = RasaResponseService( 

38 config['Rasa']['model'], 

39 config['Plugins'].get('location', 'plugins'), 

40 config['Plugins'].getint('action_server_port', fallback=5055) 

41 ) if 'Plugins' in config else RasaResponseService(config['Rasa']['model']) 

42 

43 if args.serve: 

44 if 'Server' not in config: 

45 logging.error("No server configuration provided.") 

46 return False 

47 

48 # Run Ask Bob in server mode 

49 from .server import serve 

50 serve(responder, config, args.voice) 

51 else: 

52 # Run Ask Bob in interactive mode 

53 from askbob.loop import interactive_loop 

54 import asyncio 

55 asyncio.run(interactive_loop(args, config, responder)) 

56 

57 

58if __name__ == '__main__': 

59 main()