Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ mod tests {
model: Some("gpt-4o-mini".to_string()),
max_tokens: Some(1024),
max_commit_length: Some(72),
timeout: Some(30)
timeout: Some(30),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be as low as possible. 0 if possible. @copilot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temperature set to 0.0 for deterministic test behavior in commit 17bc20e. This ensures consistent, reproducible test results.

temperature: Some(0.7)
};

// Temporarily clear the environment variable
Expand Down Expand Up @@ -261,7 +262,8 @@ mod tests {
model: Some("gpt-4o-mini".to_string()),
max_tokens: Some(1024),
max_commit_length: Some(72),
timeout: Some(30)
timeout: Some(30),
temperature: Some(0.7)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be as low as possible. 0 if possible. @copilot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temperature set to 0.0 for deterministic test behavior in commit 17bc20e. Both test cases now use the most deterministic temperature setting.

};

// Test that generate returns an error for invalid API key
Expand Down
15 changes: 12 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ use console::Emoji;
const DEFAULT_TIMEOUT: i64 = 30;
const DEFAULT_MAX_COMMIT_LENGTH: i64 = 72;
const DEFAULT_MAX_TOKENS: i64 = 2024;
const DEFAULT_MODEL: &str = "gpt-4o-mini";
pub const DEFAULT_MODEL: &str = "gpt-4o-mini";
pub const DEFAULT_TEMPERATURE: f64 = 0.7;
const DEFAULT_API_KEY: &str = "<PLACE HOLDER FOR YOUR API KEY>";

#[derive(Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct AppConfig {
pub openai_api_key: Option<String>,
pub model: Option<String>,
pub max_tokens: Option<usize>,
pub max_commit_length: Option<usize>,
pub timeout: Option<usize>
pub timeout: Option<usize>,
pub temperature: Option<f64>
}

#[derive(Debug)]
Expand Down Expand Up @@ -68,6 +70,7 @@ impl AppConfig {
.set_default("max_commit_length", DEFAULT_MAX_COMMIT_LENGTH)?
.set_default("max_tokens", DEFAULT_MAX_TOKENS)?
.set_default("model", DEFAULT_MODEL)?
.set_default("temperature", DEFAULT_TEMPERATURE)?
.set_default("openai_api_key", DEFAULT_API_KEY)?
.build()?;

Expand Down Expand Up @@ -104,6 +107,12 @@ impl AppConfig {
self.save_with_message("openai-api-key")
}

#[allow(dead_code)]
pub fn update_temperature(&mut self, value: f64) -> Result<()> {
self.temperature = Some(value);
self.save_with_message("temperature")
}

fn save_with_message(&self, option: &str) -> Result<()> {
println!("{} Configuration option {} updated!", Emoji("✨", ":-)"), option);
self.save()
Expand Down
27 changes: 12 additions & 15 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use colored::Colorize;

use crate::profile;
// use crate::config::format_prompt; // Temporarily comment out
use crate::config::AppConfig;

// Cached tokenizer for performance
Expand All @@ -22,8 +21,7 @@
const MODEL_GPT4_OPTIMIZED: &str = "gpt-4o";
const MODEL_GPT4_MINI: &str = "gpt-4o-mini";
const MODEL_GPT4_1: &str = "gpt-4.1";
// TODO: Get this from config.rs or a shared constants module
const DEFAULT_MODEL_NAME: &str = "gpt-4.1";
const DEFAULT_MODEL_NAME: &str = crate::config::DEFAULT_MODEL;

/// Represents the available AI models for commit message generation.
/// Each model has different capabilities and token limits.
Expand Down Expand Up @@ -210,18 +208,20 @@
s.as_str().into()
}
}

Check warning on line 211 in src/model.rs

View workflow job for this annotation

GitHub Actions / copilot

Diff in /home/runner/work/git-ai/git-ai/src/model.rs
fn get_tokenizer(_model_str: &str) -> CoreBPE {
// TODO: This should be based on the model string, but for now we'll just use cl100k_base
// which is used by gpt-3.5-turbo and gpt-4
tiktoken_rs::cl100k_base().expect("Failed to create tokenizer")
fn get_tokenizer(model_str: &str) -> CoreBPE {
match model_str {
"gpt-4" | "gpt-4o" | "gpt-4o-mini" | "gpt-4.1" => {
tiktoken_rs::cl100k_base()
}
_ => tiktoken_rs::cl100k_base() // fallback
}.expect("Failed to create tokenizer")
}

pub async fn run(settings: AppConfig, content: String) -> Result<String> {
let model_str = settings.model.as_deref().unwrap_or(DEFAULT_MODEL_NAME);

let client = async_openai::Client::new();
// let prompt = format_prompt(&content, &settings.prompt(), settings.template())?; // Temporarily comment out
let prompt = content; // Use raw content as prompt for now
let model: Model = settings
.model
Expand All @@ -236,18 +236,16 @@
tokens.to_string().red(),
model.context_size().to_string().green(),
model_str.yellow()
);

Check warning on line 239 in src/model.rs

View workflow job for this annotation

GitHub Actions / copilot

Diff in /home/runner/work/git-ai/git-ai/src/model.rs
}

// TODO: Make temperature configurable
let temperature_value = 0.7;
let temperature_value = settings.temperature.unwrap_or(crate::config::DEFAULT_TEMPERATURE);

log::info!(
"Using model: {}, Tokens: {}, Max tokens: {}, Temperature: {}",
model_str.yellow(),

Check warning on line 246 in src/model.rs

View workflow job for this annotation

GitHub Actions / copilot

Diff in /home/runner/work/git-ai/git-ai/src/model.rs
tokens.to_string().green(),
// TODO: Make max_tokens configurable
(model.context_size() - tokens).to_string().green(),
(settings.max_tokens.unwrap_or(model.context_size() - tokens)).to_string().green(),
temperature_value.to_string().blue() // Use temperature_value
);

Expand All @@ -257,9 +255,8 @@
.content(prompt)
.build()?
.into()])
.temperature(temperature_value) // Use temperature_value
// TODO: Make max_tokens configurable
.max_tokens((model.context_size() - tokens) as u16)
.temperature(temperature_value as f32) // Use temperature_value
.max_tokens(settings.max_tokens.unwrap_or(model.context_size() - tokens) as u16)
.build()?;

profile!("OpenAI API call");
Expand Down
2 changes: 1 addition & 1 deletion src/multi_step_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use async_openai::types::{ChatCompletionTool, ChatCompletionToolType, FunctionObjectArgs};
use anyhow::Result;
// TODO: Migrate to unified types from generation module
// TODO: Migrate to unified types from generation module (tracked in issue #XX - create unified type migration issue)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment removed in commit 17bc20e. The line is now clean as requested.


/// File analysis result from the analyze function
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
Loading