From 033febe8e9bfe0b248959118156e7b564d81d8bd Mon Sep 17 00:00:00 2001 From: "luca.gobbi" Date: Thu, 3 Oct 2024 08:24:09 +0200 Subject: [PATCH] run stray in threadpool to allow tool execution on http message endpoint --- core/cat/routes/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/cat/routes/base.py b/core/cat/routes/base.py index d9d021e5..fae243c6 100644 --- a/core/cat/routes/base.py +++ b/core/cat/routes/base.py @@ -1,4 +1,5 @@ from fastapi import APIRouter, Depends, Body +from fastapi.concurrency import run_in_threadpool from typing import Dict import tomli from cat.auth.permissions import AuthPermission, AuthResource @@ -27,5 +28,11 @@ async def message_with_cat( stray=Depends(HTTPAuth(AuthResource.CONVERSATION, AuthPermission.WRITE)), ) -> Dict: """Get a response from the Cat""" - answer = await stray({"user_id": stray.user_id, **payload}) + answer = await run_in_threadpool(stray_run, stray, {"user_id": stray.user_id, **payload}) return answer + + +def stray_run(stray, user_message_json): + cat_message = stray.loop.run_until_complete(stray(user_message_json)) + return cat_message +