Skip to content

Commit

Permalink
Make automation should_notify check robust to non json mode chat models
Browse files Browse the repository at this point in the history
Use clean_json to handle automation should_notify check For gemini and
other chat models where enforcing json mode is problematic, not supported
  • Loading branch information
debanjum committed Jan 6, 2025
1 parent 9a5e358 commit 266d274
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/khoj/routers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,8 +1672,7 @@ def format_automation_response(scheduling_request: str, executed_query: str, ai_
Format the AI response to send in automation email to user.
"""
name = get_user_name(user)
if name:
username = prompts.user_name.format(name=name)
username = prompts.user_name.format(name=name) if name else ""

automation_format_prompt = prompts.automation_format_prompt.format(
original_query=scheduling_request,
Expand Down Expand Up @@ -1704,7 +1703,7 @@ def should_notify(original_query: str, executed_query: str, ai_response: str, us
try:
# TODO Replace with async call so we don't have to maintain a sync version
raw_response = send_message_to_model_wrapper_sync(to_notify_or_not, user=user, response_type="json_object")
response = json.loads(raw_response)
response = json.loads(clean_json(raw_response))
should_notify_result = response["decision"] == "Yes"
reason = response.get("reason", "unknown")
logger.info(
Expand Down

0 comments on commit 266d274

Please sign in to comment.