mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Format server code with ruff recommendations
This commit is contained in:
@@ -33,7 +33,7 @@ def create_conversation(message_list, user, agent=None):
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_chat_with_no_chat_history_or_retrieved_content(chat_client):
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": "Hello, my name is Testatron. Who are you?"})
|
||||
response = chat_client.post("/api/chat", json={"q": "Hello, my name is Testatron. Who are you?"})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -50,7 +50,7 @@ def test_chat_with_no_chat_history_or_retrieved_content(chat_client):
|
||||
def test_chat_with_online_content(chat_client):
|
||||
# Act
|
||||
q = "/online give me the link to paul graham's essay how to do great work"
|
||||
response = chat_client.post(f"/api/chat?", json={"q": q})
|
||||
response = chat_client.post("/api/chat?", json={"q": q})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -59,9 +59,9 @@ def test_chat_with_online_content(chat_client):
|
||||
"paulgraham.com/hwh.html",
|
||||
]
|
||||
assert response.status_code == 200
|
||||
assert any(
|
||||
[expected_response in response_message for expected_response in expected_responses]
|
||||
), f"Expected links: {expected_responses}. Actual response: {response_message}"
|
||||
assert any([expected_response in response_message for expected_response in expected_responses]), (
|
||||
f"Expected links: {expected_responses}. Actual response: {response_message}"
|
||||
)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -70,15 +70,15 @@ def test_chat_with_online_content(chat_client):
|
||||
def test_chat_with_online_webpage_content(chat_client):
|
||||
# Act
|
||||
q = "/online how many firefighters were involved in the great chicago fire and which year did it take place?"
|
||||
response = chat_client.post(f"/api/chat", json={"q": q})
|
||||
response = chat_client.post("/api/chat", json={"q": q})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
expected_responses = ["185", "1871", "horse"]
|
||||
assert response.status_code == 200
|
||||
assert any(
|
||||
[expected_response in response_message for expected_response in expected_responses]
|
||||
), f"Expected links: {expected_responses}. Actual response: {response_message}"
|
||||
assert any([expected_response in response_message for expected_response in expected_responses]), (
|
||||
f"Expected links: {expected_responses}. Actual response: {response_message}"
|
||||
)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -93,7 +93,7 @@ def test_answer_from_chat_history(chat_client, default_user2: KhojUser):
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": "What is my name?"})
|
||||
response = chat_client.post("/api/chat", json={"q": "What is my name?"})
|
||||
response_message = response.content.decode("utf-8")
|
||||
|
||||
# Assert
|
||||
@@ -120,7 +120,7 @@ def test_answer_from_currently_retrieved_content(chat_client, default_user2: Kho
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": "Where was Xi Li born?"})
|
||||
response = chat_client.post("/api/chat", json={"q": "Where was Xi Li born?"})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -144,7 +144,7 @@ def test_answer_from_chat_history_and_previously_retrieved_content(chat_client_n
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client_no_background.post(f"/api/chat", json={"q": "Where was I born?"})
|
||||
response = chat_client_no_background.post("/api/chat", json={"q": "Where was I born?"})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -167,7 +167,7 @@ def test_answer_from_chat_history_and_currently_retrieved_content(chat_client, d
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": "Where was I born?"})
|
||||
response = chat_client.post("/api/chat", json={"q": "Where was I born?"})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -192,7 +192,7 @@ def test_no_answer_in_chat_history_or_retrieved_content(chat_client, default_use
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": "Where was I born?"})
|
||||
response = chat_client.post("/api/chat", json={"q": "Where was I born?"})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -222,7 +222,7 @@ def test_answer_using_general_command(chat_client, default_user2: KhojUser):
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "stream": True})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "stream": True})
|
||||
response_message = response.content.decode("utf-8")
|
||||
|
||||
# Assert
|
||||
@@ -240,7 +240,7 @@ def test_answer_from_retrieved_content_using_notes_command(chat_client, default_
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -258,7 +258,7 @@ def test_answer_not_known_using_notes_command(chat_client_no_background, default
|
||||
create_conversation(message_list, default_user2)
|
||||
|
||||
# Act
|
||||
response = chat_client_no_background.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client_no_background.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -291,7 +291,7 @@ def test_summarize_one_file(chat_client, default_user2: KhojUser):
|
||||
json={"filename": summarization_file, "conversation_id": str(conversation.id)},
|
||||
)
|
||||
query = "/summarize"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
# Assert
|
||||
assert response_message != ""
|
||||
@@ -322,7 +322,7 @@ def test_summarize_extra_text(chat_client, default_user2: KhojUser):
|
||||
json={"filename": summarization_file, "conversation_id": str(conversation.id)},
|
||||
)
|
||||
query = "/summarize tell me about Xiu"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
# Assert
|
||||
assert response_message != ""
|
||||
@@ -349,7 +349,7 @@ def test_summarize_multiple_files(chat_client, default_user2: KhojUser):
|
||||
)
|
||||
|
||||
query = "/summarize"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -365,7 +365,7 @@ def test_summarize_no_files(chat_client, default_user2: KhojUser):
|
||||
|
||||
# Act
|
||||
query = "/summarize"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -400,11 +400,11 @@ def test_summarize_different_conversation(chat_client, default_user2: KhojUser):
|
||||
|
||||
# Act
|
||||
query = "/summarize"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation2.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation2.id)})
|
||||
response_message_conv2 = response.json()["response"]
|
||||
|
||||
# now make sure that the file filter is still in conversation 1
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation1.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation1.id)})
|
||||
response_message_conv1 = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -430,7 +430,7 @@ def test_summarize_nonexistant_file(chat_client, default_user2: KhojUser):
|
||||
json={"filename": "imaginary.markdown", "conversation_id": str(conversation.id)},
|
||||
)
|
||||
query = urllib.parse.quote("/summarize")
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
# Assert
|
||||
assert response_message == "No files selected for summarization. Please add files using the section on the left."
|
||||
@@ -462,7 +462,7 @@ def test_summarize_diff_user_file(chat_client, default_user: KhojUser, pdf_confi
|
||||
|
||||
# Act
|
||||
query = "/summarize"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -477,7 +477,7 @@ def test_summarize_diff_user_file(chat_client, default_user: KhojUser, pdf_confi
|
||||
def test_answer_requires_current_date_awareness(chat_client):
|
||||
"Chat actor should be able to answer questions relative to current date using provided notes"
|
||||
# Act
|
||||
response = chat_client.post(f"/api/chat", json={"q": "Where did I have lunch today?", "stream": True})
|
||||
response = chat_client.post("/api/chat", json={"q": "Where did I have lunch today?", "stream": True})
|
||||
response_message = response.content.decode("utf-8")
|
||||
|
||||
# Assert
|
||||
@@ -496,7 +496,7 @@ def test_answer_requires_date_aware_aggregation_across_provided_notes(chat_clien
|
||||
"Chat director should be able to answer questions that require date aware aggregation across multiple notes"
|
||||
# Act
|
||||
query = "How much did I spend on dining this year?"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -518,7 +518,7 @@ def test_answer_general_question_not_in_chat_history_or_retrieved_content(chat_c
|
||||
|
||||
# Act
|
||||
query = "Write a haiku about unit testing. Do not say anything else."
|
||||
response = chat_client.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -536,7 +536,7 @@ def test_answer_general_question_not_in_chat_history_or_retrieved_content(chat_c
|
||||
def test_ask_for_clarification_if_not_enough_context_in_question(chat_client_no_background):
|
||||
# Act
|
||||
query = "What is the name of Namitas older son?"
|
||||
response = chat_client_no_background.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client_no_background.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"].lower()
|
||||
|
||||
# Assert
|
||||
@@ -571,7 +571,7 @@ def test_answer_in_chat_history_beyond_lookback_window(chat_client, default_user
|
||||
|
||||
# Act
|
||||
query = "What is my name?"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert
|
||||
@@ -604,9 +604,7 @@ def test_answer_in_chat_history_by_conversation_id(chat_client, default_user2: K
|
||||
|
||||
# Act
|
||||
query = "/general What is my favorite color?"
|
||||
response = chat_client.post(
|
||||
f"/api/chat", json={"q": query, "conversation_id": str(conversation.id), "stream": True}
|
||||
)
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id), "stream": True})
|
||||
response_message = response.content.decode("utf-8")
|
||||
|
||||
# Assert
|
||||
@@ -639,7 +637,7 @@ def test_answer_in_chat_history_by_conversation_id_with_agent(
|
||||
|
||||
# Act
|
||||
query = "/general What did I buy for breakfast?"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response = chat_client.post("/api/chat", json={"q": query, "conversation_id": str(conversation.id)})
|
||||
response_message = response.json()["response"]
|
||||
|
||||
# Assert that agent only responds with the summary of spending
|
||||
@@ -657,7 +655,7 @@ def test_answer_requires_multiple_independent_searches(chat_client):
|
||||
"Chat director should be able to answer by doing multiple independent searches for required information"
|
||||
# Act
|
||||
query = "Is Xi Li older than Namita? Just say the older persons full name"
|
||||
response = chat_client.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"].lower()
|
||||
|
||||
# Assert
|
||||
@@ -681,7 +679,7 @@ def test_answer_using_file_filter(chat_client):
|
||||
query = (
|
||||
'Is Xi Li older than Namita? Just say the older persons full name. file:"Namita.markdown" file:"Xi Li.markdown"'
|
||||
)
|
||||
response = chat_client.post(f"/api/chat", json={"q": query})
|
||||
response = chat_client.post("/api/chat", json={"q": query})
|
||||
response_message = response.json()["response"].lower()
|
||||
|
||||
# Assert
|
||||
|
||||
Reference in New Issue
Block a user