-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ai-cfia/issue40-integrate-pagination
Issue40-integrate-pagination
- Loading branch information
Showing
14 changed files
with
236 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from .app_creator import create_app | ||
from .config import Config | ||
from .config import create_config | ||
|
||
configuration = Config() | ||
app = create_app(configuration) | ||
app = create_app(create_config()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,83 @@ | ||
import json | ||
import os | ||
from dataclasses import dataclass | ||
from typing import TypedDict | ||
|
||
import app.constants as constants | ||
from azure.core.credentials import AzureKeyCredential | ||
from azure.search.documents import SearchClient | ||
from dotenv import load_dotenv | ||
from index_search import AzureIndexSearchConfig | ||
|
||
load_dotenv() | ||
|
||
AZURE_SEARCH_ENDPOINT = "" | ||
AZURE_SEARCH_INDEX_NAME = "" | ||
AZURE_SEARCH_API_KEY = "" | ||
DEFAULT_DEBUG_MODE = "False" | ||
DEFAULT_ERROR_EMPTY_QUERY = "Search query cannot be empty" | ||
DEFAULT_ERROR_AZURE_FAILED = "Azure index search failed." | ||
DEFAULT_ERROR_FINESSE_DATA_FAILED = "finesse-data static search failed" | ||
DEFAULT_ERROR_UNEXPECTED = "Unexpected error." | ||
DEFAULT_FUZZY_MATCH_THRESHOLD = 90 | ||
DEFAULT_ERROR_AILAB_FAILED = "Ailab-db search failed." | ||
DEFAULT_SANITIZE_PATTERN = ( | ||
"[^\w \d\"#\$%&'\(\)\*\+,-\.\/:;?@\^_`{\|}~]+|\%\w+|;|/|\(|\)" | ||
) | ||
DEFAULT_HIGHLIGHT_FIELDS = "content" | ||
DEFAULT_HIGHLIGHT_TAG = "strong" | ||
|
||
class Config(TypedDict): | ||
AZURE_SEARCH_SKIP: int | ||
AZURE_SEARCH_TOP: int | ||
AZURE_SEARCH_CLIENT: SearchClient | ||
AZURE_SEARCH_PARAMS: dict | ||
AZURE_SEARCH_TRANSFORM_MAP: dict | ||
FINESSE_DATA_URL: str | ||
DEBUG: bool | ||
ERROR_EMPTY_QUERY: str | ||
ERROR_AZURE_FAILED: str | ||
ERROR_FINESSE_DATA_FAILED: str | ||
ERROR_AILAB_FAILED: str | ||
ERROR_UNEXPECTED: str | ||
FUZZY_MATCH_THRESHOLD: int | ||
SANITIZE_PATTERN: str | ||
|
||
@dataclass | ||
class Config: | ||
AZURE_CONFIG = AzureIndexSearchConfig( | ||
client=SearchClient( | ||
os.getenv("FINESSE_BACKEND_AZURE_SEARCH_ENDPOINT", AZURE_SEARCH_ENDPOINT), | ||
os.getenv( | ||
"FINESSE_BACKEND_AZURE_SEARCH_INDEX_NAME", AZURE_SEARCH_INDEX_NAME | ||
), | ||
AzureKeyCredential( | ||
os.getenv("FINESSE_BACKEND_AZURE_SEARCH_API_KEY", AZURE_SEARCH_API_KEY) | ||
), | ||
), | ||
highlight_fields=os.getenv( | ||
"FINESSE_BACKEND_HIGHLIGHT_FIELDS", DEFAULT_HIGHLIGHT_FIELDS | ||
|
||
def create_config() -> Config: | ||
azure_search_client = SearchClient( | ||
endpoint=os.getenv("FINESSE_BACKEND_AZURE_SEARCH_ENDPOINT", ""), | ||
index_name=os.getenv("FINESSE_BACKEND_AZURE_SEARCH_INDEX_NAME", ""), | ||
credential=AzureKeyCredential( | ||
os.getenv("FINESSE_BACKEND_AZURE_SEARCH_API_KEY", "") | ||
), | ||
highlight_tag=os.getenv("FINESSE_BACKEND_HIGHLIGHT_TAG", DEFAULT_HIGHLIGHT_TAG), | ||
) | ||
FINESSE_DATA_URL = os.getenv("FINESSE_BACKEND_STATIC_FILE_URL") | ||
DEBUG = ( | ||
os.getenv("FINESSE_BACKEND_DEBUG_MODE", DEFAULT_DEBUG_MODE).lower() == "true" | ||
) | ||
ERROR_EMPTY_QUERY = os.getenv( | ||
"FINESSE_BACKEND_ERROR_EMPTY_QUERY", DEFAULT_ERROR_EMPTY_QUERY | ||
) | ||
ERROR_AZURE_FAILED = os.getenv( | ||
"FINESSE_BACKEND_ERROR_AZURE_FAILED", DEFAULT_ERROR_AZURE_FAILED | ||
) | ||
ERROR_FINESSE_DATA_FAILED = os.getenv( | ||
"FINESSE_BACKEND_ERROR_FINESSE_DATA_FAILED", DEFAULT_ERROR_FINESSE_DATA_FAILED | ||
) | ||
ERROR_AILAB_FAILED = os.getenv( | ||
"FINESSE_BACKEND_ERROR_AILAB_FAILED", DEFAULT_ERROR_AILAB_FAILED | ||
) | ||
ERROR_UNEXPECTED = os.getenv( | ||
"FINESSE_BACKEND_ERROR_UNEXPECTED", DEFAULT_ERROR_UNEXPECTED | ||
) | ||
FUZZY_MATCH_THRESHOLD = int( | ||
os.getenv( | ||
"FINESSE_BACKEND_FUZZY_MATCH_THRESHOLD", DEFAULT_FUZZY_MATCH_THRESHOLD | ||
) | ||
azure_search_transform_map = ( | ||
json.loads(os.getenv("FINESSE_BACKEND_AZURE_SEARCH_TRANSFORM_MAP", "{}")) | ||
or constants.DEFAULT_AZURE_SEARCH_TRANSFORM_MAP_JSON | ||
) | ||
SANITIZE_PATTERN = os.getenv( | ||
"FINESSE_BACKEND_SANITIZE_PATTERN", DEFAULT_SANITIZE_PATTERN | ||
azure_search_params = ( | ||
json.loads(os.getenv("FINESSE_BACKEND_AZURE_SEARCH_PARAMS", "{}")) | ||
or constants.DEFAULT_AZURE_SEARCH_PARAMS | ||
) | ||
|
||
return { | ||
"AZURE_SEARCH_SKIP": constants.DEFAULT_AZURE_SEARCH_SKIP, | ||
"AZURE_SEARCH_TOP": constants.DEFAULT_AZURE_SEARCH_TOP, | ||
"AZURE_SEARCH_CLIENT": azure_search_client, | ||
"AZURE_SEARCH_PARAMS": azure_search_params, | ||
"AZURE_SEARCH_TRANSFORM_MAP": azure_search_transform_map, | ||
"FINESSE_DATA_URL": os.getenv("FINESSE_BACKEND_STATIC_FILE_URL"), | ||
"DEBUG": os.getenv( | ||
"FINESSE_BACKEND_DEBUG_MODE", constants.DEFAULT_DEBUG_MODE | ||
).lower() | ||
== "true", | ||
"ERROR_EMPTY_QUERY": os.getenv( | ||
"FINESSE_BACKEND_ERROR_EMPTY_QUERY", constants.DEFAULT_ERROR_EMPTY_QUERY | ||
), | ||
"ERROR_AZURE_FAILED": os.getenv( | ||
"FINESSE_BACKEND_ERROR_AZURE_FAILED", constants.DEFAULT_ERROR_AZURE_FAILED | ||
), | ||
"ERROR_FINESSE_DATA_FAILED": os.getenv( | ||
"FINESSE_BACKEND_ERROR_FINESSE_DATA_FAILED", | ||
constants.DEFAULT_ERROR_FINESSE_DATA_FAILED, | ||
), | ||
"ERROR_AILAB_FAILED": os.getenv( | ||
"FINESSE_BACKEND_ERROR_AILAB_FAILED", constants.DEFAULT_ERROR_AILAB_FAILED | ||
), | ||
"ERROR_UNEXPECTED": os.getenv( | ||
"FINESSE_BACKEND_ERROR_UNEXPECTED", constants.DEFAULT_ERROR_UNEXPECTED | ||
), | ||
"FUZZY_MATCH_THRESHOLD": int( | ||
os.getenv( | ||
"FINESSE_BACKEND_FUZZY_MATCH_THRESHOLD", | ||
str(constants.DEFAULT_FUZZY_MATCH_THRESHOLD), | ||
) | ||
), | ||
"SANITIZE_PATTERN": os.getenv( | ||
"FINESSE_BACKEND_SANITIZE_PATTERN", constants.DEFAULT_SANITIZE_PATTERN | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Constants | ||
|
||
# Flag to determine if debug mode is active, default is False | ||
DEFAULT_DEBUG_MODE = "False" | ||
|
||
# Default error message for empty search queries | ||
DEFAULT_ERROR_EMPTY_QUERY = "Search query cannot be empty" | ||
|
||
# Default error message when Azure search service fails | ||
DEFAULT_ERROR_AZURE_FAILED = "Azure index search failed." | ||
|
||
# Default error message for failures in finesse-data static search | ||
DEFAULT_ERROR_FINESSE_DATA_FAILED = "finesse-data static search failed" | ||
|
||
# Default error message for any unexpected errors encountered | ||
DEFAULT_ERROR_UNEXPECTED = "Unexpected error." | ||
|
||
# Threshold for fuzzy match scoring, default set to 90% | ||
DEFAULT_FUZZY_MATCH_THRESHOLD = 90 | ||
|
||
# Default error message when Ailab-db search fails | ||
DEFAULT_ERROR_AILAB_FAILED = "Ailab-db search failed." | ||
|
||
# Regular expression pattern for sanitizing search queries | ||
DEFAULT_SANITIZE_PATTERN = ( | ||
"[^\w \d\"#\$%&'\(\)\*\+,-\.\/:;?@\^_`{\|}~]+|\%\w+|;|/|\(|\)" | ||
) | ||
|
||
# Default number of search results to skip in Azure search, default is 0 | ||
DEFAULT_AZURE_SEARCH_SKIP = 0 | ||
|
||
# Default number of search results to return from Azure search, default is 10 | ||
DEFAULT_AZURE_SEARCH_TOP = 10 | ||
|
||
# Mapping of Azure search result fields to desired output structure. | ||
# Knowledge of the index search result structure is required. | ||
DEFAULT_AZURE_SEARCH_TRANSFORM_MAP_JSON = { | ||
"id": "/id", | ||
"title": "/title", | ||
"score": "/@search.score", | ||
"url": "/url", | ||
"content": "/content", | ||
"last_updated": "/last_updated", | ||
} | ||
|
||
# Default parameters for Azure search highlighting | ||
# Consult https://learn.microsoft.com/en-us/python/api/azure-search-documents/azure.search.documents.searchclient?view=azure-python#azure-search-documents-searchclient-search | ||
DEFAULT_AZURE_SEARCH_PARAMS = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.