Skip to content

Commit 6b4c4f1

Browse files
committed
Make OpenAI optional and gate CLI extract
Make the 'openai' integration opt-in: remove it from Cargo.toml default features and drop the bin required-features entry so the project can build without OpenAI support. In src/bin/cli.rs, conditionally import query_openai and gate the Extract command and query_llm function with cfg(feature = "openai"). Add a fallback Extract arm when the feature is disabled that returns a clear error telling users to enable the 'openai' feature. This allows building the CLI without the OpenAI dependency while providing a helpful message when extracting is requested but not enabled.
1 parent 830d1f6 commit 6b4c4f1

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ variantly = "0.4.0"
4848
case = "1.0.0"
4949

5050
[features]
51-
default = ["openai"]
51+
default = []
5252
python = ["pyo3"]
5353
wasm = ["wasm-bindgen", "serde-wasm-bindgen", "tsify-next"]
5454
openai = ["openai-api-rs"]
@@ -59,7 +59,6 @@ minijinja-embed = "2.0.1"
5959
[[bin]]
6060
name = "md-models"
6161
path = "src/bin/cli.rs"
62-
required-features = ["openai"]
6362

6463
[dev-dependencies]
6564
assert_cmd = "2.0.14"

src/bin/cli.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use mdmodels::{
3030
exporters::{render_jinja_template, Templates},
3131
json::validation::validate_json,
3232
linkml::export::serialize_linkml,
33-
llm::extraction::query_openai,
3433
pipeline::process_pipeline,
3534
};
3635
use serde::{Deserialize, Serialize};
@@ -44,6 +43,9 @@ use std::{
4443
str::FromStr,
4544
};
4645

46+
#[cfg(feature = "openai")]
47+
use mdmodels::llm::extraction::query_openai;
48+
4749
/// Command-line interface for MD-Models CLI.
4850
#[derive(Parser)]
4951
#[command(name = "MD-Models CLI", version = "0.1.0")]
@@ -236,7 +238,10 @@ fn main() -> Result<(), Box<dyn Error>> {
236238
Commands::Validate(args) => validate(args),
237239
Commands::Convert(args) => convert(args),
238240
Commands::Pipeline(args) => process_pipeline(&args.input),
241+
#[cfg(feature = "openai")]
239242
Commands::Extract(args) => query_llm(args),
243+
#[cfg(not(feature = "openai"))]
244+
Commands::Extract(_) => Err("OpenAI support is not enabled. Please enable the 'openai' feature using the --features openai flag when building the package.".into()),
240245
Commands::Dataset(args) => match args.command {
241246
DatasetCommands::Validate(args) => validate_ds(args),
242247
},
@@ -306,6 +311,7 @@ fn print_validation_result(result: bool) {
306311
println!(" └── {message}\n");
307312
}
308313

314+
#[cfg(feature = "openai")]
309315
fn query_llm(args: ExtractArgs) -> Result<(), Box<dyn Error>> {
310316
let path = resolve_input_path(&args.model);
311317
let model = DataModel::from_markdown(&path)?;

0 commit comments

Comments
 (0)