72 lines
3.6 KiB
C#
72 lines
3.6 KiB
C#
using Azure;
|
|
using Nop.Core;
|
|
using Nop.Core.Domain.Customers;
|
|
using Nop.Core.Domain.Stores;
|
|
using Nop.Plugin.Misc.FruitBankPlugin.Helpers;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
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;
|
|
string 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.";
|
|
|
|
string userMessage = "Hello";
|
|
|
|
var response = await _openAIApiService.GetSimpleResponseAsync(systemMessage, userMessage);
|
|
return response;
|
|
}
|
|
|
|
//public async Task<string> GetOpenAIPDFAnalyzisFromText(string pdfText, string userQuestion)
|
|
//{
|
|
// string systemMessage = $"You are a helpful assistant of a webshop, you work in the administration area, with the ADMIN user. The ADMIN 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);
|
|
|
|
// var fixedResponse = TextHelper.FixJsonWithoutAI(response);
|
|
|
|
// return fixedResponse;
|
|
//}
|
|
|
|
public async Task<string> GetOpenAIPDFAnalysisFromText(string pdfText, string userQuestion)
|
|
{
|
|
string systemMessage = $"You are a pdf analyzis assistant, 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);
|
|
|
|
var fixedResponse = TextHelper.FixJsonWithoutAI(response);
|
|
|
|
return fixedResponse;
|
|
}
|
|
|
|
//public async Task<string> GetOpenAIPartnerInfoFromText(string pdfText, string userQuestion)
|
|
//{
|
|
// string systemMessage = $"You are a pdf analyzis assistant, 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);
|
|
|
|
// var fixedResponse = TextHelper.FixJsonWithoutAI(response);
|
|
|
|
// return fixedResponse;
|
|
//}
|
|
|
|
}
|
|
}
|