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
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ console = "0.16.3"
ctrlc = "3.5.2"
reqwest = { version = "0.12.15", default-features = false, features = ["brotli", "deflate", "gzip", "json", "multipart", "rustls-tls", "stream"] }
futures-util = "0.3.34"
fs2 = "0.4"
jsonc-parser = { version = "0.33.1", features = ["serde"] }
scraper = "0.27.0"
serde = { version = "1.0.228", features = ["derive"] }
Expand Down
43 changes: 41 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,20 @@ pub struct FastGptArgs {
#[arg(long, value_name = "SECONDS")]
pub cache_ttl: Option<u64>,
}
impl FastGptArgs {
/// Validates fastgpt arguments.
///
/// # Errors
/// Returns an error when web search is explicitly disabled, which the
/// upstream FastGPT API does not support.
pub fn validate(&self) -> Result<(), String> {
if self.web_search == Some(false) {
return Err("fastgpt --web-search false is not supported by the upstream FastGPT API, which requires web search grounding. Omit --web-search or pass --web-search true".to_string());
}

Ok(())
}
}

#[derive(Debug, Args)]
/// Arguments for the `news` subcommand.
Expand Down Expand Up @@ -1920,8 +1934,8 @@ pub struct RedirectUpdateArgs {
#[cfg(test)]
mod tests {
use super::{
Cli, Commands, NewsArgs, NewsFilterMode, NewsFilterScope, OutputFormat, SearchArgs,
SearchOrder, SearchTime, SummarizeArgs,
Cli, Commands, FastGptArgs, NewsArgs, NewsFilterMode, NewsFilterScope, OutputFormat,
SearchArgs, SearchOrder, SearchTime, SummarizeArgs,
};
use clap::Parser;

Expand Down Expand Up @@ -2074,6 +2088,31 @@ mod tests {
.expect_err("summarize should require url or text input");
assert!(error.contains("exactly one of --url or --text"));
}
#[test]
fn rejects_fastgpt_disabled_web_search() {
let args = FastGptArgs {
query: "What is the capital of Australia?".to_string(),
cache: None,
web_search: Some(false),
local_cache: false,
cache_ttl: None,
};
let error = args
.validate()
.expect_err("web_search false should be rejected");
assert!(error.contains("not supported"));

for web_search in [None, Some(true)] {
let args = FastGptArgs {
query: "What is the capital of Australia?".to_string(),
cache: None,
web_search,
local_cache: false,
cache_ttl: None,
};
assert!(args.validate().is_ok());
}
}

#[test]
fn parses_product_workflow_commands() {
Expand Down
Loading