| @@ -1,4 +1,5 @@ | |||
| using Microsoft.AspNetCore.Http; | |||
| using DocumentFormat.OpenXml.Office2010.Excel; | |||
| using Microsoft.AspNetCore.Http; | |||
| using Microsoft.AspNetCore.Mvc; | |||
| using ReAct_PME.Application; | |||
| using ReAct_PME.Domain; | |||
| @@ -37,6 +38,14 @@ namespace ReAct_PME_API.Controllers | |||
| return Ok(rep); | |||
| } | |||
| [HttpGet("conversation/{idConv}")] | |||
| public async Task<ActionResult> GetConversation(string idConv) | |||
| { | |||
| Guid Id = Guid.Parse(idConv); | |||
| var item = await service.GetConversation(Id, dt_conversationService); | |||
| return Ok(item); | |||
| } | |||
| [HttpGet("conversations/{idWF}/{typeLLM}")] | |||
| public async Task<ActionResult> GetConversations(string idWF, int typeLLM) | |||
| { | |||
| @@ -14,6 +14,7 @@ namespace ReAct_PME.Application | |||
| Task<string> EnvoiRequete_RAG(List<string> requete, IDT_CONVERSATIONService dt_conversationService, IDT_CONVERSATION_LIGNEService dt_conversation_ligneService, IDT_WORK_FORCEService dt_work_forceService); | |||
| Task<List<string>> ListeDomaines_RAG(); | |||
| Task<List<ConversationDto>?> GetConversations(Guid Id, IDT_CONVERSATIONService dt_conversationService); | |||
| Task<ConversationDto?> GetConversation(Guid IdConv, IDT_CONVERSATIONService dt_conversationService); | |||
| Task<MessageDto> EnvoiRequete_LLM(SendMessageRequest requete, IDT_CONVERSATIONService dt_conversationService, IDT_CONVERSATION_LIGNEService dt_conversation_ligneService, IDT_WORK_FORCEService dt_work_forceService); | |||
| Task<MessageDto> EnvoiRequete_RAG(SendMessageRequest requete, IDT_CONVERSATIONService dt_conversationService, IDT_CONVERSATION_LIGNEService dt_conversation_ligneService, IDT_WORK_FORCEService dt_work_forceService); | |||
| @@ -225,6 +225,63 @@ namespace ReAct_PME.Application | |||
| return null; | |||
| } | |||
| public async Task<ConversationDto?> GetConversation(Guid IdConv, IDT_CONVERSATIONService dt_conversationService) | |||
| { | |||
| var oneConv = await dt_conversationService.GetById_Async(IdConv); | |||
| if (oneConv != null) | |||
| { | |||
| ConversationDto conv = new(); | |||
| conv.Id = oneConv.ID_CONVERSATION.ToString(); | |||
| conv.IdWorkForce = oneConv.ID_WORK_FORCE.ToString(); | |||
| conv.TypeConv = oneConv.TypeConv; | |||
| conv.Date = oneConv.DATE_START; | |||
| conv.Title = oneConv.LIBELLE; | |||
| if (oneConv.DT_CONVERSATION_LIGNEs != null && oneConv.DT_CONVERSATION_LIGNEs.Count > 0) | |||
| { | |||
| var lstMessageOrder = oneConv.DT_CONVERSATION_LIGNEs.Where(m => m.IsEnabled == true).OrderBy(c => c.DATE).ToList(); | |||
| var lstMsg = new List<MessageDto>(); | |||
| foreach (var oneMessage in lstMessageOrder!) | |||
| { | |||
| MessageDto msg = new(); | |||
| msg.Id = oneMessage.ID_CONVERSATION_LIGNE.ToString(); | |||
| msg.Role = "user"; | |||
| //msg.Content = oneMessage.QUESTION; | |||
| msg.Model = oneMessage.MODELE!; | |||
| msg.IsUser = true; | |||
| msg.Text = oneMessage.QUESTION; | |||
| msg.CreatedAt = oneMessage.DATE; | |||
| lstMsg.Add(msg); | |||
| MessageDto msg2 = new(); | |||
| msg2.Id = oneMessage.ID_CONVERSATION_LIGNE.ToString(); | |||
| msg2.Role = "assistant"; | |||
| //msg2.Content = oneMessage.REPONSE; | |||
| msg2.Model = oneMessage.MODELE!; | |||
| msg2.IsUser = false; | |||
| msg2.Text = oneMessage.REPONSE; | |||
| msg2.CreatedAt = oneMessage.DATE; | |||
| lstMsg.Add(msg2); | |||
| } | |||
| conv.Messages = lstMsg; | |||
| } | |||
| return conv; | |||
| } | |||
| return null; | |||
| } | |||
| public async Task<MessageDto> EnvoiRequete_LLM(SendMessageRequest requete, IDT_CONVERSATIONService dt_conversationService, IDT_CONVERSATION_LIGNEService dt_conversation_ligneService, IDT_WORK_FORCEService dt_work_forceService) | |||
| { | |||
| var lst = new List<ChatMessage>(); | |||
| @@ -270,7 +270,7 @@ | |||
| private void OnSelectConversation(string conversationId, int typeLLM) | |||
| { | |||
| Navigation.NavigateTo($"chatroom_base/{typeLLM}/{conversationId}", true); | |||
| Navigation.NavigateTo($"chatroom_base/{typeLLM}/{conversationId}"); | |||
| } | |||
| private void NavigateTo(string route) | |||
| @@ -7,6 +7,7 @@ using Microsoft.JSInterop; | |||
| using ReAct_PME.Domain; | |||
| using ReAct_PME.WebUI.ServicesUI; | |||
| using System.Net.Http.Json; | |||
| using System.Runtime.CompilerServices; | |||
| using System.Text.Json; | |||
| @@ -53,10 +54,55 @@ namespace ReAct_PME.WebUI.Pages.ChatRoom | |||
| private bool IsNewConversation = false; | |||
| public bool hiddenDomain = true; | |||
| protected override async Task OnParametersSetAsync() | |||
| { | |||
| await LoadConversations(); | |||
| if (TypeLLM == 1) | |||
| { | |||
| SelectedMode = "llm"; | |||
| IsWithHistorique = true; | |||
| } | |||
| else if (TypeLLM == 2) | |||
| { | |||
| SelectedMode = "rag"; | |||
| IsWithHistorique = false; | |||
| hiddenDomain = false; | |||
| await LoadRagDomains(); | |||
| SelectedDomain = RagDomains[0]; | |||
| } | |||
| else if (TypeLLM == 3) | |||
| { | |||
| SelectedMode = "code"; | |||
| IsWithHistorique = true; | |||
| } | |||
| else if (TypeLLM == 4) | |||
| { | |||
| SelectedMode = "image"; | |||
| IsWithHistorique = false; | |||
| } | |||
| else | |||
| { | |||
| SelectedMode = "llm"; | |||
| IsWithHistorique = true; | |||
| } | |||
| var uri = new Uri(Navigation.Uri); | |||
| if (!string.IsNullOrEmpty(ConversationId)) | |||
| { | |||
| SelectConversation(ConversationId); | |||
| } | |||
| else | |||
| { | |||
| Console.WriteLine("No conversationId in URL"); | |||
| // IsNewConversation reste false par défaut | |||
| } | |||
| StateHasChanged(); | |||
| } | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| #region Vérification si utilisateur est connecté et s'il a les droits | |||
| var tok = await PagesInitializer.VerifConnexionAndRules(AuthenticationStateProvider, Navigation, Http, ToastService, "/api/ChatRoom/llm/test"); | |||
| if (tok == null || tok.Length == 0) | |||
| return; | |||
| @@ -66,10 +112,10 @@ namespace ReAct_PME.WebUI.Pages.ChatRoom | |||
| #endregion | |||
| await LoadConversations(); | |||
| //await LoadConversations(); | |||
| //await LoadOllamaModels(); | |||
| /* | |||
| if (TypeLLM == 1) | |||
| { | |||
| SelectedMode = "llm"; | |||
| @@ -110,6 +156,7 @@ namespace ReAct_PME.WebUI.Pages.ChatRoom | |||
| Console.WriteLine("No conversationId in URL"); | |||
| // IsNewConversation reste false par défaut | |||
| } | |||
| */ | |||
| } | |||
| private async Task UploadDocuments(InputFileChangeEventArgs e) | |||
| @@ -137,10 +184,19 @@ namespace ReAct_PME.WebUI.Pages.ChatRoom | |||
| private async Task LoadConversations() | |||
| { | |||
| var oneConversation = await Http.GetFromJsonAsync<ConversationDto>($"/api/ChatRoom/conversation/{ConversationId}") | |||
| ?? new(); | |||
| Conversations = new(); | |||
| Conversations.Add(oneConversation); | |||
| /* | |||
| Conversations = await Http.GetFromJsonAsync<List<ConversationDto>>($"/api/ChatRoom/conversations/{AuthService.ID}/{TypeLLM}") | |||
| ?? new(); | |||
| Conversations = Conversations.OrderByDescending(c => c.Messages.Any() ? c.Messages.Max(m => m.CreatedAt) : DateTime.MinValue).ToList(); | |||
| */ | |||
| StateHasChanged(); | |||
| } | |||