Compare commits

..

No commits in common. "889c368a462defc6aeba6fe577a47b3d855ed4d2" and "9bc7d4a27e666eb792d6ef8f4f14419eca091405" have entirely different histories.

5 changed files with 630 additions and 682 deletions

View File

@ -14,7 +14,6 @@ using Nop.Plugin.Misc.FruitBankPlugin.Helpers;
using Nop.Plugin.Misc.FruitBankPlugin.Services;
using Nop.Plugin.Misc.FruitBankPlugin.Services.FileStorage;
using Nop.Services.Catalog;
using Nop.Services.Common;
using Nop.Services.Security;
using Nop.Web.Framework;
using Nop.Web.Framework.Controllers;
@ -32,37 +31,31 @@ namespace Nop.Plugin.Misc.FruitBank.Controllers
{
private readonly IPermissionService _permissionService;
private readonly OpenAIApiService _aiApiService;
private readonly CerebrasAPIService _cerebrasApiService;
private readonly AICalculationService _aiCalculationService;
private readonly IProductService _productService;
private readonly FruitBankDbContext _dbContext;
private readonly PdfToImageService _pdfToImageService;
private readonly IWorkContext _workContext;
private readonly FileStorageService _fileStorageService;
private readonly FruitBankAttributeService _fruitBankAttributeService;
public FileManagerController(
IPermissionService permissionService,
OpenAIApiService aiApiService,
CerebrasAPIService cerebrasApiService,
AICalculationService aiCalculationService,
IProductService productService,
FruitBankDbContext fruitBankDbContext,
PdfToImageService pdfToImageService,
IWorkContext workContext,
FileStorageService fileStorageService,
FruitBankAttributeService fruitBankAttributeService)
FileStorageService fileStorageService)
{
_permissionService = permissionService;
_aiApiService = aiApiService;
_cerebrasApiService = cerebrasApiService;
_aiCalculationService = aiCalculationService;
_productService = productService;
_dbContext = fruitBankDbContext;
_pdfToImageService = pdfToImageService;
_workContext = workContext;
_fileStorageService = fileStorageService;
_fruitBankAttributeService = fruitBankAttributeService;
}
/// <summary>
@ -490,8 +483,7 @@ namespace Nop.Plugin.Misc.FruitBank.Controllers
deserializedProduct.name + "\n\n" +
"Return the best matching product name from the catalog above (matching ALL details including size/grade), or 'NONE' if no good match exists.";
//var aiMatchedProductName = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiMatchedProductName = await _cerebrasApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiMatchedProductName = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
//var aiMatchedProductName = await _aiApiService.GetSimpleResponseAsync(aiMatchPrompt, deserializedProduct.name);
Console.WriteLine($"AI matched product name for {deserializedProduct.name}: {aiMatchedProductName}");
@ -585,8 +577,7 @@ namespace Nop.Plugin.Misc.FruitBank.Controllers
deserializedProduct.name + "\n\n" +
"Return the best matching product name from the catalog above that matches ALL details (size, grade, quality), or 'NONE' if no confident match exists.";
//var aiMatchedProductName2 = await _aiApiService.GetSimpleResponseAsync(systemPrompt2, userPrompt2);
var aiMatchedProductName2 = await _cerebrasApiService.GetSimpleResponseAsync(systemPrompt2, userPrompt2);
var aiMatchedProductName2 = await _aiApiService.GetSimpleResponseAsync(systemPrompt2, userPrompt2);
Console.WriteLine($"AI matched product name from hybrid catalog for {deserializedProduct.name}: {aiMatchedProductName2}");
if (!string.IsNullOrEmpty(aiMatchedProductName2) && aiMatchedProductName2 != "NONE")
@ -746,8 +737,7 @@ namespace Nop.Plugin.Misc.FruitBank.Controllers
partnerAnalysis + "\n\n" +
"Return ONLY the numeric ID of the matching partner, or '0' if no match found.";
//var aiResponse = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiResponse = await _cerebrasApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiResponse = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
Console.WriteLine($"AI Partner Match Response: {aiResponse}");
// Parse the ID
@ -838,8 +828,7 @@ namespace Nop.Plugin.Misc.FruitBank.Controllers
"4. Return ONLY the company name, nothing else\n\n" +
"If uncertain, return the most prominent non-FruitBank company name from the document.";
//var partnerAnalysis = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var partnerAnalysis = await _cerebrasApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var partnerAnalysis = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
// Clean up the response
var cleanedPartnerName = CleanPartnerName(partnerAnalysis);
@ -1098,17 +1087,6 @@ namespace Nop.Plugin.Misc.FruitBank.Controllers
Console.WriteLine("⚠ No original file provided - skipping file save");
}
//everything done, let's update the genericattribute "IncomingQuantity" of the product
foreach (var item in shippingDocument.ShippingItems.Where(x => x.ProductId != null))
{
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, int>(
item.ProductId.Value,
"IncomingQuantity",
item.QuantityOnDocument
);
}
return Json(new
{
success = true,

View File

@ -24,7 +24,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
{
private readonly IPermissionService _permissionService;
private readonly OpenAIApiService _aiApiService;
private readonly CerebrasAPIService _cerebrasApiService;
private readonly ICustomerService _customerService;
private readonly IProductService _productService;
private readonly FruitBankDbContext _dbContext;
@ -32,14 +31,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
public VoiceOrderController(
IPermissionService permissionService,
OpenAIApiService aiApiService,
CerebrasAPIService cerebrasApiService,
ICustomerService customerService,
IProductService productService,
FruitBankDbContext dbContext)
{
_permissionService = permissionService;
_aiApiService = aiApiService;
_cerebrasApiService = cerebrasApiService;
_customerService = customerService;
_productService = productService;
_dbContext = dbContext;
@ -323,12 +320,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
transcribedText = await _aiApiService.TranscribeAudioAsync(audioStream, fileName, language, customPrompt);
}
if(transcribedText.EndsWith(".") || transcribedText.EndsWith("!") || transcribedText.EndsWith("?"))
{
//remove trailing punctuation
transcribedText = transcribedText.Substring(0, transcribedText.Length - 1);
}
// Clean up temporary file
try
{
@ -421,7 +412,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
try
{
// Get all customers with company names (increased limit)
var allCustomersWithCompany = await _customerService.GetAllCustomersAsync(); // Increased from 500 to catch more companies
var allCustomersWithCompany = await _customerService.GetAllCustomersAsync(
pageIndex: 0,
pageSize: 1000); // Increased from 500 to catch more companies
// Filter to only those with company names
var customersWithCompany = allCustomersWithCompany
@ -448,7 +441,7 @@ CRITICAL MATCHING RULES (in priority order):
2. SUBSTRING MATCH: If the search term is contained within a company name (e.g., 'Junket' in 'Junket Silver Kft.')
3. WORD MATCH: If all words from search term appear in company name (any order)
4. PARTIAL MATCH: If significant words overlap (e.g., 'Silver' matches 'Junket Silver')
5. PHONETIC SIMILARITY: How it sounds when spoken in Hungarian (e.g. 'Ökotály' should be matched to 'Öcotáj')
5. PHONETIC SIMILARITY: How it sounds when spoken
6. ABBREVIATIONS: 'SFI' matches 'SFI Rotterdam B.V.'
EXAMPLES:
@ -468,8 +461,7 @@ OUTPUT FORMAT (JSON only):
Companies:
{companyList}";
//var aiResponse = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiResponse = await _cerebrasApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiResponse = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
Console.WriteLine($"[VoiceOrder] AI company matching response: {aiResponse}");
@ -560,8 +552,7 @@ Output: [{""product"":""szőlő"",""quantity"":50}]";
var userPrompt = $"Parse this: {text}";
//var aiResponse = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiResponse = await _cerebrasApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
var aiResponse = await _aiApiService.GetSimpleResponseAsync(systemPrompt, userPrompt);
Console.WriteLine($"[VoiceOrder] AI Response: {aiResponse}");

View File

@ -333,7 +333,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services
"TaxId",
customer.VatNumber);
}
_dbContext.Customers.Update(customer, false);
}
}
}

View File

@ -840,7 +840,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services
role = "system",
content = new object[]
{
new { type = "text", text = systemPrompt },
new { type = "text", text = prompt },
}
},
new {