Skip to content
Closed
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: 19 additions & 14 deletions cortex-cli/src/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,17 @@ impl RunCli {
pub async fn run(self) -> Result<()> {
// Validate temperature if provided
if let Some(temp) = self.temperature
&& !(0.0..=2.0).contains(&temp) {
bail!("Temperature must be between 0.0 and 2.0, got {temp}");
}
&& !(0.0..=2.0).contains(&temp)
{
bail!("Temperature must be between 0.0 and 2.0, got {temp}");
}

// Validate top_p if provided
if let Some(top_p) = self.top_p
&& !(0.0..=1.0).contains(&top_p) {
bail!("top-p must be between 0.0 and 1.0, got {top_p}");
}
&& !(0.0..=1.0).contains(&top_p)
{
bail!("top-p must be between 0.0 and 1.0, got {top_p}");
}

// Check if original message args are all whitespace (before quote-wrapping)
// This catches cases like `cortex run " "` which would otherwise pass validation
Expand Down Expand Up @@ -420,6 +422,7 @@ impl RunCli {
let overrides = cortex_engine::ConfigOverrides {
model: self.model.clone(),
cwd: self.cwd.clone(),
temperature: self.temperature,
..Default::default()
};
let config = cortex_engine::Config::load_sync(overrides).unwrap_or_default();
Expand Down Expand Up @@ -460,9 +463,10 @@ impl RunCli {
SessionMode::New { title } => {
let id = uuid::Uuid::new_v4().to_string();
if let Some(ref t) = title
&& self.verbose {
eprintln!("New session: {id} (title: {t})");
}
&& self.verbose
{
eprintln!("New session: {id} (title: {t})");
}
id
}
};
Expand Down Expand Up @@ -558,11 +562,12 @@ impl RunCli {
while let Ok(event) = handle.event_rx.recv().await {
// Check timeout
if let Some(timeout) = timeout_duration
&& start_time.elapsed() > timeout {
eprintln!("Timeout reached after {} seconds", self.timeout);
error_occurred = true;
break;
}
&& start_time.elapsed() > timeout
{
eprintln!("Timeout reached after {} seconds", self.timeout);
error_occurred = true;
break;
}

event_count += 1;

Expand Down
8 changes: 8 additions & 0 deletions cortex-engine/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub struct Config {
/// Small model for lightweight tasks (title generation, summaries).
/// Format: "provider/model" (e.g., "openai/gpt-4o-mini").
pub small_model: Option<String>,
/// Temperature for generation (0.0-2.0).
/// CLI override takes precedence over agent default.
pub temperature: Option<f32>,
}

impl Default for Config {
Expand Down Expand Up @@ -110,6 +113,7 @@ impl Default for Config {
current_agent: None,
permission: PermissionConfig::default(),
small_model: None, // Auto-detected based on available providers
temperature: None,
}
}
}
Expand Down Expand Up @@ -225,6 +229,8 @@ impl Config {
current_agent: toml.current_agent,
permission: toml.permission,
small_model: toml.small_model,
// CLI temperature override takes precedence
temperature: overrides.temperature,
}
}
}
Expand All @@ -238,4 +244,6 @@ pub struct ConfigOverrides {
pub approval_policy: Option<AskForApproval>,
pub sandbox_mode: Option<SandboxMode>,
pub additional_writable_roots: Vec<PathBuf>,
/// Temperature override from CLI (0.0-2.0).
pub temperature: Option<f32>,
}
3 changes: 2 additions & 1 deletion cortex-engine/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,8 @@ impl Session {
model: self.config.model.clone(),
messages: self.messages.clone(),
max_tokens: Some(4096),
temperature: Some(0.7),
// Use CLI-provided temperature or default to 0.7
temperature: Some(self.config.temperature.unwrap_or(0.7)),
tools,
stream: true,
};
Expand Down
Loading