+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions fluent_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fluent_cli"
version = "0.1.0"
name = "fluent"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -23,4 +23,5 @@ regex = "1.10.4"
termimad = "0.14"
serde_yaml = "0.9.34+deprecated"
chrono = "0.4.38"
anyhow = "1.0.68"
anyhow = "1.0.68"
colored = "2.1.0"
2 changes: 1 addition & 1 deletion fluent_cli/functional_tests/functional_test_02.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Configuration
CLI_PATH="/Users/n/RustroverProjects/fluent_cli/fluent_cli/target/release/fluent_cli"
CLI_PATH="/Users/n/RustroverProjects/fluent_cli/fluent_cli/target/release/fluent"
TEST_DATA_PATH="/Users/n/RustroverProjects/fluent_cli/fluent_cli/functional_tests"
CSV_FILE="/Users/n/Downloads/functional_test_results.csv"
LOG_FILE="/Users/n/Downloads/functional_test_log.txt"
Expand Down
21 changes: 3 additions & 18 deletions fluent_cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ pub async fn handle_response(response_body: &str, matches: &clap::ArgMatches) ->
download_media(urls, directory).await;
}
if matches.is_present("markdown-output") {
let pretty_text = pretty_format_markdown(&parsed_output.text); // Ensure text is obtained correctly
eprintln!("{:?}", pretty_text);
pretty_format_markdown(&parsed_output.text); // Ensure text is obtained correctly

} else if matches.is_present("parse-code-output") {
let code_blocks = extract_code_blocks(&parsed_output.text);
for block in code_blocks {
Expand Down Expand Up @@ -108,11 +108,6 @@ pub async fn handle_response(response_body: &str, matches: &clap::ArgMatches) ->
}







fn extract_urls(text: &str) -> Vec<String> {
let url_regex = Regex::new(r"https?://[^\s]+").unwrap();
url_regex.find_iter(text)
Expand All @@ -122,13 +117,9 @@ fn extract_urls(text: &str) -> Vec<String> {

fn pretty_format_markdown(markdown_content: &str) {
let skin = MadSkin::default(); // Assuming `termimad` is used
let formatted = skin.print_text(markdown_content); // Render to a string
formatted
skin.print_text(markdown_content); // Render to a string
}




fn extract_code_blocks(markdown_content: &str) -> Vec<String> {
let re = Regex::new(r"```[\w]*\n([\s\S]*?)\n```").unwrap();
re.captures_iter(markdown_content)
Expand All @@ -138,20 +129,14 @@ fn extract_code_blocks(markdown_content: &str) -> Vec<String> {
.collect()
}


pub fn parse_fluent_cli_output(json_data: &str) -> Result<FluentCliOutput> {
let output: FluentCliOutput = serde_json::from_str(json_data)?;
Ok(output)
}


use reqwest;

use tokio::io::AsyncWriteExt;

use chrono::Local;


use anyhow::{Context};

// Correct definition of the function returning a Result with a boxed dynamic error
Expand Down
22 changes: 19 additions & 3 deletions fluent_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,32 @@ use crate::config::{EnvVarGuard, generate_bash_autocomplete_script};
use anyhow::Result;


use colored::*; // Import the colored crate
use colored::control::*;

fn print_status(flowname: &str, new_question: &str) {
eprintln!(
"{}{}Fluent: {}\nProcessing: {}\n{}{}",
">>>>".bright_yellow().bold(),
"\n".normal(),
flowname.bright_blue().bold(),
new_question.bright_green(),
">>>>".bright_yellow().bold(),
"\n".normal()
);
}

// use env_logger; // Uncomment this when you are using it to initialize logs
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
colored::control::set_override(true);

let mut configs = config::load_config()?;

let matches = Command::new("Fluent CLI")
.version("0.1.0")
.author("Your Name <your.email@example.com>")
.author("Nicholas Ferguson <nick@njf.io>")
.about("Interacts with FlowiseAI workflows")
.arg(Arg::new("flowname")
.help("The flow name to invoke")
Expand Down Expand Up @@ -104,7 +121,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let flowname = matches.value_of("flowname").unwrap();
let flow = configs.iter_mut().find(|f| f.name == flowname).expect("Flow not found");

let request = matches.value_of("request").unwrap();

// Load context from stdin if not provided
Expand Down Expand Up @@ -175,7 +191,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut env_guard = EnvVarGuard::new();
let env_guard_result = env_guard.decrypt_amber_keys_for_flow(flow)?;
debug!("EnvGuard result: {:?}", env_guard_result);

print_status(flowname, actual_final_context_clone.as_ref().unwrap_or(&new_question).as_str());
let payload = crate::client::prepare_payload(&flow, request, file_path, actual_final_context_clone ).await?;
let response = crate::client::send_request(&flow, &payload).await?;
debug!("Handling Response");
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载