Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Make backend search, backend tools and remainder backend files PEP8 compliant #899

Merged
merged 9 commits into from
May 14, 2024
File renamed without changes.
8 changes: 4 additions & 4 deletions code/backend/batch/function_app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import os
import azure.functions as func
from AddURLEmbeddings import bp_add_url_embeddings
from BatchPushResults import bp_batch_push_results
from BatchStartProcessing import bp_batch_start_processing
from GetConversationResponse import bp_get_conversation_response
from add_url_embeddings import bp_add_url_embeddings
from batch_push_results import bp_batch_push_results
from batch_start_processing import bp_batch_start_processing
from get_conversation_response import bp_get_conversation_response
from azure.monitor.opentelemetry import configure_azure_monitor

logging.captureWarnings(True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from typing import List, Optional
from .SourceDocument import SourceDocument
from .source_document import SourceDocument


class Answer:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Create an abstract class for document loading
from typing import List
from abc import ABC, abstractmethod
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument
from .chunking_strategy import ChunkingSettings


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .document_chunking_base import DocumentChunkingBase
from langchain.text_splitter import TokenTextSplitter
from .chunking_strategy import ChunkingSettings
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class FixedSizeOverlapDocumentChunking(DocumentChunkingBase):
Expand Down
2 changes: 1 addition & 1 deletion code/backend/batch/utilities/document_chunking/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .document_chunking_base import DocumentChunkingBase
from langchain.text_splitter import MarkdownTextSplitter
from .chunking_strategy import ChunkingSettings
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class LayoutDocumentChunking(DocumentChunkingBase):
Expand Down
2 changes: 1 addition & 1 deletion code/backend/batch/utilities/document_chunking/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .document_chunking_base import DocumentChunkingBase
from langchain.text_splitter import MarkdownTextSplitter
from .chunking_strategy import ChunkingSettings
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class PageDocumentChunking(DocumentChunkingBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
from .document_chunking_base import DocumentChunkingBase
from .chunking_strategy import ChunkingSettings
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class ParagraphDocumentChunking(DocumentChunkingBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Create an abstract class for document loading
from typing import List
from abc import ABC, abstractmethod
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class DocumentLoadingBase(ABC):
Expand Down
2 changes: 1 addition & 1 deletion code/backend/batch/utilities/document_loading/layout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
from .document_loading_base import DocumentLoadingBase
from ..helpers.azure_form_recognizer_helper import AzureFormRecognizerClient
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class LayoutDocumentLoading(DocumentLoadingBase):
Expand Down
2 changes: 1 addition & 1 deletion code/backend/batch/utilities/document_loading/read.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
from .document_loading_base import DocumentLoadingBase
from ..helpers.azure_form_recognizer_helper import AzureFormRecognizerClient
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class ReadDocumentLoading(DocumentLoadingBase):
Expand Down
2 changes: 1 addition & 1 deletion code/backend/batch/utilities/document_loading/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from langchain.docstore.document import Document
from langchain_community.document_loaders import WebBaseLoader
from .document_loading_base import DocumentLoadingBase
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class WebDocumentLoading(DocumentLoadingBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from docx import Document
import requests
from .document_loading_base import DocumentLoadingBase
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class WordDocumentLoading(DocumentLoadingBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .embedder_base import EmbedderBase
from ..env_helper import EnvHelper
from ..llm_helper import LLMHelper
from ...integrated_vectorization.AzureSearchIndex import AzureSearchIndex
from ...integrated_vectorization.AzureSearchIndexer import AzureSearchIndexer
from ...integrated_vectorization.AzureSearchDatasource import AzureSearchDatasource
from ...integrated_vectorization.AzureSearchSkillset import AzureSearchSkillset
from ...integrated_vectorization.azure_search_index import AzureSearchIndex
from ...integrated_vectorization.azure_search_indexer import AzureSearchIndexer
from ...integrated_vectorization.azure_search_datasource import AzureSearchDatasource
from ...integrated_vectorization.azure_search_skillset import AzureSearchSkillset
from ..config.config_helper import ConfigHelper
import logging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..azure_search_helper import AzureSearchHelper
from ..document_loading_helper import DocumentLoading
from ..document_chunking_helper import DocumentChunking
from ...common.SourceDocument import SourceDocument
from ...common.source_document import SourceDocument

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

from .orchestrator_base import OrchestratorBase
from ..helpers.llm_helper import LLMHelper
from ..tools.PostPromptTool import PostPromptTool
from ..tools.QuestionAnswerTool import QuestionAnswerTool
from ..tools.TextProcessingTool import TextProcessingTool
from ..common.Answer import Answer
from ..tools.post_prompt_tool import PostPromptTool
from ..tools.question_answer_tool import QuestionAnswerTool
from ..tools.text_processing_tool import TextProcessingTool
from ..common.answer import Answer

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from .orchestrator_base import OrchestratorBase
from ..helpers.llm_helper import LLMHelper
from ..tools.PostPromptTool import PostPromptTool
from ..tools.QuestionAnswerTool import QuestionAnswerTool
from ..tools.TextProcessingTool import TextProcessingTool
from ..common.Answer import Answer
from ..tools.post_prompt_tool import PostPromptTool
from ..tools.question_answer_tool import QuestionAnswerTool
from ..tools.text_processing_tool import TextProcessingTool
from ..common.answer import Answer

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from uuid import uuid4
from typing import List, Optional
from abc import ABC, abstractmethod
from ..loggers.ConversationLogger import ConversationLogger
from ..loggers.conversation_logger import ConversationLogger
from ..helpers.config.config_helper import ConfigHelper
from ..parser.output_parser_tool import OutputParserTool
from ..tools.ContentSafetyChecker import ContentSafetyChecker
from ..tools.content_safety_checker import ContentSafetyChecker

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from semantic_kernel.contents.chat_message_content import ChatMessageContent
from semantic_kernel.contents.finish_reason import FinishReason

from ..common.Answer import Answer
from ..common.answer import Answer
from ..helpers.llm_helper import LLMHelper
from ..plugins.chat_plugin import ChatPlugin
from ..plugins.post_answering_plugin import PostAnsweringPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import json
from .parser_base import ParserBase
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion code/backend/batch/utilities/parser/parser_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Create an abstract class for parser
from abc import ABC, abstractmethod
from typing import List
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class ParserBase(ABC):
Expand Down
6 changes: 3 additions & 3 deletions code/backend/batch/utilities/plugins/chat_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from semantic_kernel.functions import kernel_function

from ..common.Answer import Answer
from ..tools.QuestionAnswerTool import QuestionAnswerTool
from ..tools.TextProcessingTool import TextProcessingTool
from ..common.answer import Answer
from ..tools.question_answer_tool import QuestionAnswerTool
from ..tools.text_processing_tool import TextProcessingTool


class ChatPlugin:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from semantic_kernel.functions import kernel_function
from semantic_kernel.functions.kernel_arguments import KernelArguments

from ..common.Answer import Answer
from ..tools.PostPromptTool import PostPromptTool
from ..common.answer import Answer
from ..tools.post_prompt_tool import PostPromptTool


class PostAnsweringPlugin:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List
from .SearchHandlerBase import SearchHandlerBase
from .search_handler_base import SearchHandlerBase
from ..helpers.llm_helper import LLMHelper
from ..helpers.azure_search_helper import AzureSearchHelper
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument
import json
from azure.search.documents.models import VectorizedQuery
import tiktoken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import List
from .SearchHandlerBase import SearchHandlerBase
from .search_handler_base import SearchHandlerBase
from azure.search.documents import SearchClient
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.models import VectorizableTextQuery
from azure.core.credentials import AzureKeyCredential
from azure.identity import DefaultAzureCredential
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument
import re


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from ..search.AzureSearchHandler import AzureSearchHandler
from ..search.IntegratedVectorizationSearchHandler import (
from ..search.azure_search_handler import AzureSearchHandler
from ..search.integrated_vectorization_search_handler import (
IntegratedVectorizationSearchHandler,
)
from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument
from ..helpers.env_helper import EnvHelper


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from ..helpers.env_helper import EnvHelper

from ..common.SourceDocument import SourceDocument
from ..common.source_document import SourceDocument


class SearchHandlerBase(ABC):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create an abstract class for tool
from abc import ABC, abstractmethod
from ..common.Answer import Answer
from ..common.answer import Answer


class AnswerProcessingBase(ABC):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Create an abstract class for tool
from abc import ABC, abstractmethod
from typing import List
from ..common.Answer import Answer
from ..common.answer import Answer


class AnsweringToolBase(ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from azure.core.exceptions import HttpResponseError
from azure.ai.contentsafety.models import AnalyzeTextOptions
from ..helpers.env_helper import EnvHelper
from .AnswerProcessingBase import AnswerProcessingBase
from ..common.Answer import Answer
from .answer_processing_base import AnswerProcessingBase
from ..common.answer import Answer

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from langchain.chains.llm import LLMChain
from langchain.prompts import PromptTemplate
from langchain_community.callbacks import get_openai_callback
from ..common.Answer import Answer
from ..common.answer import Answer
from ..helpers.llm_helper import LLMHelper
from ..helpers.config.config_helper import ConfigHelper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging
import warnings

from ..common.SourceDocument import SourceDocument
from ..search.Search import Search
from .AnsweringToolBase import AnsweringToolBase
from ..common.source_document import SourceDocument
from ..search.search import Search
from .answering_tool_base import AnsweringToolBase

from langchain.chains.llm import LLMChain
from langchain.prompts import (
Expand All @@ -21,7 +21,7 @@
from ..helpers.config.config_helper import ConfigHelper
from ..helpers.llm_helper import LLMHelper
from ..helpers.env_helper import EnvHelper
from ..common.Answer import Answer
from ..common.answer import Answer

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
from ..helpers.llm_helper import LLMHelper
from .AnsweringToolBase import AnsweringToolBase
from ..common.Answer import Answer
from .answering_tool_base import AnsweringToolBase
from ..common.answer import Answer


class TextProcessingTool(AnsweringToolBase):
Expand Down
2 changes: 1 addition & 1 deletion code/backend/pages/02_Explore_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import pandas as pd
from batch.utilities.helpers.env_helper import EnvHelper
from batch.utilities.search.Search import Search
from batch.utilities.search.search import Search

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
env_helper: EnvHelper = EnvHelper()
Expand Down
2 changes: 1 addition & 1 deletion code/backend/pages/03_Delete_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import logging
from batch.utilities.helpers.env_helper import EnvHelper
from batch.utilities.search.Search import Search
from batch.utilities.search.search import Search

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
env_helper: EnvHelper = EnvHelper()
Expand Down
4 changes: 2 additions & 2 deletions code/tests/common/test_source_document.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hashlib
from unittest.mock import patch
from urllib.parse import urlparse
from backend.batch.utilities.common.SourceDocument import (
from backend.batch.utilities.common.source_document import (
SourceDocument,
SourceDocumentDecoder,
SourceDocumentEncoder,
Expand All @@ -27,7 +27,7 @@ def test_get_filename():
assert filename == "file"


@patch("backend.batch.utilities.common.SourceDocument.AzureBlobStorageClient")
@patch("backend.batch.utilities.common.source_document.AzureBlobStorageClient")
def test_get_markdown_url(azure_blob_service_mock):
# Given
azure_blob_service_mock().get_container_sas.return_value = "_12345"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
os.path.join(os.path.dirname(sys.path[0]), "..", "..", "backend", "batch")
)

from backend.batch.BatchPushResults import batch_push_results # noqa: E402
from backend.batch.batch_push_results import batch_push_results # noqa: E402

pytestmark = pytest.mark.functional

Expand Down
Loading
Loading