EnglishFormatter is a command-line tool designed to help users format, summarize, or paraphrase text documents using advanced language models. It provides an interactive menu-driven interface and supports customization through command-line arguments.
Here's a link to a demo of the tool in action using VSCode.
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- Examples
- Development
- Contributing
- License
- Contact
- Acknowledgments
- Notes
- FAQ
- Detailed Class Explanations
- Extending the Tool
- Support
- Format Documents: Improve the readability and structure of your text.
- Summarize Documents: Generate concise summaries of lengthy texts.
- Paraphrase Documents: Rephrase text while preserving the original meaning.
- Customizable Models: Choose different language models for processing.
- Output Customization: Define custom suffixes for output files.
- Interactive Menu: User-friendly navigation through the tool's features.
- Cross-Platform Support: Compatible with Windows and Unix-like systems.
- CMake 3.20 or higher: For building the project.
- C++20 Compiler: A compiler that supports C++20 (e.g., GCC 10+, Clang 10+, MSVC 2019+).
- Vcpkg: For dependency management.
- An API Key: You'll need an API key from the language model provider (e.g., OpenAI).
Vcpkg is a package manager for C++ libraries.
-
Clone Vcpkg
git clone https://github.com/microsoft/vcpkg.git
-
Bootstrap Vcpkg
cd vcpkg # On Unix/Linux/macOS ./bootstrap-vcpkg.sh # On Windows (PowerShell) .\bootstrap-vcpkg.bat
git clone https://github.com/yourusername/EnglishFormatter.git
cd EnglishFormatter
Create a .env
file in the project's root directory:
API_KEY=your_api_key_here
Replace your_api_key_here
with your actual API key.
-
Create a Build Directory
mkdir build cd build
-
Configure the Project with CMake
cmake .. -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake
-
Build the Project
cmake --build .
Note: On Windows with Visual Studio, you may need to specify the configuration:
cmake --build . --config Release
-
Unix/Linux/macOS
./EnglishFormatter
-
Windows
.\EnglishFormatter.exe
-
API Key
The tool requires an API key to access the language model API. Set the
API_KEY
in the.env
file or as an environment variable. -
Default Model
The default language model is
gpt-3.5-turbo
. You can change this using the--model
command-line option. -
Output Suffix
The default suffix for output files is
_modified
. Customize it using the--output
command-line option.
EnglishFormatter [options]
Options:
-h, --help Show this help message and exit
-v, --version Show the tool's version and exit
-m, --model MODEL Specify the language model to use (default: gpt-3.5-turbo)
-o, --output SUFFIX Specify the output file suffix (default: _modified)
-t, --token-usage Show token usage and exit
- --help (-h): Displays help information.
- --version (-v): Shows the tool's version.
- --model (-m): Sets a custom language model.
- --output (-o): Sets a custom suffix for output files.
- --token-usage (-t): Shows token-usage information.
Run the tool without any arguments to start the interactive menu:
./EnglishFormatter
- Format document: Format text files.
- Summarize document: Summarize text files.
- Paraphrase document: Paraphrase text files.
- Exit: Exit the application.
- Use the Up and Down arrow keys to navigate the menu.
- Press Enter to select an option.
- Select an action from the menu.
- When prompted, enter the names of the files you want to process, separated by spaces.
- The tool will process each file and save the output with the specified suffix.
./EnglishFormatter --model gpt-3.5-turbo --output _formatted
- Select: Format document
- Enter:
document1.txt document2.txt
Output Files:
document1.txt_formatted.txt
document2.txt_formatted.txt
./EnglishFormatter
- Select: Summarize document
- Enter:
report.txt
Output File:
report.txt_modified.txt
./EnglishFormatter --model gpt-4
- Select: Paraphrase document
- Enter:
essay.txt
Output File:
essay.txt_modified.txt
-
cli_app/
- src/: Source code files.
cli.cpp
: Entry point of the application.eng_format.cpp
: Contains theeng_format
class responsible for processing files and making API calls.display.cpp
: Contains thedisplay
class for the interactive menu.
- include/: Header files.
eng_format.hpp
display.hpp
common.hpp
: Common includes and declarations.
- src/: Source code files.
-
vcpkg.json: Manifest file for Vcpkg dependencies.
-
.env: Contains environment variables like
API_KEY
.
- curl: For making HTTP requests.
- fmt: For formatting strings.
- nlohmann-json: For JSON parsing.
- dotenv-cpp: For environment variable management.
- GoogleTest: For unit testing.
Follow the instructions in the Installation section.
After building the project, you can run the tests using:
ctest
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with clear and descriptive messages.
- Push to your fork and submit a Pull Request.
For development and contribution guidelines, refer to CONTRIBUTING.md.
This project is licensed under the MIT License.
For any questions or suggestions, please open an issue on the GitHub repository or contact the maintainer.
- libcurl: For easy HTTP requests.
- nlohmann/json: For JSON parsing.
- dotenv-cpp: For environment variable management.
- fmt: For formatting strings.
- GoogleTest: For unit testing.
- OpenAI: For providing advanced language models.
- API Usage: Be aware of the API usage policies and costs associated with the language model provider.
- Error Handling: The tool includes error handling for missing files, API errors, and invalid inputs.
- Extensibility: The code is modular, making it easy to add new features or support for additional models.
A: Ensure that your .env
file is in the correct directory and contains the API_KEY
variable. Alternatively, set the API_KEY
as an environment variable in your system.
A: Yes. Modify the eng_format
class to adjust the API endpoint and parameters according to the provider's documentation.
A: Currently, the tool supports text files. To add support for other formats, extend the read_file_content
and save_file
methods in the eng_format
class.
- Purpose: Handles file processing and API communication.
- Key Methods:
process_files()
: Processes a list of files based on the selected action.make_api_call()
: Sends a request to the language model API.parse_response()
: Parses the API response to extract the result.read_file_content()
: Reads the content of a file.save_file()
: Writes the processed content to an output file.
- Purpose: Provides an interactive menu for user interaction.
- Key Methods:
navigate_menu()
: Handles menu navigation and selection.show_menu()
: Displays the menu options.handle_file_input()
: Prompts the user for file names.
-
Adding New Actions:
- Update the
menuItems
vector incli.cpp
with the new action. - Implement a new method in
eng_format
to handle the action. - Update the
process_files()
method to include the new action.
- Update the
-
Customizing Prompts:
- Modify the prompt messages in the
handle_file_input()
method of thedisplay
class.
- Modify the prompt messages in the
-
Enhancing Error Handling:
- Add additional checks and exception handling where necessary.
If you encounter any issues or have questions, please create an issue on the GitHub repository or contact the maintainer directly.