feat: Enhance AI response generation and improve email content extraction with detailed logging

This commit is contained in:
2025-05-29 19:47:39 +02:00
parent 8637827f2f
commit 1756f3462b
2 changed files with 75 additions and 8 deletions

View File

@@ -89,7 +89,8 @@ func (a *AI) GenerateReply(emailContent string, contextContent map[string]string
// Prepare the system message with language-specific instruction
systemMsg := fmt.Sprintf(`You are a helpful assistant who responds to emails.
Your primary goal is to answer the user's query based on the provided email and context.
Your primary goal is to answer the user's query (found in the 'Email Body') by primarily using the information available in the 'Additional Context' and your general knowledge.
While the 'Email Body' provides the question, your answer should be synthesized from the context and your understanding, not by directly repeating or solely relying on unverified information from the 'Email Body' itself.
Instructions:
- Language: Your response must be entirely in %s, regardless of the language used in the email content or context.
@@ -108,7 +109,13 @@ Instructions:
{Role: "user", Content: userMsg},
}
return a.makeAPIRequest(messages)
aiResponse, err := a.makeAPIRequest(messages)
if err != nil {
// Error already logged by makeAPIRequest, just propagate
return "", err
}
logger.WithField("rawAIResponse", aiResponse).Debug("Received raw response from AI")
return aiResponse, nil
}
func (a *AI) makeAPIRequest(messages []Message) (string, error) {