mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Fix input/output mismatches in the /summarize command
This commit is contained in:
parent
e4285941d1
commit
9e8ac7f89e
3 changed files with 8 additions and 6 deletions
|
@ -1480,7 +1480,9 @@ class EntryAdapters:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def aget_agent_entry_filepaths(agent: Agent):
|
async def aget_agent_entry_filepaths(agent: Agent):
|
||||||
return await sync_to_async(list)(Entry.objects.filter(agent=agent).values_list("file_path", flat=True))
|
return await sync_to_async(set)(
|
||||||
|
Entry.objects.filter(agent=agent).distinct("file_path").values_list("file_path", flat=True)
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_filenames_by_source(user: KhojUser, file_source: str):
|
def get_all_filenames_by_source(user: KhojUser, file_source: str):
|
||||||
|
|
|
@ -792,9 +792,10 @@ async def chat(
|
||||||
tracer=tracer,
|
tracer=tracer,
|
||||||
):
|
):
|
||||||
if isinstance(response, dict) and ChatEvent.STATUS in response:
|
if isinstance(response, dict) and ChatEvent.STATUS in response:
|
||||||
yield result[ChatEvent.STATUS]
|
yield response[ChatEvent.STATUS]
|
||||||
else:
|
else:
|
||||||
if isinstance(response, str):
|
if isinstance(response, str):
|
||||||
|
response_log = response
|
||||||
async for result in send_llm_response(response):
|
async for result in send_llm_response(response):
|
||||||
yield result
|
yield result
|
||||||
|
|
||||||
|
|
|
@ -650,7 +650,7 @@ async def generate_summary_from_files(
|
||||||
if await EntryAdapters.aagent_has_entries(agent):
|
if await EntryAdapters.aagent_has_entries(agent):
|
||||||
file_names = await EntryAdapters.aget_agent_entry_filepaths(agent)
|
file_names = await EntryAdapters.aget_agent_entry_filepaths(agent)
|
||||||
if len(file_names) > 0:
|
if len(file_names) > 0:
|
||||||
file_object = await FileObjectAdapters.async_get_file_objects_by_name(None, file_names[0], agent)
|
file_object = await FileObjectAdapters.async_get_file_objects_by_name(None, file_names.pop(), agent)
|
||||||
|
|
||||||
if len(file_filters) > 0:
|
if len(file_filters) > 0:
|
||||||
file_object = await FileObjectAdapters.async_get_file_objects_by_name(user, file_filters[0])
|
file_object = await FileObjectAdapters.async_get_file_objects_by_name(user, file_filters[0])
|
||||||
|
@ -663,7 +663,7 @@ async def generate_summary_from_files(
|
||||||
if not q:
|
if not q:
|
||||||
q = "Create a general summary of the file"
|
q = "Create a general summary of the file"
|
||||||
async for result in send_status_func(f"**Constructing Summary Using:** {file_object[0].file_name}"):
|
async for result in send_status_func(f"**Constructing Summary Using:** {file_object[0].file_name}"):
|
||||||
yield result
|
yield {ChatEvent.STATUS: result}
|
||||||
|
|
||||||
response = await extract_relevant_summary(
|
response = await extract_relevant_summary(
|
||||||
q,
|
q,
|
||||||
|
@ -674,9 +674,8 @@ async def generate_summary_from_files(
|
||||||
agent=agent,
|
agent=agent,
|
||||||
tracer=tracer,
|
tracer=tracer,
|
||||||
)
|
)
|
||||||
response_log = str(response)
|
|
||||||
|
|
||||||
yield result
|
yield str(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response_log = "Error summarizing file. Please try again, or contact support."
|
response_log = "Error summarizing file. Please try again, or contact support."
|
||||||
logger.error(f"Error summarizing file for {user.email}: {e}", exc_info=True)
|
logger.error(f"Error summarizing file for {user.email}: {e}", exc_info=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue