Mango.Nop.Plugins/Nop.Plugin.Misc.AIPlugin/Services/AICalculationService.cs

46 lines
2.3 KiB
C#

using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Plugin.Misc.FruitBankPlugin.Helpers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Services
{
public class AICalculationService
{
private readonly CerebrasAPIService _cerebrasApiService;
private readonly OpenAIApiService _openAIApiService;
private readonly IStoreContext _storeContext;
public AICalculationService(CerebrasAPIService cerebrasApiService, IStoreContext storeContext, OpenAIApiService openAIApiService)
{
_cerebrasApiService = cerebrasApiService;
_storeContext = storeContext;
_openAIApiService = openAIApiService;
}
public async Task<string> GetWelcomeMessageAsync(Customer customer)
{
var store = await _storeContext.GetCurrentStoreAsync();
var storeName = store.Name;
var storeCompanyName = store.CompanyName;
var systemMessage = $"You are a helpful assistant of a webshop called {storeName}, of the company {storeCompanyName}, you work in the administration area, with the ADMIN user. The ADMIN user is {customer.FirstName}. Date and time is {DateTime.Now} When the user greets you, answer with a warm HUNGARIAN welcome message, incorporating some reference of the time, and maybe the weather too, making it pleasant for the ADMIN user to start working with the shop system. Assure the user that AI connection is established and you are ready to assist them.";
const string userMessage = "Hello";
var response = await _openAIApiService.GetSimpleResponseAsync(systemMessage, userMessage) ?? string.Empty;
return response;
}
public async Task<string> GetOpenAIPDFAnalysisFromText(string pdfText, string userQuestion)
{
var systemMessage = $"You are a pdf analyzis assistant of FRUITBANK, the user is asking you questions about a PDF document, that you have access to. The content of the PDF document is the following: {pdfText}";
var response = await _openAIApiService.GetSimpleResponseAsync(systemMessage, userQuestion);
if (response == null) return string.Empty;
var fixedResponse = TextHelper.FixJsonWithoutAI(response);
return fixedResponse;
}
}
}