004df79e66
Signed-off-by: Catty Steve <4795515+Catty2014@user.noreply.gitee.com>
88 lines
2.4 KiB
Rust
88 lines
2.4 KiB
Rust
use clap::Parser;
|
|
use log::error;
|
|
use workshop_llm_detector::{CICDLLMHelper, LLMClient, OllamaClient, OpenAIClient};
|
|
// use std::path::Path;
|
|
use anyhow::Result;
|
|
|
|
#[derive(Parser)]
|
|
#[command(name = "workshop-llm-detector")]
|
|
#[command(about = "LLM helper for analyzing repositories")]
|
|
struct Cli {
|
|
/// Repository path to analyze
|
|
repository_path: String,
|
|
|
|
/// Additional files to read (comma separated)
|
|
#[arg(short, long, value_delimiter = ',')]
|
|
files: Vec<String>,
|
|
|
|
/// LLM Provider
|
|
#[arg(long, default_value = "openai")]
|
|
provider: String,
|
|
|
|
/// Model to use
|
|
#[arg(long)]
|
|
model: String,
|
|
|
|
/// Model API URL
|
|
#[arg(long)]
|
|
model_url: Option<String>,
|
|
|
|
/// Package type for dependencies
|
|
#[arg(long, default_value = "deb")]
|
|
package_type: String,
|
|
|
|
/// Cookbook directory
|
|
#[arg(long, default_value = "cookbook")]
|
|
cookbook_dir: String,
|
|
|
|
/// Output directory
|
|
#[arg(short, long, default_value = ".")]
|
|
output_dir: String,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let args = Cli::parse();
|
|
|
|
// Initialize cookbook manager
|
|
let helper = CICDLLMHelper::new(&args.cookbook_dir)?;
|
|
|
|
// Initialize LLM client
|
|
let llm_client: Box<dyn LLMClient> = match args.provider.as_str() {
|
|
"openai" => {
|
|
let api_key = std::env::var("OPENAI_API_KEY")
|
|
.expect("OPENAI_API_KEY environment variable must be set");
|
|
let base_url = args.model_url.clone();
|
|
Box::new(OpenAIClient::new(api_key, base_url, args.model))
|
|
}
|
|
"ollama" => {
|
|
let url = args.model_url.unwrap_or_else(|| "http://localhost:11434".to_string());
|
|
Box::new(OllamaClient::new(url, args.model))
|
|
}
|
|
_ => {
|
|
error!("Unsupported provider: {}", args.provider);
|
|
std::process::exit(1);
|
|
}
|
|
};
|
|
|
|
// Analyze repository
|
|
let result = helper.analyze_repository(
|
|
&args.repository_path,
|
|
&args.files,
|
|
&*llm_client,
|
|
&args.package_type,
|
|
).await?;
|
|
|
|
println!("Analysis completed for project type: {}", result.project_type);
|
|
println!("Found {} dependencies", result.dependencies.len());
|
|
println!("Generated {} build steps", result.build_steps.len());
|
|
println!("Identified {} artifacts", result.artifacts.len());
|
|
|
|
// Write output files
|
|
helper.write_output_files(&result, &args.output_dir)?;
|
|
|
|
println!("Output files written to {}", args.output_dir);
|
|
|
|
Ok(())
|
|
}
|