chore: cargo fmt + clippy fix for collapsed if-let chain (T017)
- cargo fmt applied across all modified source files - Collapse nested if let Some / if !is_empty into a single let-chain (clippy::collapsible_match) - All other warnings are pre-existing dead-code lint on unused trait methods Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -738,7 +738,11 @@ impl InsightGenerator {
|
||||
.map(|t| t.name)
|
||||
.collect()
|
||||
};
|
||||
log::info!("Fetched {} tags for photo: {:?}", tag_names.len(), tag_names);
|
||||
log::info!(
|
||||
"Fetched {} tags for photo: {:?}",
|
||||
tag_names.len(),
|
||||
tag_names
|
||||
);
|
||||
|
||||
// 4. Get location name from GPS coordinates (needed for RAG query)
|
||||
let location = match exif {
|
||||
@@ -827,7 +831,10 @@ impl InsightGenerator {
|
||||
Some(desc)
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Failed to generate photo description for RAG enrichment: {}", e);
|
||||
log::warn!(
|
||||
"Failed to generate photo description for RAG enrichment: {}",
|
||||
e
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -845,7 +852,11 @@ impl InsightGenerator {
|
||||
if !tag_names.is_empty() {
|
||||
parts.push(format!("tags: {}", tag_names.join(", ")));
|
||||
}
|
||||
if parts.is_empty() { None } else { Some(parts.join(". ")) }
|
||||
if parts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(parts.join(". "))
|
||||
}
|
||||
};
|
||||
|
||||
let mut search_enrichment: Option<String> = enriched_query.clone();
|
||||
@@ -900,7 +911,11 @@ impl InsightGenerator {
|
||||
if !tag_names.is_empty() {
|
||||
parts.push(format!("tags: {}", tag_names.join(", ")));
|
||||
}
|
||||
if parts.is_empty() { None } else { Some(parts.join(". ")) }
|
||||
if parts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(parts.join(". "))
|
||||
}
|
||||
};
|
||||
|
||||
// Step 3: Try historical RAG (>30 days ago) using extracted topics
|
||||
@@ -980,7 +995,14 @@ impl InsightGenerator {
|
||||
log::info!("No immediate messages found, trying basic RAG as fallback");
|
||||
// Fallback to basic RAG even without strong query
|
||||
match self
|
||||
.find_relevant_messages_rag(date_taken, None, contact.as_deref(), None, 20, enriched_query.as_deref())
|
||||
.find_relevant_messages_rag(
|
||||
date_taken,
|
||||
None,
|
||||
contact.as_deref(),
|
||||
None,
|
||||
20,
|
||||
enriched_query.as_deref(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(rag_messages) if !rag_messages.is_empty() => {
|
||||
@@ -1399,11 +1421,7 @@ Return ONLY the summary, nothing else."#,
|
||||
Ok(d) => d,
|
||||
Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e),
|
||||
};
|
||||
let timestamp = date
|
||||
.and_hms_opt(12, 0, 0)
|
||||
.unwrap()
|
||||
.and_utc()
|
||||
.timestamp();
|
||||
let timestamp = date.and_hms_opt(12, 0, 0).unwrap().and_utc().timestamp();
|
||||
|
||||
log::info!(
|
||||
"tool_get_sms_messages: date={}, contact='{}', days_radius={}",
|
||||
@@ -1442,7 +1460,11 @@ Return ONLY the summary, nothing else."#,
|
||||
format!("[{}] {}: {}", ts, sender, m.body)
|
||||
})
|
||||
.collect();
|
||||
format!("Found {} messages:\n{}", messages.len(), formatted.join("\n"))
|
||||
format!(
|
||||
"Found {} messages:\n{}",
|
||||
messages.len(),
|
||||
formatted.join("\n")
|
||||
)
|
||||
}
|
||||
Ok(_) => "No messages found.".to_string(),
|
||||
Err(e) => format!("Error fetching SMS messages: {}", e),
|
||||
@@ -1468,11 +1490,7 @@ Return ONLY the summary, nothing else."#,
|
||||
Ok(d) => d,
|
||||
Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e),
|
||||
};
|
||||
let timestamp = date
|
||||
.and_hms_opt(12, 0, 0)
|
||||
.unwrap()
|
||||
.and_utc()
|
||||
.timestamp();
|
||||
let timestamp = date.and_hms_opt(12, 0, 0).unwrap().and_utc().timestamp();
|
||||
|
||||
log::info!(
|
||||
"tool_get_calendar_events: date={}, days_radius={}",
|
||||
@@ -1541,11 +1559,7 @@ Return ONLY the summary, nothing else."#,
|
||||
Ok(d) => d,
|
||||
Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e),
|
||||
};
|
||||
let timestamp = date
|
||||
.and_hms_opt(12, 0, 0)
|
||||
.unwrap()
|
||||
.and_utc()
|
||||
.timestamp();
|
||||
let timestamp = date.and_hms_opt(12, 0, 0).unwrap().and_utc().timestamp();
|
||||
|
||||
log::info!(
|
||||
"tool_get_location_history: date={}, days_radius={}",
|
||||
@@ -1805,12 +1819,10 @@ Return ONLY the summary, nothing else."#,
|
||||
|
||||
// 2a. Verify the model exists on at least one server before checking capabilities
|
||||
if let Some(ref model_name) = custom_model {
|
||||
let available_on_primary = OllamaClient::is_model_available(
|
||||
&ollama_client.primary_url,
|
||||
model_name,
|
||||
)
|
||||
.await
|
||||
.unwrap_or(false);
|
||||
let available_on_primary =
|
||||
OllamaClient::is_model_available(&ollama_client.primary_url, model_name)
|
||||
.await
|
||||
.unwrap_or(false);
|
||||
|
||||
let available_on_fallback = if let Some(ref fallback_url) = ollama_client.fallback_url {
|
||||
OllamaClient::is_model_available(fallback_url, model_name)
|
||||
@@ -2002,28 +2014,28 @@ Return ONLY the summary, nothing else."#,
|
||||
|
||||
messages.push(response.clone());
|
||||
|
||||
if let Some(ref tool_calls) = response.tool_calls {
|
||||
if !tool_calls.is_empty() {
|
||||
for tool_call in tool_calls {
|
||||
log::info!(
|
||||
"Agentic tool call [{}]: {} {:?}",
|
||||
iteration,
|
||||
tool_call.function.name,
|
||||
tool_call.function.arguments
|
||||
);
|
||||
let result = self
|
||||
.execute_tool(
|
||||
&tool_call.function.name,
|
||||
&tool_call.function.arguments,
|
||||
&ollama_client,
|
||||
&image_base64,
|
||||
&loop_cx,
|
||||
)
|
||||
.await;
|
||||
messages.push(ChatMessage::tool_result(result));
|
||||
}
|
||||
continue;
|
||||
if let Some(ref tool_calls) = response.tool_calls
|
||||
&& !tool_calls.is_empty()
|
||||
{
|
||||
for tool_call in tool_calls {
|
||||
log::info!(
|
||||
"Agentic tool call [{}]: {} {:?}",
|
||||
iteration,
|
||||
tool_call.function.name,
|
||||
tool_call.function.arguments
|
||||
);
|
||||
let result = self
|
||||
.execute_tool(
|
||||
&tool_call.function.name,
|
||||
&tool_call.function.arguments,
|
||||
&ollama_client,
|
||||
&image_base64,
|
||||
&loop_cx,
|
||||
)
|
||||
.await;
|
||||
messages.push(ChatMessage::tool_result(result));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// No tool calls — this is the final answer
|
||||
@@ -2033,13 +2045,14 @@ Return ONLY the summary, nothing else."#,
|
||||
|
||||
// If loop exhausted without final answer, ask for one
|
||||
if final_content.is_empty() {
|
||||
log::info!("Agentic loop exhausted after {} iterations, requesting final answer", iterations_used);
|
||||
log::info!(
|
||||
"Agentic loop exhausted after {} iterations, requesting final answer",
|
||||
iterations_used
|
||||
);
|
||||
messages.push(ChatMessage::user(
|
||||
"Based on the context gathered, please write the final photo insight: a title and a detailed personal summary. Write in first person as Cameron.",
|
||||
));
|
||||
let final_response = ollama_client
|
||||
.chat_with_tools(messages, vec![])
|
||||
.await?;
|
||||
let final_response = ollama_client.chat_with_tools(messages, vec![]).await?;
|
||||
final_content = final_response.content;
|
||||
}
|
||||
|
||||
@@ -2179,18 +2192,29 @@ mod tests {
|
||||
Some("vacation, hiking, mountains".to_string()),
|
||||
);
|
||||
assert!(result.contains("## Tags"), "Should include Tags section");
|
||||
assert!(result.contains("vacation, hiking, mountains"), "Should include tag names");
|
||||
assert!(
|
||||
result.contains("vacation, hiking, mountains"),
|
||||
"Should include tag names"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn combine_contexts_omits_tags_section_when_no_tags() {
|
||||
let result = InsightGenerator::combine_contexts(
|
||||
Some("some messages".to_string()),
|
||||
None, None, None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None, // no tags
|
||||
);
|
||||
assert!(!result.contains("## Tags"), "Should not include Tags section when None");
|
||||
assert!(result.contains("## Messages"), "Should still include Messages");
|
||||
assert!(
|
||||
!result.contains("## Tags"),
|
||||
"Should not include Tags section when None"
|
||||
);
|
||||
assert!(
|
||||
result.contains("## Messages"),
|
||||
"Should still include Messages"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user