Skip to content

Commit 8fee008

Browse files
fix lint
1 parent 5694585 commit 8fee008

6 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎src/app/api/api_v1/endpoints/micro_learning.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy
2-
from fastapi import APIRouter, HTTPException, Depends
2+
from fastapi import APIRouter, Depends, HTTPException
33
from welearn_database.data.models import ContextDocument
44

55
from src.app.models.documents import JourneySectionType
@@ -9,9 +9,9 @@
99
collection_and_model_id_according_lang,
1010
convert_embedding_bytes,
1111
)
12+
from src.app.services.search import SearchService, get_search_service
1213
from src.app.services.sql_db import get_context_documents, get_subject, get_subjects
1314
from src.app.utils.logger import logger as logger_utils
14-
from src.app.services.search import SearchService, get_search_service
1515

1616
router = APIRouter()
1717
logger = logger_utils(__name__)
@@ -23,7 +23,9 @@
2323
description="Retrieve all the subjects",
2424
response_model=list[str],
2525
)
26-
async def get_subject_list(lang: str | None = None,sp: SearchService = Depends(get_search_service)) -> list[str]:
26+
async def get_subject_list(
27+
lang: str | None = None, sp: SearchService = Depends(get_search_service)
28+
) -> list[str]:
2729
collection_info, model_id = await collection_and_model_id_according_lang(
2830
sp=sp, lang=lang
2931
)
@@ -38,7 +40,12 @@ async def get_subject_list(lang: str | None = None,sp: SearchService = Depends(g
3840
summary="get the full journey",
3941
description="Get all documents for the micro learning journey of one sdg",
4042
)
41-
async def get_full_journey(sdg: int, subject: str, lang: str | None = None):
43+
async def get_full_journey(
44+
sdg: int,
45+
subject: str,
46+
lang: str | None = None,
47+
sp: SearchService = Depends(get_search_service),
48+
):
4249
collection_info, model_id = await collection_and_model_id_according_lang(
4350
sp=sp, lang=lang
4451
)

‎src/app/api/api_v1/endpoints/search.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from src.app.services.sql_db import session_maker
3131
from src.app.utils.logger import logger as logger_utils
3232

33-
3433
router = APIRouter()
3534
logger = logger_utils(__name__)
3635

@@ -148,7 +147,7 @@ async def search_doc_by_collection(
148147
async def search_all_slices_by_lang(
149148
response: Response,
150149
qp: EnhancedSearchQuery = Depends(get_params),
151-
sp: SearchService = Depends(get_search_service)
150+
sp: SearchService = Depends(get_search_service),
152151
):
153152
try:
154153

@@ -174,7 +173,7 @@ async def search_all_slices_by_lang(
174173
async def multi_search_all_slices_by_lang(
175174
response: Response,
176175
qp: EnhancedSearchQuery = Depends(get_params),
177-
sp: SearchService = Depends(get_search_service)
176+
sp: SearchService = Depends(get_search_service),
178177
):
179178
if isinstance(qp.query, str):
180179
qp.query = [qp.query]

‎src/app/api/api_v1/endpoints/tutor.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from typing import Annotated
22

3-
from fastapi import APIRouter, File, Response, UploadFile, Depends
4-
from qdrant_client import qdrant_client
3+
from fastapi import APIRouter, Depends, File, Response, UploadFile
54

65
from src.app.api.dependencies import get_settings
76
from src.app.models.search import EnhancedSearchQuery
87
from src.app.services.abst_chat import AbstractChat
98
from src.app.services.exceptions import NoResultsError
109
from src.app.services.helpers import extract_json_from_response
11-
from src.app.services.search import SearchService, get_qdrant
10+
from src.app.services.search import SearchService, get_search_service
1211
from src.app.services.search_helpers import search_multi_inputs
1312
from src.app.services.tutor.agents import TEMPLATES
1413
from src.app.services.tutor.models import (
@@ -28,8 +27,6 @@
2827
from src.app.services.tutor.utils import get_files_content
2928
from src.app.utils.logger import logger as utils_logger
3029

31-
from src.app.services.search import SearchService, get_search_service
32-
3330
logger = utils_logger(__name__)
3431

3532
router = APIRouter()

‎src/app/core/lifespan.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from contextlib import asynccontextmanager
2+
23
from fastapi import FastAPI
3-
from src.app.services.search import init_qdrant, close_qdrant
4+
5+
from src.app.services.search import close_qdrant, init_qdrant
46

57

68
@asynccontextmanager

‎src/app/services/search.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
from functools import cache
33
from typing import Tuple, cast
44

5-
from fastapi import Depends
65
import numpy as np
6+
from fastapi import Depends
77
from numpy import ndarray
88
from psycopg import Error
9-
from qdrant_client import models as qdrant_models, qdrant_client
9+
from qdrant_client import AsyncQdrantClient
10+
from qdrant_client import models as qdrant_models
11+
from qdrant_client import qdrant_client
1012
from qdrant_client.http import exceptions as qdrant_exceptions
1113
from qdrant_client.http import models as http_models
1214
from sentence_transformers import SentenceTransformer
1315
from sklearn.metrics.pairwise import cosine_similarity
1416

17+
from src.app.api.dependencies import get_settings
1518
from src.app.models.collections import Collection
1619
from src.app.models.search import (
1720
EnhancedSearchQuery,
@@ -24,8 +27,6 @@
2427
from src.app.services.sql_db import get_subject
2528
from src.app.utils.decorators import log_time_and_error, log_time_and_error_sync
2629
from src.app.utils.logger import logger as logger_utils
27-
from qdrant_client import AsyncQdrantClient
28-
from src.app.api.dependencies import get_settings
2930

3031
logger = logger_utils(__name__)
3132

@@ -346,11 +347,13 @@ def sort_slices_using_mmr(
346347
logger.debug("sort_slices_using_mmr=end")
347348
return [qdrant_results[i] for i in id_s]
348349

350+
349351
async def get_search_service(
350352
qdrant: AsyncQdrantClient = Depends(get_qdrant),
351353
) -> SearchService:
352354
return SearchService(qdrant)
353355

356+
354357
@log_time_and_error_sync
355358
def concatenate_same_doc_id_slices(
356359
qdrant_results: list[http_models.ScoredPoint],

‎src/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
description=settings.DESCRIPTION,
2424
title=settings.PROJECT_NAME,
2525
openapi_url=f"{settings.API_V1_STR}/openapi.json",
26-
lifespan=lifespan
26+
lifespan=lifespan,
2727
)
2828

2929
# TODO: check this with JM

0 commit comments

Comments
 (0)