Allow iterative chat director to do notes search

This commit is contained in:
Debanjum Singh Solanky
2024-10-09 19:01:34 -07:00
parent a6905a9f0c
commit ec248efd31
2 changed files with 33 additions and 34 deletions

View File

@@ -355,10 +355,9 @@ async def extract_references_and_questions(
agent_has_entries = await sync_to_async(EntryAdapters.agent_has_entries)(agent=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 and not agent_has_entries
True
): ):
yield compiled_references, inferred_queries, q yield compiled_references, inferred_queries, q
return return

View File

@@ -853,37 +853,37 @@ async def chat(
yield result yield result
return return
# Gather Context # # Gather Context
async for result in extract_references_and_questions( # async for result in extract_references_and_questions(
request, # request,
meta_log, # meta_log,
q, # q,
(n or 7), # (n or 7),
d, # d,
conversation_id, # conversation_id,
conversation_commands, # conversation_commands,
location, # location,
partial(send_event, ChatEvent.STATUS), # partial(send_event, ChatEvent.STATUS),
uploaded_image_url=uploaded_image_url, # uploaded_image_url=uploaded_image_url,
agent=agent, # agent=agent,
): # ):
if isinstance(result, dict) and ChatEvent.STATUS in result: # if isinstance(result, dict) and ChatEvent.STATUS in result:
yield result[ChatEvent.STATUS] # yield result[ChatEvent.STATUS]
else: # else:
compiled_references.extend(result[0]) # compiled_references.extend(result[0])
inferred_queries.extend(result[1]) # inferred_queries.extend(result[1])
defiltered_query = result[2] # defiltered_query = result[2]
if not is_none_or_empty(compiled_references): # if not is_none_or_empty(compiled_references):
try: # try:
headings = "\n- " + "\n- ".join(set([c.get("compiled", c).split("\n")[0] for c in compiled_references])) # headings = "\n- " + "\n- ".join(set([c.get("compiled", c).split("\n")[0] for c in compiled_references]))
# Strip only leading # from headings # # Strip only leading # from headings
headings = headings.replace("#", "") # headings = headings.replace("#", "")
async for result in send_event(ChatEvent.STATUS, f"**Found Relevant Notes**: {headings}"): # async for result in send_event(ChatEvent.STATUS, f"**Found Relevant Notes**: {headings}"):
yield result # yield result
except Exception as e: # except Exception as e:
# TODO Get correct type for compiled across research notes extraction # # TODO Get correct type for compiled across research notes extraction
logger.error(f"Error extracting references: {e}", exc_info=True) # logger.error(f"Error extracting references: {e}", exc_info=True)
if conversation_commands == [ConversationCommand.Notes] and not await EntryAdapters.auser_has_entries(user): 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()}"): async for result in send_llm_response(f"{no_entries_found.format()}"):