Usage
The run
function is the primary entry point for using the tool. It takes parsed CLI options and performs the necessary actions to interact with the Flowise AI workflows.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let opts = CliOpts::from_args();
if let Err(e) = run(opts).await {
eprintln!("Application error: {}", e);
std::process::exit(1);
}
Ok(())
}
Introduction
fluent
is a command-line utility that interacts with Flowise AI workflows, providing a Rust implementation of various features including configuration management, HTTP requests to call AI workflows, command-line interface (CLI) processing, response handling, and output formatting.
The main goals and objectives of the Fluent project are to provide a user-friendly and efficient way to interact with Flowise AI workflows from the command line. It aims to solve the problem of manual and repetitive tasks involved in calling AI workflows, handling their responses, and formatting the output.
At a high level, FluentCLI works by parsing command-line arguments provided by the user, reading configuration files, constructing HTTP requests to call the specified Flowise AI workflow, handling the response received from the workflow, and formatting the output based on user preferences. The key components of FluentCLI include the command-line interface for user interaction, configuration management for storing and retrieving settings, HTTP client for making requests to the Flowise AI workflows, and response handling and output formatting modules for processing the received data and presenting it to the user.
License
This project is licensed under MIT License.
Contribution
Contributions are welcome through pull requests and issues on GitHub. Please adhere to the project’s code of conduct.
Installation
Prerequisites
Before installing and using Fluent, ensure that you have the following prerequisites installed on your system:
- Rust programming language (version 1.51 or later)
- Cargo package manager (usually bundled with Rust)
Installation Steps
To install Fluent, follow these steps:
-
Clone the Fluent repository from GitHub:
git clone https://github.com/your-username/fluent.git
-
Navigate to the cloned repository directory:
cd fluent
-
Build the project using Cargo:
cargo build --release
This command will compile the Fluent application and generate the executable binary in the
target/release
directory.
Configuration Setup
Before running Fluent, you need to set up the configuration:
-
Set the
FLUENT_CONFIG_PATH
environment variable to point to the location of your configuration file:export FLUENT_CONFIG_PATH=/path/to/your/config.json
Replace
/path/to/your/config.json
with the actual path to your configuration file. -
Prepare the configuration file in JSON format. Here’s an example configuration:
{ "flows": [ { "name": "example_flow", "url": "https://example.com/api/flow", "method": "POST", "headers": { "Content-Type": "application/json" }, "overrideConfig": {} } ], "http_request": { "timeout": 60 }, "combined_input_format": "", "processing_message": "Processing...", "paths": { "config_path": "/path/to/config" }, "regex": { "url_regex": "^https?://" }, "defaults": { "verbosity": 1 }, "styling": { "error": "red", "success": "green" }, "skin_config": { "headers_fg": "blue", "bold_fg": "yellow", "italic_fg_bg": [ "magenta", "black" ], "bullet": "", "bullet_char": "-", "quote_mark": ">", "code_block_margin": 4, "code_block_align": "Left", "code_block_bg": "black", "italic_attrs": [ "Underlined" ] } }
Modify the configuration file according to your specific requirements, such as adding your own flows, adjusting timeout settings, and customizing the styling options.
Once you have completed the installation and configuration setup, you can run the Fluent application using the generated executable binary.
Usage
Command-Line Options
-
--name
: Required. Specifies the name for the workflow. -
--question
: Optional. Provides a question to pass along to the workflow. -
--outline-path
: Optional. Can be specified either as a positional argument or flagged by “–outline-path”. Indicates the path to an outline file. -
-p
,--parse-structured
: Optional flag. Enables parsing of structured data in the response. -
-s
,--system-prompt-override
: Optional flag. Provides a system prompt override. -
-f
,--system-prompt-override-file
: Optional flag. Specifies a file path containing the system prompt override. -
-i
,--image-folder-path
: Optional flag. Specifies the path to a folder where downloaded images will be saved. -
-m
,--markdown
: Optional flag. Enables markdown rendering of the response. -
-h
,--include-extra
: Optional flag. Includes extra data in the HTTP request. -
-g
,--generate-html-chat-client
: Optional flag. Generates an HTML chat client. -
--generate-completions
: Optional flag. Generates Bash shell autocompletion scripts based on the configuration. -
--dump-completions
: Optional flag. Generates shell completions for the specified shell (e.g., bash, zsh) based on the configuration.
Examples: - fluent --name "My Workflow" --question "What is the meaning of life?"
- fluent --name "Image Analysis" --outline-path "/path/to/outline.txt" --image-folder-path "/path/to/images"
- fluent --name "Markdown Processor" --markdown --parse-structured
- fluent --name "Custom Prompts" --system-prompt-override "You are an AI assistant."
- fluent --name "Custom Prompts File" --system-prompt-override-file "/path/to/prompt.txt"
- fluent --name "Extra Data" --include-extra --question "Analyze this data."
- fluent --name "Chat Client Generator" --generate-html-chat-client
- fluent --generate-completions
- fluent --dump-completions bash
Configuration
The configuration for the Fluent application is stored in a JSON file whose path is specified by the FLUENT_CONFIG_PATH
environment variable. The Config
struct represents the main configuration object that encapsulates all the settings.
The configuration file has the following structure:
{
"flows": [
{
"name": "string",
"url": "string",
"method": "string",
"headers": {},
"overrideConfig": {}
}
],
"http_request": {
"timeout": 60
},
"combined_input_format": "string",
"processing_message": "string",
"paths": {
"config_path": "string"
},
"regex": {
"url_regex": "string"
},
"defaults": {
"verbosity": 1
},
"styling": {
"error": "string",
"success": "string"
},
"skin_config": {
"headers_fg": "string",
"bold_fg": "string",
"italic_fg": "string",
"italic_bg": "string",
"bullet": "string",
"bullet_char": "char",
"quote_mark_fg": "string",
"code_block_margin": 4,
"code_block_align": "string",
"code_block_bg": "string",
"italic_attrs": [
"string"
],
"bold_attrs": [
"string"
],
"bold_bg": "string",
"list_indent": 8,
"list_start": "string",
"list_spacing": 8,
"list_char": "string",
"list_margin": 8,
"list_align": "string",
"list_bg": "string",
"list_fg": "string",
"list_padding": 8,
"italic_fg_bg": [
"string"
],
"quote_mark": "string"
}
}
The main sections of the configuration are:
-
flows
: An array ofFlow
objects representing the flow of operations, which includes HTTP requests and configuration overrides. -
http_request
: Configuration for HTTP requests, including the timeout value. -
combined_input_format
: A string specifying the format for combining inputs. -
processing_message
: A string message to display while processing. -
paths
: Configuration for different file paths used in the application. -
regex
: Configuration for regex patterns used in the application. -
defaults
: Default configuration values, such as the verbosity level. -
styling
: Configuration for styling console output, including colors for error and success messages. -
skin_config
: Configuration for customizing the appearance (“skin”) of console output, including colors, formatting, and layout options for various elements like headers, code blocks, lists, and more.
To customize the configuration, modify the JSON file located at the path specified by the FLUENT_CONFIG_PATH
environment variable. Update the values of the desired options within each section according to your preferences and requirements.
The read_config
function in the config
module is responsible for reading the configuration file and parsing its contents into the Config
struct. It returns a Result
type, allowing for error handling if the file is missing, fails to be read, or contains invalid JSON.
Here are some examples demonstrating common use cases of the Fluent CLI:
Calling a specific AI workflow
fluent --name "sentiment_analysis" --question "What is the sentiment of this review?"
Providing questions and context
fluent --name "question_answering" --question "What is the capital of France?" --context "France is a country in Europe. Its capital and largest city is Paris."
Generating shell completion scripts
fluent --generate-completions > fluent_completions.sh
source fluent_completions.sh
Parsing structured responses
fluent --name "extract_entities" --question "John works at Google in Mountain View" --parse-structured
Downloading images from responses
fluent --name "image_generation" --question "A futuristic city at night" --image-folder-path "./generated_images"
Generating an HTML chat client
fluent --name "chatbot" --generate-html-chat-client
This will generate an HTML file that can be opened in a web browser to interact with the specified chatbot workflow.
Contributing
We welcome contributions to the Fluent project! If you’d like to contribute, please follow these guidelines:
Reporting Issues
If you encounter any bugs, have feature requests, or want to discuss improvements, please open an issue on the GitHub repository. When reporting bugs, please include a detailed description of the issue, steps to reproduce it, and any relevant error messages or logs.
Submitting Pull Requests
To contribute code changes, please follow these steps:
- Fork the repository and create a new branch for your feature or bug fix.
- Make your changes, following the code style and conventions used in the project.
- Write tests to cover your changes and ensure that existing tests pass.
- Run the linters to check for any code style or formatting issues.
- Commit your changes with a clear and descriptive commit message.
- Push your branch to your forked repository.
- Open a pull request against the main branch of the original repository.
Please provide a detailed description of your changes in the pull request, explaining the problem you’re solving or the feature you’re adding.
Code Style and Conventions
When contributing to Fluent, please adhere to the following code style and conventions:
- Follow the Rust Style Guide for code formatting and style.
- Use meaningful variable and function names that clearly convey their purpose.
- Write concise and descriptive comments to explain complex or non-obvious code.
- Organize code into logical modules and use appropriate visibility modifiers.
- Handle errors properly and provide meaningful error messages.
Setting Up the Development Environment
To set up the development environment for Fluent, follow these steps:
-
Install Rust and Cargo by following the instructions on the official Rust website.
-
Clone the Fluent repository:
git clone https://github.com/your_username/fluent.git
-
Navigate to the project directory:
cd fluent
-
Build the project:
cargo build
Running Tests and Linters
To ensure the quality and reliability of the codebase, Fluent uses a combination of tests and linters.
To run the tests, use the following command:
cargo test
To run the linters, use the following commands:
cargo fmt -- --check
cargo clippy
Please make sure that all tests pass and there are no linter warnings before submitting a pull request.
We appreciate your contributions to Fluent and look forward to collaborating with you!
//! ## License //! //! This project is licensed under MIT License. //!