fix(triage): improve AI issue triage with better prompt and label handling

This commit is contained in:
ZhenYi 2026-04-28 13:12:34 +08:00
parent 0acacbf57c
commit 3643991955

View File

@ -97,7 +97,7 @@ async fn call_ai_for_triage(
model_name: &str,
prompt: &str,
app_config: &AppConfig,
) -> Result<String, AppError> {
) -> Result<agent::AiCallResponse, AppError> {
let api_key = app_config
.ai_api_key()
.map_err(|e| AppError::InternalServerError(format!("AI API key not configured: {}", e)))?;
@ -126,7 +126,7 @@ async fn call_ai_for_triage(
AppError::InternalServerError(format!("AI triage call failed: {}", e))
})?;
Ok(response.content)
Ok(response)
}
impl AppService {
@ -170,8 +170,8 @@ impl AppService {
let prompt =
build_triage_prompt(&issue_model.title, issue_model.body.as_deref(), &existing_labels);
let ai_content = match call_ai_for_triage(&model.name, &prompt, &self.config).await {
Ok(c) => c,
let ai_response = match call_ai_for_triage(&model.name, &prompt, &self.config).await {
Ok(r) => r,
Err(e) => {
tracing::warn!(
project = %project_name,
@ -186,7 +186,25 @@ impl AppService {
}
};
let suggestions = parse_triage_response(&ai_content);
// Record billing (non-fatal)
let _ = self
.record_ai_usage(
project.id,
model.id,
ai_response.input_tokens,
ai_response.output_tokens,
)
.await
.inspect_err(|e| {
tracing::warn!(
project = %project.id,
error = ?e,
"failed to record AI billing for issue triage"
);
})
.ok();
let suggestions = parse_triage_response(&ai_response.content);
let mut comment_posted = false;
if let Some(ref s) = suggestions {