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
1from askbob.server.routes import routes
2from askbob.action.responder import ResponseService
3import logging
4import json as Json
7def make_app(responder: ResponseService, config: dict, voice: bool = False):
8 from sanic import Sanic
10 plugin_configs = Json.load(open(config['Plugins']['summary'],
11 'r')) if 'summary' in config['Plugins'] else []
13 app = Sanic("Ask Bob", configure_logging=False)
15 if config['Server'].get('cors_origins', ''): 15 ↛ 21line 15 didn't jump to line 21, because the condition on line 15 was never false
16 from sanic_cors import CORS
17 CORS(app, resources={
18 r"/*": {"origins": config['Server']['cors_origins']}
19 })
21 routes(app, responder, plugin_configs)
23 if voice: 23 ↛ 27line 23 didn't jump to line 27, because the condition on line 23 was never false
24 from askbob.server.voice import voice_routes
25 voice_routes(app, responder, config)
26 else:
27 from sanic import response
28 @app.route('/voicequery', methods=['POST'])
29 def voice_disabled(request):
30 return response.json({
31 "error": "Voice transcription is disabled on this server."
32 }, status=503)
34 return app
37def serve(responder: ResponseService, config: dict, voice: bool = False):
38 """Services responses to Ask Bob queries and provides information about loaded skills via RESTful endpoints.
40 Args:
41 responder (ResponseService): The response service handling queries.
42 config (dict): The runtime configuration (usually from config.ini).
43 """
44 try:
45 app = make_app(responder, config, voice)
46 except Exception as e:
47 logging.error(f"Failed to start the Ask Bob HTTP server: {str(e)}")
48 return
50 logging.info("Running the Ask Bob HTTP server.")
51 app.run(host=config['Server'].get('host', '0.0.0.0'),
52 port=config['Server'].getint('port', fallback=8000),
53 access_log=False)