tl_cli/cli/commands/
chat.rs1use anyhow::Result;
4
5use crate::chat::{ChatSession, SessionConfig};
6use crate::config::{ConfigManager, ResolveOptions, resolve_config};
7
8pub struct ChatOptions {
10 pub to: Option<String>,
12 pub provider: Option<String>,
14 pub model: Option<String>,
16 pub style: Option<String>,
18}
19
20pub async fn run_chat(options: ChatOptions) -> Result<()> {
24 let manager = ConfigManager::new()?;
25 let config_file = manager.load_or_default();
26
27 let resolve_options = ResolveOptions {
28 to: options.to,
29 provider: options.provider,
30 model: options.model,
31 style: options.style,
32 };
33
34 let resolved = resolve_config(&resolve_options, &config_file)?;
35
36 let session_config = SessionConfig::new(
37 resolved.provider_name,
38 resolved.endpoint,
39 resolved.model,
40 resolved.api_key,
41 resolved.target_language,
42 resolved.style_name,
43 resolved.style_prompt,
44 config_file.styles.clone(),
45 );
46
47 let mut session = ChatSession::new(session_config);
48 session.run().await
49}