From 5704fbacb9acb8f0f302970a47489e38f1626443 Mon Sep 17 00:00:00 2001 From: Kristian Ivanov Date: Tue, 11 Jun 2024 23:20:11 +0300 Subject: [PATCH 1/4] ChatService update --- src/server/CookingApp/Services/ChatService/ChatService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/CookingApp/Services/ChatService/ChatService.cs b/src/server/CookingApp/Services/ChatService/ChatService.cs index 82fa9320..eb66482a 100644 --- a/src/server/CookingApp/Services/ChatService/ChatService.cs +++ b/src/server/CookingApp/Services/ChatService/ChatService.cs @@ -1,6 +1,8 @@ namespace CookingApp.Services.ChatHistory { using CookingApp.Infrastructure.Interfaces; + using CookingApp.Models.DTOs; + using System.Text.Json; public class ChatService : IChatService { From c72b095ed1576040c9b1ccb972a31927cbebf64b Mon Sep 17 00:00:00 2001 From: Kristian Ivanov Date: Wed, 12 Jun 2024 21:47:14 +0300 Subject: [PATCH 2/4] Updated the ChatService --- .../CookingApp/Services/ChatService/ChatService.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/server/CookingApp/Services/ChatService/ChatService.cs b/src/server/CookingApp/Services/ChatService/ChatService.cs index 5ebbd7f8..977ea6fe 100644 --- a/src/server/CookingApp/Services/ChatService/ChatService.cs +++ b/src/server/CookingApp/Services/ChatService/ChatService.cs @@ -9,23 +9,19 @@ using CookingApp.Infrastructure.Interfaces; using CookingApp.Models.DTOs; using System.Text.Json; - using CookingApp.Models; public class ChatService : IChatService { private readonly IRepository _chatRepository; private readonly ILogger _logger; - private readonly IChatService _chatService; private readonly IOpenAIService _openAIService; public ChatService(IOpenAIService openAIService, IRepository userRepo, - IChatService chatService, ILogger logger, IRepository chatRepository) { _openAIService = openAIService; - _chatService = chatService; _logger = logger; _chatRepository = chatRepository; } @@ -110,7 +106,7 @@ public async Task UpdateChat(string request, strin { try { - var userChat = await _chatService.GetByIdAsync(chatId); + var userChat = await GetByIdAsync(chatId); var completionResult = await _openAIService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest { @@ -173,7 +169,7 @@ private async Task CreateNewChat(ChatCompletionCreateResponse completionResult, Responses = new List() }; - await _chatService.InsertAsync(chat); + await InsertAsync(chat); } private async Task GenerateTitle(string message) @@ -208,7 +204,7 @@ private async void UpdateUserChat(Chat? userChat, string? request, string? respo { userChat?.Requests.Add(CreateNewRequest(request)); userChat?.Responses.Add(CreateNewResponse(response)); - await _chatService.UpdateAsync(userChat); + await UpdateAsync(userChat); } } } From 9249d008862b7999e236960bf75aafa8f80e2fe3 Mon Sep 17 00:00:00 2001 From: Kristian Ivanov Date: Wed, 12 Jun 2024 21:53:32 +0300 Subject: [PATCH 3/4] Updated ChatController --- src/server/CookingApp/Controllers/ChatController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/CookingApp/Controllers/ChatController.cs b/src/server/CookingApp/Controllers/ChatController.cs index 1b26b12a..16df5068 100644 --- a/src/server/CookingApp/Controllers/ChatController.cs +++ b/src/server/CookingApp/Controllers/ChatController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; [ApiController] + [AllowAnonymous] public class ChatController : ControllerBase { private readonly IChatService _chatService; From 174c8a6a45b283e5773e26f9fb42a5f788a849c1 Mon Sep 17 00:00:00 2001 From: Kristian Ivanov Date: Wed, 12 Jun 2024 22:16:39 +0300 Subject: [PATCH 4/4] Fixed ChatService call to ChatGPT API. --- src/server/CookingApp/Controllers/ChatController.cs | 4 ++-- src/server/CookingApp/Services/ChatService/ChatService.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/server/CookingApp/Controllers/ChatController.cs b/src/server/CookingApp/Controllers/ChatController.cs index 16df5068..99615469 100644 --- a/src/server/CookingApp/Controllers/ChatController.cs +++ b/src/server/CookingApp/Controllers/ChatController.cs @@ -1,7 +1,6 @@ namespace CookingApp.Controllers { using CookingApp.Common; - using CookingApp.Models.DTOs; using CookingApp.Services.ChatHistory; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -28,7 +27,8 @@ public async Task GetChats() return Ok(chats); } - [HttpPost("chat-request")] + [HttpPost] + [Route("chat-request")] public async Task SendQuery([FromBody] string message, [FromHeader] string? chatId = null) { try diff --git a/src/server/CookingApp/Services/ChatService/ChatService.cs b/src/server/CookingApp/Services/ChatService/ChatService.cs index 977ea6fe..f53ba485 100644 --- a/src/server/CookingApp/Services/ChatService/ChatService.cs +++ b/src/server/CookingApp/Services/ChatService/ChatService.cs @@ -17,7 +17,6 @@ public class ChatService : IChatService private readonly IOpenAIService _openAIService; public ChatService(IOpenAIService openAIService, - IRepository userRepo, ILogger logger, IRepository chatRepository) {