From 7f186be7422cfd2bf9927e0bf24e61f0df59bca0 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 11 Sep 2024 18:18:57 -0700 Subject: [PATCH] Fix json payload passed by automations to the new POST chat API --- src/khoj/routers/helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index 7a6881c7..cd15f7ee 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1200,6 +1200,9 @@ def scheduled_chat( if conversation_id: query_dict["conversation_id"] = [conversation_id] + # Restructure the original query_dict into a valid JSON payload for the chat API + json_payload = {key: values[0] for key, values in query_dict.items()} + # Construct the URL to call the chat API with the scheduled query string url = f"{scheme}://{calling_url.netloc}/api/chat?client=khoj" @@ -1215,7 +1218,7 @@ def scheduled_chat( headers["Authorization"] = f"Bearer {token}" # Call the chat API endpoint with authenticated user token and query - raw_response = requests.post(url, headers=headers, json=query_dict) + raw_response = requests.post(url, headers=headers, json=json_payload) # Stop if the chat API call was not successful if raw_response.status_code != 200: