Skip to content

Commit

Permalink
Extract agent from request and remove app param
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandre Miguel <aleronupe@gmail.com>
  • Loading branch information
RomuloSouza and aleronupe committed Jan 12, 2021
1 parent ddfd8bd commit 529aeb5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rasa/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ def decorated(*args, **kwargs):
return decorator


def ensure_conversation_exists(app: Sanic) -> Callable[..., HTTPResponse]:
def ensure_conversation_exists() -> Callable[..., HTTPResponse]:
"""Wraps a request handler ensuring the conversation exists.
"""

def decorator(f: Callable[..., HTTPResponse]) -> HTTPResponse:
@wraps(f)
def decorated(*args: Any, **kwargs: Any) -> HTTPResponse:
def decorated(request: Request, *args: Any, **kwargs: Any) -> HTTPResponse:
conversation_id = kwargs["conversation_id"]
if app.agent.tracker_store.exists(conversation_id):
return f(*args, **kwargs)
if request.app.agent.tracker_store.exists(conversation_id):
return f(request, *args, **kwargs)
else:
raise ErrorResponse(
HTTPStatus.NOT_FOUND, "Not found", "Conversation ID not found."
Expand Down Expand Up @@ -811,7 +811,7 @@ async def replace_events(request: Request, conversation_id: Text):
@app.get("/conversations/<conversation_id:path>/story")
@requires_auth(app, auth_token)
@ensure_loaded_agent(app)
@ensure_conversation_exists(app)
@ensure_conversation_exists()
async def retrieve_story(request: Request, conversation_id: Text):
"""Get an end-to-end story corresponding to this conversation."""
until_time = rasa.utils.endpoints.float_arg(request, "until")
Expand All @@ -838,7 +838,7 @@ async def retrieve_story(request: Request, conversation_id: Text):
@app.post("/conversations/<conversation_id:path>/execute")
@requires_auth(app, auth_token)
@ensure_loaded_agent(app)
@ensure_conversation_exists(app)
@ensure_conversation_exists()
async def execute_action(request: Request, conversation_id: Text):
request_params = request.json

Expand Down Expand Up @@ -947,7 +947,7 @@ async def trigger_intent(request: Request, conversation_id: Text) -> HTTPRespons
@app.post("/conversations/<conversation_id:path>/predict")
@requires_auth(app, auth_token)
@ensure_loaded_agent(app)
@ensure_conversation_exists(app)
@ensure_conversation_exists()
async def predict(request: Request, conversation_id: Text) -> HTTPResponse:
try:
# Fetches the appropriate bot response in a json format
Expand Down

0 comments on commit 529aeb5

Please sign in to comment.