### Set Up Development Environment Source: https://github.com/mags0ft/spamfilter/blob/master/docs/contributing.md Clone the repository, create and activate a virtual environment, and install development dependencies. This is the initial setup for contributing code. ```bash git clone https://github.com/mags0ft/spamfilter.git cd spamfilter python3 -m venv .venv source .venv/bin/activate # On Windows use .venv\Scripts\activate pip install -e .[dev] ``` -------------------------------- ### Install Spamfilter using Pip Source: https://github.com/mags0ft/spamfilter/blob/master/docs/installation.md Use this command to install the spamfilter library via pip, the standard Python package installer. This is the recommended and easiest method. ```bash pip install spamfilter ``` -------------------------------- ### Install Spamfilter with Transformers Support Source: https://github.com/mags0ft/spamfilter/blob/master/docs/installation.md Install spamfilter with the '[transformers]' extra dependency to leverage machine learning text classification using 🤗 Transformers. ```bash pip install spamfilter[transformers] ``` -------------------------------- ### Install Spamfilter using Python -m pip Source: https://github.com/mags0ft/spamfilter/blob/master/docs/installation.md If the standard 'pip install' command fails, likely due to PATH issues, use this alternative command to install spamfilter via the Python interpreter. ```bash python3 -m pip install spamfilter ``` -------------------------------- ### Install Spamfilter with API Support Source: https://github.com/mags0ft/spamfilter/blob/master/docs/installation.md Install spamfilter with the '[api]' extra dependency to enable support for third-party API calling features. ```bash pip install spamfilter[api] ``` -------------------------------- ### Install Spamfilter with OpenAI Integration Source: https://github.com/mags0ft/spamfilter/blob/master/docs/installation.md Install spamfilter with the '[openai]' extra dependency to enable integration with OpenAI services. ```bash pip install spamfilter[openai] ``` -------------------------------- ### Verify Spamfilter Installation Source: https://github.com/mags0ft/spamfilter/blob/master/docs/get_started.md Run this Python code in the console to verify that the spamfilter library has been installed successfully by checking its version. ```python >>> import spamfilter >>> spamfilter.__version__ 'v3.0.0' >>> ``` -------------------------------- ### Install Spamfilter with Development Dependencies Source: https://github.com/mags0ft/spamfilter/blob/master/docs/installation.md Install spamfilter with the '[dev]' extra dependency to include all necessary packages for development purposes. ```bash pip install spamfilter[dev] ``` -------------------------------- ### Create and Use Chat Pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/docs/premade.md Demonstrates creating a chat pipeline with `create_pipeline` and accessing the default `chatPipeline` object. ```python from spamfilter.premade import chat c1 = chat.create_pipeline(...args) c2 = chat.chatPipeline ``` -------------------------------- ### Fine-tune Article Pipeline with create_pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/docs/premade.md Illustrates creating an article pipeline with `create_pipeline`, allowing adjustments to parameters for high-quality writing environments. ```python from spamfilter.premade import article c = article.create_pipeline( bypass_protection: bool = True, length_filter: bool = True, min_: int = 400, max_: int = 300_000, wordlength_filter: bool = True, max_word_length: int = 50, max_num_too_long_words: int = 3, capitals_filter: bool = True, capitals_percentage: float = 0.4, capitals_mode: str = "normal", specialchars_filter: bool = True, profanity_filter: bool = False, profanity_blocklist_filepath: str = "" ) ``` -------------------------------- ### Create and Use a Pipeline with Multiple Filters Source: https://github.com/mags0ft/spamfilter/blob/master/docs/pipelines.md Demonstrates creating a pipeline with Capitals, SpecialChars, and Length filters. The pipeline checks if a string passes all filter conditions, including length constraints. ```python from spamfilter.pipelines import Pipeline from spamfilter.filters import ( Capitals, SpecialChars, Length ) m = Pipeline([ Capitals(), SpecialChars(mode = "crop"), Length(min_ = 20, max_ = 60) ]) print( m.check("Test string!").passed ) ``` -------------------------------- ### Fine-tune Chat Pipeline with create_pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/docs/premade.md Shows how to customize a chat pipeline using `create_pipeline` with various arguments for fine-grained control. ```python from spamfilter.premade import chat c = chat.create_pipeline( bypass_protection: bool = True, length_filter: bool = True, min_: int = 1, max_: int = 200, wordlength_filter: bool = True, max_word_length: int = 20, max_num_too_long_words: int = 1, capitals_filter: bool = True, capitals_percentage: float = 0.3, capitals_mode: str = "crop", specialchars_filter: bool = True, profanity_filter: bool = False, profanity_blocklist_filepath: str = "" ) ``` -------------------------------- ### Use Default Chat Pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/docs/premade.md Provides the code to instantiate the default, ready-to-use chat pipeline without any custom configuration. ```python from spamfilter.premade import chat c = chat.chatPipeline ``` -------------------------------- ### Create and use a basic spamfilter pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/README.md Demonstrates how to create a simple spam filtering pipeline using Length and SpecialChars filters and then test a string against it. The pipeline is configured to crop strings between 10 and 200 characters and limit the use of special characters. ```python from spamfilter.filters import Length from spamfilter.filters import SpecialChars from spamfilter.pipelines import Pipeline # create a new pipeline m = Pipeline([ # length of 10 to 200 chars, crop if needed Length(min_=10, max_=200, mode="crop"), # limit use of special characters SpecialChars(mode="normal") ]) # test a string against it TEST_STRING = "This is a test string." print(m.check(TEST_STRING).passed) ``` -------------------------------- ### Use Default Article Pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/docs/premade.md Shows how to access the default article pipeline object for immediate use in demanding writing platforms. ```python from spamfilter.premade import article c = chat.articlePipeline ``` -------------------------------- ### Import Pipeline Class Source: https://github.com/mags0ft/spamfilter/blob/master/docs/pipelines.md Import the Pipeline class from the spamfilter.pipelines module. ```python from spamfilter.pipelines import Pipeline ``` -------------------------------- ### Create a Result Object Source: https://github.com/mags0ft/spamfilter/blob/master/docs/results.md Instantiate a Result object when you need to create your own. Ensure the spamfilter.results module is imported. ```python from spamfilter.results import Result r = Result(...args) ``` -------------------------------- ### Use Premade Chat Pipeline Source: https://github.com/mags0ft/spamfilter/blob/master/docs/get_started.md This Python code demonstrates how to create and use a premade chat pipeline from the spamfilter library to check if a given string is considered spam. It prints 'True' if the string passes the filter and 'False' otherwise. ```python from spamfilter.premade import chat c = chat.create_pipeline() INPUT_STRING = "This is a test string." print(c.check(INPUT_STRING).passed) ``` -------------------------------- ### Import Single Filter Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md Import a single filter class from the spamfilter.filters module. ```python from spamfilter.filters import Filter ``` -------------------------------- ### Import All Filters Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md Import all filter classes from the spamfilter.filters module. Wildcard imports are generally discouraged. ```python from spamfilter.filters import * ``` -------------------------------- ### Import Multiple Filters Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md Import several filter classes simultaneously from the spamfilter.filters module. ```python from spamfilter.filters import ( Capitals, Length, SpecialChars ) ``` -------------------------------- ### Filter Construction Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md Construct a filter instance with specified options and mode. The 'normal' mode is commonly used. ```python Filter(**options, mode = "normal") ``` -------------------------------- ### Default OpenAI Response Parsing Function Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md The standard function for parsing responses from the OpenAI filter. It determines if a response indicates spam and extracts corrected text. ```python RespFuncType = Callable[[dict[str, Union[bool, str]]], Tuple[bool, str]] STD_RESP_FUNC: RespFuncType = lambda resp: ( not resp["is_spam"], (resp["corrected_text"] if "corrected_text" in resp else ""), ) ``` -------------------------------- ### Filter Check Method Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md Use the check method of a filter instance to assess a string. It returns a tuple indicating success and the processed string. ```python (passed: int, output_string: str) ``` -------------------------------- ### Default Email Filter Regex Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md The default regular expression pattern used by the Email filter for email address validation. ```regex ([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+) ``` -------------------------------- ### Default MLTextClassifier Response Parsing Function Source: https://github.com/mags0ft/spamfilter/blob/master/docs/filters.md The default function for parsing results from the MLTextClassifier filter. It identifies spam or toxic content based on score. ```python def _default_response_parsing_function( result: list[dict[str, Union[str, float]]], ) -> bool: """ Default response parsing function that checks if the label is 'spam' or 'toxic'. """ sorted_result = sorted(result, key=lambda x: x["score"], reverse=True) top_label: str = str(sorted_result[0]["label"]).lower() return top_label not in ["spam", "toxic", "hate", "abusive"] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.