Skip to content

Commit

Permalink
run stray in threadpool to allow tool execution on http message endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
luca.gobbi committed Oct 3, 2024
1 parent aa0efc6 commit 033febe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/cat/routes/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 033febe

Please sign in to comment.