Include transaction name in receipt parsing prompt
Pass the transaction name from the bank statement to OpenAI when parsing receipts. This helps identify merchants when receipts have cryptic or unclear merchant names (e.g., Arby's receipts). The transaction name is included as additional context in the prompt: "This transaction was recorded as 'XXX' in the bank statement, which may help identify the merchant if the receipt is unclear." 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -88,8 +88,9 @@ namespace MoneyMap.Services
|
||||
mediaType = receipt.ContentType;
|
||||
}
|
||||
|
||||
// Call OpenAI Vision API
|
||||
var parseData = await CallOpenAIVisionAsync(apiKey, base64Data, mediaType);
|
||||
// Call OpenAI Vision API with transaction name context
|
||||
var transactionName = receipt.Transaction?.Name;
|
||||
var parseData = await CallOpenAIVisionAsync(apiKey, base64Data, mediaType, transactionName);
|
||||
|
||||
// Update receipt with parsed data
|
||||
receipt.Merchant = parseData.Merchant;
|
||||
@@ -172,22 +173,10 @@ namespace MoneyMap.Services
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<ParsedReceiptData> CallOpenAIVisionAsync(string apiKey, string base64Image, string mediaType)
|
||||
private async Task<ParsedReceiptData> CallOpenAIVisionAsync(string apiKey, string base64Image, string mediaType, string? transactionName = null)
|
||||
{
|
||||
var requestBody = new
|
||||
{
|
||||
model = "gpt-4o-mini",
|
||||
messages = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
role = "user",
|
||||
content = new object[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "text",
|
||||
text = @"Analyze this receipt image and extract the following information as JSON:
|
||||
// Build the prompt with optional transaction context
|
||||
var promptText = @"Analyze this receipt image and extract the following information as JSON:
|
||||
{
|
||||
""merchant"": ""store name"",
|
||||
""receiptDate"": ""YYYY-MM-DD"" (or null if not found),
|
||||
@@ -211,9 +200,29 @@ Extract all line items you can see on the receipt. For each item:
|
||||
- unitPrice: Price per unit if quantity applies, otherwise null
|
||||
- lineTotal: The total amount for this line (required)
|
||||
|
||||
For utility bills, service charges, fees, and taxes - these are NOT products with quantities, so set quantity and unitPrice to null.
|
||||
For utility bills, service charges, fees, and taxes - these are NOT products with quantities, so set quantity and unitPrice to null.";
|
||||
|
||||
Respond ONLY with valid JSON, no other text."
|
||||
if (!string.IsNullOrWhiteSpace(transactionName))
|
||||
{
|
||||
promptText += $"\n\nNote: This transaction was recorded as \"{transactionName}\" in the bank statement, which may help identify the merchant if the receipt is unclear.";
|
||||
}
|
||||
|
||||
promptText += "\n\nRespond ONLY with valid JSON, no other text.";
|
||||
|
||||
var requestBody = new
|
||||
{
|
||||
model = "gpt-4o-mini",
|
||||
messages = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
role = "user",
|
||||
content = new object[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "text",
|
||||
text = promptText
|
||||
},
|
||||
new
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user