1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// use clap::Parser;
// use std::path::Path;
// use tokio;
// use crate::summarizer;
// #[derive(Parser, Debug, Default)]
// pub struct SummarizeArgs {
// /// Crate location to start the upward search for Cargo.toml.
// #[arg(short, long, value_hint = clap::ValueHint::DirPath, default_value = ".")]
// pub crate_location: String,
// /// Run interactive follow-up mode.
// #[arg(long = "stdin", conflicts_with = "question")]
// pub interactive: bool,
// /// Provide a single follow-up question.
// #[arg(short = 'q', long, conflicts_with = "interactive")]
// pub question: Option<String>,
// }
// /// Run the summarize subcommand.
// pub fn run(args: SummarizeArgs) -> anyhow::Result<()> {
// let rt = tokio::runtime::Runtime::new()?;
// rt.block_on(async {
// // Assumes your summarizer module exposes summarize_a_crate that accepts a crate location.
// let summary =
// summarizer::summarize_a_crate(&args.crate_location).await?;
// println!("Summary:\n{}\n", summary);
// if args.interactive || args.question.is_some() {
// if args.interactive {
// let mut rl = rustyline::DefaultEditor::new()?;
// println!("Interactive mode: enter follow-up questions (empty line to quit):");
// loop {
// let line = rl.readline("> ")?;
// let q = line.trim().to_string();
// if q.is_empty() {
// break;
// }
// rl.add_history_entry(&q).ok();
// let answer = session.ask(&q).await?;
// println!("Answer: {}\n", answer);
// }
// } else if let Some(q) = args.question {
// let answer = session.ask(&q).await?;
// println!("Answer: {}\n", answer);
// }
// }
// Ok(())
// })
// }
// /// Default run if no subcommand is provided.
// pub fn default_run() -> anyhow::Result<()> {
// run(SummarizeArgs::default())
// }
// use clap::Parser;
// use tokio;
// #[derive(Parser, Debug, Default)]
// pub struct SummarizeArgs {
// /// Crate location to begin the upward search for Cargo.toml.
// #[arg(short, long, default_value = ".")]
// pub crate_location: String,
// /// Run interactive follow-up mode.
// #[arg(long = "stdin", conflicts_with = "question")]
// pub interactive: bool,
// /// Provide a single follow-up question.
// #[arg(short = 'q', long, conflicts_with = "interactive")]
// pub question: Option<String>,
// /// Enable streaming mode for the summarization session.
// #[arg(short = 's', long = "streaming")]
// pub streaming: bool,
// /// Model to use for the summarization (e.g. "gpt-4o-mini").
// #[arg(short = 'm', long = "model", default_value = "gpt-4o-mini")]
// pub model: String,
// /// System prompt to initialize the chat session.
// #[arg(
// short = 'S',
// long = "system",
// default_value = "You are a Rust code analyst."
// )]
// pub system: String,
// }
// pub fn run(args: SummarizeArgs) -> anyhow::Result<()> {
// let rt = tokio::runtime::Runtime::new()?;
// rt.block_on(async {
// // Create a ChatSession using the provided system prompt, model, and streaming flag.
// let mut session =
// crate::summarizer::ChatSession::new(&args.system, &args.model, args.streaming);
// // Call summarize_a_crate with the provided crate location and mutable session.
// let summary =
// crate::summarizer::summarize_a_crate(&args.crate_location, &mut session).await?;
// println!("Summary:\n{}\n", summary);
// // If interactive mode or a follow-up question is requested, use the session.
// if args.interactive || args.question.is_some() {
// if args.interactive {
// let mut rl = rustyline::DefaultEditor::new()?;
// println!("Interactive mode: enter follow-up questions (empty line to quit):");
// loop {
// let line = rl.readline("> ")?;
// let q = line.trim().to_string();
// if q.is_empty() {
// break;
// }
// rl.add_history_entry(&q).ok();
// let answer = session.ask(&q).await?;
// println!("Answer: {}\n", answer);
// }
// } else if let Some(q) = args.question {
// let answer = session.ask(&q).await?;
// println!("Answer: {}\n", answer);
// }
// }
// Ok(())
// })
// }
use Parser;
use tokio;
/// Asynchronous version of your run function.
pub async
/// Synchronous wrapper that reuses the asynchronous run_async function.