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
9 changes: 5 additions & 4 deletions src/app/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

from fastapi import APIRouter

from src.app.api.api_v1.endpoints import chat, metric, micro_learning, search, user
from src.app.tutor.api import router
from src.app.api.api_v1.endpoints import chat, metric, micro_learning, user
from src.app.search.api import router as search_router
from src.app.tutor.api import router as tutor_router

api_router = APIRouter()
api_router.include_router(chat.router, prefix="/qna", tags=["qna"])
api_router.include_router(search.router, prefix="/search", tags=["search"])
api_router.include_router(router.router, prefix="/tutor", tags=["tutor"])
api_router.include_router(search_router.router, prefix="/search", tags=["search"])
api_router.include_router(tutor_router.router, prefix="/tutor", tags=["tutor"])
api_router.include_router(metric.router, prefix="/metric", tags=["metric"])
api_router.include_router(
micro_learning.router, prefix="/micro_learning", tags=["micro_learning"]
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/api_v1/endpoints/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from pydantic import BaseModel

from src.app.models import chat as models
from src.app.services.constants import subjects as subjectsDict
from src.app.search.services.search import SearchService, get_search_service
from src.app.services.data_collection import get_data_collection_service
from src.app.services.exceptions import (
from src.app.shared.domain.constants import subjects as subjectsDict
from src.app.shared.domain.exceptions import (
EmptyQueryError,
InvalidQuestionError,
LanguageNotSupportedError,
bad_request,
)
from src.app.services.search import SearchService, get_search_service
from src.app.shared.infra.abst_chat import get_chat_service
from src.app.shared.utils.dependencies import get_settings
from src.app.utils.logger import logger as utils_logger
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/api_v1/endpoints/micro_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from welearn_database.data.models import ContextDocument

from src.app.models.documents import JourneySectionType
from src.app.models.search import FilterDefinition, SearchFilters
from src.app.search.models.search import FilterDefinition, SearchFilters
from src.app.search.services.search import SearchService, get_search_service
from src.app.services.helpers import (
choose_readability_according_journey_section_type,
collection_and_model_id_according_lang,
convert_embedding_bytes,
)
from src.app.services.search import SearchService, get_search_service
from src.app.services.sql_db.queries import (
get_context_documents,
get_subject,
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel, Field
from qdrant_client.models import ScoredPoint

from src.app.models.search import SDGFilter
from src.app.search.models.search import SDGFilter

from .documents import Document

Expand Down
File renamed without changes.
Empty file added src/app/search/api/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
from fastapi.concurrency import run_in_threadpool

from src.app.models.documents import Document
from src.app.models.search import (
from src.app.search.helpers.search_helpers import search_multi_inputs
from src.app.search.models.search import (
EnhancedSearchQuery,
SDGFilter,
SearchMethods,
SearchOutput,
SearchQuery,
)
from src.app.search.services.search import SearchService, get_search_service
from src.app.services.data_collection import get_data_collection_service
from src.app.services.exceptions import (
CollectionNotFoundError,
EmptyQueryError,
ModelNotFoundError,
bad_request,
)
from src.app.services.search import SearchService, get_search_service
from src.app.services.search_helpers import search_multi_inputs
from src.app.services.sql_db.queries import (
get_collections_sync,
get_documents_payload_by_ids_sync,
get_nb_docs_sync,
)
from src.app.shared.domain.exceptions import (
CollectionNotFoundError,
EmptyQueryError,
ModelNotFoundError,
bad_request,
)
from src.app.utils.logger import logger as logger_utils

router = APIRouter()
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import BackgroundTasks
from qdrant_client.http.models import ScoredPoint

from src.app.models.search import EnhancedSearchQuery, SearchMethods
from src.app.services.exceptions import handle_error
from src.app.search.models.search import EnhancedSearchQuery, SearchMethods
from src.app.shared.domain.exceptions import handle_error
from src.app.utils.logger import logger as logger_utils

logger = logger_utils(__name__)
Expand Down
Empty file.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
from transformers import AutoModel, AutoTokenizer

from src.app.models.collections import Collection
from src.app.models.search import (
from src.app.search.models.search import (
EnhancedSearchQuery,
FilterDefinition,
SearchFilters,
SearchMethods,
)
from src.app.services.data_quality import DataQualityChecker
from src.app.services.exceptions import CollectionNotFoundError, ModelNotFoundError
from src.app.services.helpers import convert_embedding_bytes
from src.app.services.sql_db.queries import (
get_embeddings_model_id_according_name,
get_subject,
)
from src.app.shared.domain.exceptions import CollectionNotFoundError, ModelNotFoundError
from src.app.utils.decorators import log_time_and_error, log_time_and_error_sync
from src.app.utils.logger import logger as logger_utils

Expand Down
4 changes: 2 additions & 2 deletions src/app/services/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from langchain_core.tools import tool

from src.app.models.documents import Document
from src.app.models.search import EnhancedSearchQuery
from src.app.search.models.search import EnhancedSearchQuery
from src.app.search.services.search import SearchService
from src.app.services.helpers import stringify_docs_content
from src.app.services.search import SearchService
from src.app.utils.decorators import log_time_and_error
from src.app.utils.logger import logger as utils_logger

Expand Down
2 changes: 1 addition & 1 deletion src/app/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from src.app.models.collections import Collection
from src.app.models.documents import JourneySectionType
from src.app.services.exceptions import LanguageNotSupportedError
from src.app.services.sql_db.queries import get_embeddings_model_id_according_name
from src.app.shared.domain.exceptions import LanguageNotSupportedError
from src.app.utils.decorators import log_time_and_error_sync
from src.app.utils.logger import logger as utils_logger

Expand Down
4 changes: 2 additions & 2 deletions src/app/services/sql_db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

from src.app.models.chat import Role
from src.app.models.documents import Document, DocumentPayloadModel, JourneySection
from src.app.models.search import ContextType
from src.app.services.constants import APP_NAME
from src.app.search.models.search import ContextType
from src.app.services.sql_db.sql_service import session_maker
from src.app.shared.domain.constants import APP_NAME

model_id_lock = Lock()

Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/app/shared/infra/abst_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@

from src.app.models.chat import ReformulatedQueryResponse
from src.app.models.documents import Document

# from src.app.shared.infra.llm_proxy import LLMProxy
from src.app.search.services.search import SearchService
from src.app.services import prompts
from src.app.services.agent import (
get_resources_about_sustainability,
trim_conversation_history,
)
from src.app.services.exceptions import LanguageNotSupportedError
from src.app.services.helpers import (
detect_language_from_entry,
extract_json_from_response,
stringify_docs_content,
)

# from src.app.shared.infra.llm_proxy import LLMProxy
from src.app.services.search import SearchService
from src.app.shared.domain.exceptions import LanguageNotSupportedError
from src.app.shared.utils.dependencies import get_settings
from src.app.utils.decorators import log_time_and_error
from src.app.utils.logger import log_environmental_impacts
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/app/tests/api/api_v1/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from src.app.models.chat import ReformulatedQueryResponse
from src.app.models.documents import Document as DocumentModel
from src.app.models.documents import DocumentPayloadModel
from src.app.services.exceptions import LanguageNotSupportedError
from src.app.shared.domain.exceptions import LanguageNotSupportedError
from src.main import app

client = TestClient(app)
Expand Down Expand Up @@ -65,7 +65,7 @@

@mock.patch("src.app.services.sql_db.queries.session_maker")
@mock.patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
@mock.patch(
Expand Down Expand Up @@ -331,7 +331,7 @@ async def test_stream(self, *mocks):

@mock.patch("psycopg.AsyncConnection.connect", new_callable=mock.AsyncMock)
@mock.patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
@mock.patch("src.app.shared.infra.abst_chat.AbstractChat.agent_message")
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/api/api_v1/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@mock.patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class TestMetricEndpoint(unittest.IsolatedAsyncioTestCase):
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/api/api_v1/test_micro_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def __call__(self, *args, **kwargs):


@mock.patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class MicroLearningTests(unittest.IsolatedAsyncioTestCase):
Expand All @@ -26,7 +26,7 @@ class MicroLearningTests(unittest.IsolatedAsyncioTestCase):
)
@mock.patch("src.app.api.api_v1.endpoints.micro_learning.get_context_documents")
@mock.patch("src.app.api.api_v1.endpoints.micro_learning.get_subject")
@mock.patch("src.app.services.search.SearchService.search")
@mock.patch("src.app.search.services.search.SearchService.search")
@mock.patch("src.app.api.api_v1.endpoints.micro_learning.convert_embedding_bytes")
async def test_get_full_journey(
self,
Expand Down
20 changes: 10 additions & 10 deletions src/app/tests/api/api_v1/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from src.app.core.config import settings
from src.app.models import collections
from src.app.models.documents import Document, DocumentPayloadModel
from src.app.models.search import EnhancedSearchQuery
from src.app.services.exceptions import CollectionNotFoundError, ModelNotFoundError
from src.app.services.search import SearchService, sort_slices_using_mmr
from src.app.search.models.search import EnhancedSearchQuery
from src.app.search.services.search import SearchService, sort_slices_using_mmr
from src.app.shared.domain.exceptions import CollectionNotFoundError, ModelNotFoundError
from src.main import app

client = TestClient(app)

search_pipeline_path = "src.app.services.search.SearchService"
search_pipeline_path = "src.app.search.services.search.SearchService"

mocked_collection = collections.Collection(
lang="mul",
Expand Down Expand Up @@ -149,7 +149,7 @@

@patch("src.app.services.sql_db.sql_service.session_maker")
@mock.patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
@patch(
Expand Down Expand Up @@ -238,7 +238,7 @@ async def test_search_all_slices_no_collections(self, *mocks):

@patch("src.app.services.sql_db.sql_service.session_maker")
@patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class SearchTestsSlices(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -306,7 +306,7 @@ async def test_search_all_slices_no_result(self, *mocks):

@patch("src.app.services.sql_db.queries.session_maker")
@patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class SearchTestsAll(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -389,7 +389,7 @@ async def test_sort_slices_using_mmr_custom_theta(self, *mocks):

@patch("src.app.services.sql_db.queries.session_maker")
@patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class SearchTestsMultiInput(IsolatedAsyncioTestCase):
Expand All @@ -414,7 +414,7 @@ async def test_search_multi_no_result(self, *mocks):

@patch("src.app.services.sql_db.queries.session_maker")
@patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class DocumentsByIdsTests(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -540,7 +540,7 @@ async def test_documents_by_ids_corpus_missing(self, session_maker_mock, *mocks)

async def test_search_multi_single_query(self, *mocks):
with mock.patch(
"src.app.api.api_v1.endpoints.search.search_multi_inputs",
"src.app.search.api.router.search_multi_inputs",
) as search_multi, mock.patch.object(
SearchService, "search_handler", return_value=mocked_documents
) as search_handler:
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/api/api_v1/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@mock.patch(
"src.app.services.security.check_api_key_sync",
"src.app.shared.infra.security.check_api_key_sync",
new=mock.MagicMock(return_value=True),
)
class UserApiTests(unittest.IsolatedAsyncioTestCase):
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from fastapi.testclient import TestClient

from src.app.services.search import get_qdrant
from src.app.search.services.search import get_qdrant
from src.main import app


Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/services/test_abst_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest import mock

from src.app.models.chat import ReformulatedQueryResponse
from src.app.services.exceptions import LanguageNotSupportedError
from src.app.shared.domain.exceptions import LanguageNotSupportedError
from src.app.shared.infra.abst_chat import AbstractChat


Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/services/test_data_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
WeLearnDocument,
)

from src.app.services.constants import APP_NAME
from src.app.services.data_quality import DataQualityChecker
from src.app.shared.domain.constants import APP_NAME


def handle_schema_with_sqlite(db_engine: Engine):
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/services/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fastapi import HTTPException

from src.app.services.exceptions import (
from src.app.shared.domain.exceptions import (
CollectionNotFoundError,
EmptyQueryError,
InvalidQuestionError,
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/services/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from langdetect.language import Language

from src.app.models.documents import Document, DocumentPayloadModel
from src.app.services.exceptions import LanguageNotSupportedError
from src.app.services.helpers import (
convert_embedding_bytes,
detect_language_from_entry,
extract_json_from_response,
stringify_docs_content,
)
from src.app.shared.domain.exceptions import LanguageNotSupportedError


class HelpersTests(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/services/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from qdrant_client.models import CollectionDescription, CollectionsResponse, ScoredPoint

from src.app.models.collections import Collection
from src.app.services.search import SearchService, concatenate_same_doc_id_slices
from src.app.search.services.search import SearchService, concatenate_same_doc_id_slices

os.environ["USE_CACHED_SETTINGS"] = "False"

Expand Down
Loading
Loading