Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ansari/app/main_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import psycopg2
import psycopg2.extras
import sentry_sdk
from diskcache import FanoutCache, Lock
from diskcache import FanoutCache
from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse, StreamingResponse
Expand All @@ -43,7 +43,7 @@
from ansari.app.main_whatsapp import router as whatsapp_router
from ansari.config import Settings, get_settings
from ansari.presenters.api_presenter import ApiPresenter
from ansari.util.general_helpers import CORSMiddlewareWithLogging, get_extended_origins, validate_cors
from ansari.util.general_helpers import CORSMiddlewareWithLogging, get_extended_origins

logger = get_logger(__name__)
deployment_type = get_settings().DEPLOYMENT_TYPE
Expand Down
2 changes: 0 additions & 2 deletions test_ansari_claude.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#\!/usr/bin/env python

import json
import os
import sys

from ansari.agents.ansari_claude import AnsariClaude
Expand Down
21 changes: 12 additions & 9 deletions tests/unit/test_citation_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_quran_search_sleeplessness_citation_format(self, mock_run):
{
"id": "25:47",
"text": "وَهُوَ ٱلَّذِى جَعَلَ لَكُمُ ٱلَّيْلَ لِبَاسًا وَٱلنَّوْمَ سُبَاتًا وَجَعَلَ ٱلنَّهَارَ نُشُورًا",
"en_text": "He is the One Who has made the night for you as a cover, and made sleep for resting, and the day for rising.",
"en_text": """He is the One Who has made the night for you as a cover,
and made sleep for resting, and the day for rising.""",
},
{"id": "78:9", "text": "وَجَعَلْنَا نَوْمَكُمْ سُبَاتًا", "en_text": "and made your sleep for rest,"},
]
Expand All @@ -56,17 +57,17 @@ def test_quran_search_sleeplessness_citation_format(self, mock_run):
self.assertIn("source", doc)
self.assertIn("data", doc["source"])
data = doc["source"]["data"]

# Verify data is valid JSON format
try:
parsed_data = json.loads(data)
self.assertIsInstance(parsed_data, list)

# Check that it contains language-text entries
self.assertTrue(len(parsed_data) > 0)
self.assertIn("lang", parsed_data[0])
self.assertIn("text", parsed_data[0])

# If we have an Arabic entry, verify it matches one of the mock texts
for item in parsed_data:
if item["lang"] == "ar":
Expand All @@ -91,7 +92,8 @@ def test_hadith_search_day_of_judgment_citation_format(self, mock_run):
"section_english": "The asking of Jibreel about Iman, Islam, Ihsan",
"hadith_number": "50",
"ar_text": "عَنْ أَبِي هُرَيْرَةَ، قَالَ كَانَ النَّبِيُّ صلى الله عليه وسلم بَارِزًا يَوْمًا لِلنَّاسِ...",
"en_text": 'Narrated Abu Huraira: One day while the Prophet (ﷺ) was sitting in the company of some people, (The angel) Gabriel came and asked, "What is faith?"...',
"en_text": """Narrated Abu Huraira: One day while the Prophet (ﷺ) was sitting in the company of some people,
(The angel) Gabriel came and asked, "What is faith?"...""",
"grade_en": "Sahih-Authentic",
},
{
Expand All @@ -103,7 +105,8 @@ def test_hadith_search_day_of_judgment_citation_format(self, mock_run):
"section_english": "Signs of the hour",
"hadith_number": "4178",
"ar_text": "قال رسول الله صلى الله عليه وسلم: لا تقوم الساعة حتى تكون عشر آيات...",
"en_text": "The Messenger of Allah (peace be upon him) said: The last hour will not come or happen until there appear ten signs before it...",
"en_text": """The Messenger of Allah (peace be upon him) said:
The last hour will not come or happen until there appear ten signs before it...""",
"grade_en": "Sahih - Authentic",
},
]
Expand All @@ -121,17 +124,17 @@ def test_hadith_search_day_of_judgment_citation_format(self, mock_run):
self.assertIn("source", doc)
self.assertIn("data", doc["source"])
data = doc["source"]["data"]

# Verify data is valid JSON format
try:
parsed_data = json.loads(data)
self.assertIsInstance(parsed_data, list)

# Check that it contains language-text entries
self.assertTrue(len(parsed_data) > 0)
self.assertIn("lang", parsed_data[0])
self.assertIn("text", parsed_data[0])

# Verify text content if we have Arabic or English entries
for item in parsed_data:
if item["lang"] == "ar":
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_logging_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_logging_changes_dont_break_basic_functionality():
claude = AnsariClaude.__new__(AnsariClaude)
claude.settings = settings
claude.message_logger = None

# Set needed attributes that would normally be set in __init__
claude.tools = []
claude.tool_name_to_instance = {}
Expand All @@ -37,26 +37,26 @@ def test_logging_changes_dont_break_basic_functionality():
claude.message_history = [
{"role": "user", "content": "Hello, world!"}
]

# Mock the API response to avoid actual API calls
claude.process_one_round = MagicMock(side_effect=lambda: [])

# Add an assistant response
claude.message_history.append({
"role": "assistant",
"role": "assistant",
"content": [{"type": "text", "text": "Hello! How can I help you today?"}]
})

# Verify basic validation works
assert claude.validate_message(claude.message_history[-1]) == True
assert claude.validate_message(claude.message_history[-1])

# Test message logging works
claude.message_logger = MagicMock()
claude._log_message(claude.message_history[-1])

# Verify logger was called
claude.message_logger.log.assert_called_once()

print("Test passed - basic functionality works!")


Expand Down
Loading