From ec248efd3144663fbcd7e181ce140a517c41cd7d Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 9 Oct 2024 19:01:34 -0700 Subject: [PATCH] Allow iterative chat director to do notes search --- src/khoj/routers/api.py | 7 ++--- src/khoj/routers/api_chat.py | 60 ++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index d26b7b5a..11ab1112 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -355,10 +355,9 @@ async def extract_references_and_questions( agent_has_entries = await sync_to_async(EntryAdapters.agent_has_entries)(agent=agent) if ( - # not ConversationCommand.Notes in conversation_commands - # and not ConversationCommand.Default in conversation_commands - # and not agent_has_entries - True + not ConversationCommand.Notes in conversation_commands + and not ConversationCommand.Default in conversation_commands + and not agent_has_entries ): yield compiled_references, inferred_queries, q return diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 505c0248..89b56a29 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -853,37 +853,37 @@ async def chat( yield result return - # Gather Context - async for result in extract_references_and_questions( - request, - meta_log, - q, - (n or 7), - d, - conversation_id, - conversation_commands, - location, - partial(send_event, ChatEvent.STATUS), - uploaded_image_url=uploaded_image_url, - agent=agent, - ): - if isinstance(result, dict) and ChatEvent.STATUS in result: - yield result[ChatEvent.STATUS] - else: - compiled_references.extend(result[0]) - inferred_queries.extend(result[1]) - defiltered_query = result[2] + # # Gather Context + # async for result in extract_references_and_questions( + # request, + # meta_log, + # q, + # (n or 7), + # d, + # conversation_id, + # conversation_commands, + # location, + # partial(send_event, ChatEvent.STATUS), + # uploaded_image_url=uploaded_image_url, + # agent=agent, + # ): + # if isinstance(result, dict) and ChatEvent.STATUS in result: + # yield result[ChatEvent.STATUS] + # else: + # compiled_references.extend(result[0]) + # inferred_queries.extend(result[1]) + # defiltered_query = result[2] - if not is_none_or_empty(compiled_references): - try: - headings = "\n- " + "\n- ".join(set([c.get("compiled", c).split("\n")[0] for c in compiled_references])) - # Strip only leading # from headings - headings = headings.replace("#", "") - async for result in send_event(ChatEvent.STATUS, f"**Found Relevant Notes**: {headings}"): - yield result - except Exception as e: - # TODO Get correct type for compiled across research notes extraction - logger.error(f"Error extracting references: {e}", exc_info=True) + # if not is_none_or_empty(compiled_references): + # try: + # headings = "\n- " + "\n- ".join(set([c.get("compiled", c).split("\n")[0] for c in compiled_references])) + # # Strip only leading # from headings + # headings = headings.replace("#", "") + # async for result in send_event(ChatEvent.STATUS, f"**Found Relevant Notes**: {headings}"): + # yield result + # except Exception as e: + # # TODO Get correct type for compiled across research notes extraction + # logger.error(f"Error extracting references: {e}", exc_info=True) if conversation_commands == [ConversationCommand.Notes] and not await EntryAdapters.auser_has_entries(user): async for result in send_llm_response(f"{no_entries_found.format()}"):