mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Allow user to chat with agent knowledge base if general mode
This commit is contained in:
@@ -349,15 +349,27 @@ async def extract_references_and_questions(
|
|||||||
compiled_references: List[Any] = []
|
compiled_references: List[Any] = []
|
||||||
inferred_queries: List[str] = []
|
inferred_queries: List[str] = []
|
||||||
|
|
||||||
|
agent_has_entries = False
|
||||||
|
|
||||||
|
if agent:
|
||||||
|
agent_has_entries = await sync_to_async(EntryAdapters.agent_has_entries)(agent=agent)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not ConversationCommand.Notes in conversation_commands
|
not ConversationCommand.Notes in conversation_commands
|
||||||
and not ConversationCommand.Default in conversation_commands
|
and not ConversationCommand.Default in conversation_commands
|
||||||
|
and not agent_has_entries
|
||||||
):
|
):
|
||||||
yield compiled_references, inferred_queries, q
|
yield compiled_references, inferred_queries, q
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# If Notes or Default is not in the conversation command, then the search should be restricted to the agent's knowledge base
|
||||||
|
should_limit_to_agent_knowledge = (
|
||||||
|
ConversationCommand.Notes not in conversation_commands
|
||||||
|
and ConversationCommand.Default not in conversation_commands
|
||||||
|
)
|
||||||
|
|
||||||
if not await sync_to_async(EntryAdapters.user_has_entries)(user=user):
|
if not await sync_to_async(EntryAdapters.user_has_entries)(user=user):
|
||||||
if not await sync_to_async(EntryAdapters.agent_has_entries)(agent=agent):
|
if not agent_has_entries:
|
||||||
logger.debug("No documents in knowledge base. Use a Khoj client to sync and chat with your docs.")
|
logger.debug("No documents in knowledge base. Use a Khoj client to sync and chat with your docs.")
|
||||||
yield compiled_references, inferred_queries, q
|
yield compiled_references, inferred_queries, q
|
||||||
return
|
return
|
||||||
@@ -461,7 +473,7 @@ async def extract_references_and_questions(
|
|||||||
n_items = min(n, 3) if using_offline_chat else n
|
n_items = min(n, 3) if using_offline_chat else n
|
||||||
search_results.extend(
|
search_results.extend(
|
||||||
await execute_search(
|
await execute_search(
|
||||||
user,
|
user if not should_limit_to_agent_knowledge else None,
|
||||||
f"{query} {filters_in_query}",
|
f"{query} {filters_in_query}",
|
||||||
n=n_items,
|
n=n_items,
|
||||||
t=SearchType.All,
|
t=SearchType.All,
|
||||||
|
|||||||
Reference in New Issue
Block a user