mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Simplify in research mode check in api_chat.
- Dedent code for readability - Use better name for in research mode check - Continue to remove inferred summarize command when multiple files in file filter even when not in research mode - Continue to show select information source train of thought. It was removed by mistake earlier
This commit is contained in:
parent
73750ef286
commit
0b0cfb35e6
1 changed files with 97 additions and 99 deletions
|
@ -693,7 +693,7 @@ async def chat(
|
|||
meta_log = conversation.conversation_log
|
||||
is_automated_task = conversation_commands == [ConversationCommand.AutomatedTask]
|
||||
|
||||
pending_research = True
|
||||
in_research_mode = False
|
||||
researched_results = ""
|
||||
online_results: Dict = dict()
|
||||
code_results: Dict = dict()
|
||||
|
@ -712,6 +712,11 @@ async def chat(
|
|||
agent=agent,
|
||||
tracer=tracer,
|
||||
)
|
||||
conversation_commands_str = ", ".join([cmd.value for cmd in conversation_commands])
|
||||
async for result in send_event(
|
||||
ChatEvent.STATUS, f"**Chose Data Sources to Search:** {conversation_commands_str}"
|
||||
):
|
||||
yield result
|
||||
|
||||
mode = await aget_relevant_output_modes(
|
||||
q, meta_log, is_automated_task, user, uploaded_images, agent, tracer=tracer
|
||||
|
@ -738,7 +743,7 @@ async def chat(
|
|||
):
|
||||
if isinstance(research_result, InformationCollectionIteration):
|
||||
if research_result.summarizedResult:
|
||||
pending_research = False
|
||||
in_research_mode = True
|
||||
if research_result.onlineContext:
|
||||
online_results.update(research_result.onlineContext)
|
||||
if research_result.codeContext:
|
||||
|
@ -752,11 +757,9 @@ async def chat(
|
|||
yield research_result
|
||||
|
||||
# researched_results = await extract_relevant_info(q, researched_results, agent)
|
||||
|
||||
in_research_mode = False
|
||||
logger.info(f"Researched Results: {researched_results}")
|
||||
|
||||
pending_research = False
|
||||
|
||||
for cmd in conversation_commands:
|
||||
await conversation_command_rate_limiter.update_and_check_if_valid(request, cmd)
|
||||
q = q.replace(f"/{cmd.value}", "").strip()
|
||||
|
@ -771,11 +774,9 @@ async def chat(
|
|||
and not used_slash_summarize
|
||||
# but we can't actually summarize
|
||||
and len(file_filters) != 1
|
||||
# not pending research
|
||||
and not pending_research
|
||||
):
|
||||
conversation_commands.remove(ConversationCommand.Summarize)
|
||||
elif ConversationCommand.Summarize in conversation_commands and pending_research:
|
||||
elif ConversationCommand.Summarize in conversation_commands and not in_research_mode:
|
||||
response_log = ""
|
||||
agent_has_entries = await EntryAdapters.aagent_has_entries(agent)
|
||||
if len(file_filters) == 0 and not agent_has_entries:
|
||||
|
@ -869,7 +870,7 @@ async def chat(
|
|||
|
||||
# Gather Context
|
||||
## Extract Document References
|
||||
if pending_research:
|
||||
if not in_research_mode:
|
||||
try:
|
||||
async for result in extract_references_and_questions(
|
||||
request,
|
||||
|
@ -916,9 +917,8 @@ async def chat(
|
|||
if ConversationCommand.Notes in conversation_commands and is_none_or_empty(compiled_references):
|
||||
conversation_commands.remove(ConversationCommand.Notes)
|
||||
|
||||
if pending_research:
|
||||
## Gather Online References
|
||||
if ConversationCommand.Online in conversation_commands:
|
||||
if ConversationCommand.Online in conversation_commands and not in_research_mode:
|
||||
try:
|
||||
async for result in search_online(
|
||||
defiltered_query,
|
||||
|
@ -943,9 +943,8 @@ async def chat(
|
|||
):
|
||||
yield result
|
||||
|
||||
if pending_research:
|
||||
## Gather Webpage References
|
||||
if ConversationCommand.Webpage in conversation_commands:
|
||||
if ConversationCommand.Webpage in conversation_commands and not in_research_mode:
|
||||
try:
|
||||
async for result in read_webpages(
|
||||
defiltered_query,
|
||||
|
@ -982,9 +981,8 @@ async def chat(
|
|||
):
|
||||
yield result
|
||||
|
||||
if pending_research:
|
||||
## Gather Code Results
|
||||
if ConversationCommand.Code in conversation_commands and pending_research:
|
||||
if ConversationCommand.Code in conversation_commands and not in_research_mode:
|
||||
try:
|
||||
context = f"# Iteration 1:\n#---\nNotes:\n{compiled_references}\n\nOnline Results:{online_results}"
|
||||
async for result in run_code(
|
||||
|
|
Loading…
Reference in a new issue