File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from flask import Blueprint , request , jsonify
1+ import fastapi
22
3- from semra .web .autocomplete import ConceptsTrie
3+ from semra .web .autocomplete import ConceptsTrie , Entry
44
5- auto_blueprint = Blueprint ( "autocomplete" , __name__ , url_prefix = "/autocomplete" )
5+ auto_router = fastapi . APIRouter ( prefix = "/autocomplete" )
66
77
88# Initialize the autocomplete trie
99trie = ConceptsTrie .from_graph_db ()
1010
1111
12- @auto_blueprint . route ("/search" , methods = [ "GET" ])
13- def autocomplete_search ():
12+ @auto_router . get ("/search" , response_model = list [ Entry ])
13+ def autocomplete_search (prefix : str , top_n : int = 100 ):
1414 """Get the autocomplete suggestions for a given prefix."""
15- prefix = request .args .get ("prefix" )
16- top_n = min (int (request .args .get ("top_n" , 100 )), 100 )
17-
18- return jsonify (
19- trie .case_insensitive_search (prefix , top_n = top_n )
20- )
15+ top_n = min (top_n , 100 )
16+ return trie .case_insensitive_search (prefix , top_n = top_n )
Original file line number Diff line number Diff line change @@ -79,17 +79,16 @@ def get_app(
7979 Bootstrap5 (flask_app )
8080
8181 flask_app .register_blueprint (flask_blueprint )
82- if add_autocomplete :
83- from semra .web .autocomplete .autocomplete_blueprint import auto_blueprint
84-
85- flask_app .register_blueprint (auto_blueprint )
8682
8783 fastapi_app = fastapi .FastAPI (
8884 title = "Semantic Reasoning Assembler" ,
8985 description = "A web app to access a SeMRA Neo4j database" ,
9086 )
9187 fastapi_app .state = state # type:ignore
9288 fastapi_app .include_router (api_router )
89+ if add_autocomplete :
90+ from semra .web .autocomplete .autocomplete_blueprint import auto_router
91+ fastapi_app .include_router (auto_router )
9392 fastapi_app .mount ("/" , WSGIMiddleware (flask_app ))
9493
9594 if return_flask :
You can’t perform that action at this time.
0 commit comments