From 64cb796cb530c9f4626bd7b2c2b62dbadf1fccdb Mon Sep 17 00:00:00 2001 From: Georgijs <48869301+gvilums@users.noreply.github.com> Date: Wed, 1 Nov 2023 17:05:11 +0100 Subject: [PATCH] In SID tool, fall back to normal search if no results are available (#1342) * fix: fall back from sid to google search on empty result * fix: add missing await * Update platform/reworkd_platform/web/api/agent/tools/sidsearch.py Co-authored-by: Adam Watkins --------- Co-authored-by: Adam Watkins --- next/src/components/dialog/ToolsDialog.tsx | 4 +-- .../web/api/agent/tools/sidsearch.py | 36 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/next/src/components/dialog/ToolsDialog.tsx b/next/src/components/dialog/ToolsDialog.tsx index 5d2c241319..edd75833cd 100644 --- a/next/src/components/dialog/ToolsDialog.tsx +++ b/next/src/components/dialog/ToolsDialog.tsx @@ -88,7 +88,6 @@ const SidTool = ({ tool, onChange }: ToolProps) => {

{tool.name}

{tool.description}

-
{sid.connected && ( <> @@ -98,8 +97,9 @@ const SidTool = ({ tool, onChange }: ToolProps) => { > Disconnect - + )} + onChange(tool.name, !tool.active)} diff --git a/platform/reworkd_platform/web/api/agent/tools/sidsearch.py b/platform/reworkd_platform/web/api/agent/tools/sidsearch.py index 19d20bbca9..e99453cd77 100644 --- a/platform/reworkd_platform/web/api/agent/tools/sidsearch.py +++ b/platform/reworkd_platform/web/api/agent/tools/sidsearch.py @@ -15,6 +15,8 @@ from reworkd_platform.web.api.agent.tools.tool import Tool from reworkd_platform.web.api.agent.tools.utils import Snippet, summarize_sid +from reworkd_platform.web.api.agent.tools.search import Search + async def _sid_search_results( search_term: str, limit: int, token: str @@ -90,27 +92,25 @@ async def dynamic_available(user: UserBase, oauth_crud: OAuthCrud) -> bool: return bool(installation and installation.access_token_enc) - async def call( + async def _run_sid( self, goal: str, task: str, input_str: str, user: UserBase, oauth_crud: OAuthCrud, - *args: Any, - **kwargs: Any, - ) -> FastAPIStreamingResponse: + ) -> Optional[FastAPIStreamingResponse]: installation = await oauth_crud.get_installation_by_user_id( user_id=user.id, provider="sid" ) - # if the tool is called, the installation should be available. However, it is possible that it is - # disconnected in the meantime. In that case, we pretend as if no information is found. if not installation: - return stream_string("Unable to fetch SID results", True) + logger.warning("No sid installation found for user {user.id}") + return None token = await get_access_token(oauth_crud, installation) if not token: - return stream_string("Unable to fetch SID results", True) + logger.warning("Unable to fetch sid access token for {user.id}") + return None try: res = await _sid_search_results(input_str, limit=10, token=token) @@ -119,9 +119,25 @@ async def call( ] except Exception as e: logger.exception(e) - return stream_string("Unable to fetch SID results", True) + return None if not snippets: - return stream_string("No good results found by SID", True) + return None return summarize_sid(self.model, self.language, goal, task, snippets) + + + async def call( + self, + goal: str, + task: str, + input_str: str, + user: UserBase, + oauth_crud: OAuthCrud, + *args: Any, + **kwargs: Any, + ) -> FastAPIStreamingResponse: + # fall back to search if no results are found + return await self._run_sid(goal, task, input_str, user, oauth_crud) or await Search(self.model, self.language).call( + goal, task, input_str, user, oauth_crud + )