Try respond even if web search, webpage read fails during chat

Khoj shouldn't refuse to respond to user if web lookups fail.
It should transparently mention that online search etc. failed.
But try respond as best as it can without those references

This change ensures a response to the users query is attempted even
when web info retrieval fails.
This commit is contained in:
Debanjum Singh Solanky 2024-10-14 17:44:46 -07:00
parent 1b04b801c6
commit a932564169

View file

@ -900,12 +900,13 @@ async def chat(
yield result[ChatEvent.STATUS] yield result[ChatEvent.STATUS]
else: else:
online_results = result online_results = result
except ValueError as e: except Exception as e:
error_message = f"Error searching online: {e}. Attempting to respond without online results" error_message = f"Error searching online: {e}. Attempting to respond without online results"
logger.warning(error_message) logger.warning(error_message)
async for result in send_llm_response(error_message): async for result in send_event(
ChatEvent.STATUS, "Online search failed. I'll try respond without online references"
):
yield result yield result
return
## Gather Webpage References ## Gather Webpage References
if ConversationCommand.Webpage in conversation_commands: if ConversationCommand.Webpage in conversation_commands:
@ -934,11 +935,15 @@ async def chat(
webpages.append(webpage["link"]) webpages.append(webpage["link"])
async for result in send_event(ChatEvent.STATUS, f"**Read web pages**: {webpages}"): async for result in send_event(ChatEvent.STATUS, f"**Read web pages**: {webpages}"):
yield result yield result
except ValueError as e: except Exception as e:
logger.warning( logger.warning(
f"Error directly reading webpages: {e}. Attempting to respond without online results", f"Error reading webpages: {e}. Attempting to respond without webpage results",
exc_info=True, exc_info=True,
) )
async for result in send_event(
ChatEvent.STATUS, "Webpage read failed. I'll try respond without webpage references"
):
yield result
## Send Gathered References ## Send Gathered References
async for result in send_event( async for result in send_event(