diff --git a/src/llm.rs b/src/llm.rs index d0bbfbf..a219bb7 100644 --- a/src/llm.rs +++ b/src/llm.rs @@ -47,12 +47,8 @@ where log_debug!("User prompt: {}", user_prompt); // Call get_refined_message_with_provider - let result = get_refined_message_with_provider::( - llm_provider, - system_prompt, - user_prompt, - ) - .await?; + let result = + get_refined_message_with_provider::(llm_provider, system_prompt, user_prompt).await?; Ok(result) } @@ -90,7 +86,7 @@ where match serde_json::from_str::(&cleaned_message) { Ok(message) => Ok(message), Err(e) => { - log_debug!("Deserialization error: {}", e); + log_debug!("Deserialization error: {} message: {}", e, cleaned_message); Err(anyhow!("Deserialization error: {}", e)) } } @@ -205,8 +201,10 @@ pub fn get_combined_config( } fn clean_json_from_llm(json_str: &str) -> String { - // Remove potential leading/trailing whitespace - let trimmed = json_str.trim(); + // Remove potential leading/trailing whitespace and invisible characters + let trimmed = json_str + .trim_start_matches(|c: char| c.is_whitespace() || !c.is_ascii()) + .trim_end_matches(|c: char| c.is_whitespace() || !c.is_ascii()); // If wrapped in code block, remove the markers let without_codeblock = if trimmed.starts_with("```") && trimmed.ends_with("```") { diff --git a/src/prompt.rs b/src/prompt.rs index 9619158..a7229d4 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -19,7 +19,7 @@ pub fn create_system_prompt(config: &Config) -> String { 3. Capitalize the subject line. 4. Do not end the subject line with a period. 5. Separate subject from body with a blank line. - 6. Wrap the body at 72 characters. + 6. Ensure that each line of the message body does not exceed 72 characters. 7. Use the body to explain what changes were made and their impact, not how they were implemented. 8. Be specific and avoid vague language. 9. Focus on the concrete changes and their effects, not assumptions about intent. @@ -42,6 +42,9 @@ pub fn create_system_prompt(config: &Config) -> String { \"title\": \"\", \"message\": \"<message>\" } + + Be sure to quote newlines and any other control characters in your response. + The message should be based entirely on the information provided in the context, without any speculation or assumptions." );