-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
309 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace CookingApp.Common | ||
{ | ||
public class SuccessMessages | ||
{ | ||
public class ChatGPT | ||
{ | ||
public const string ResponseSuccess = "Response received successully."; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace CookingApp.Common | ||
{ | ||
public class TaskInformationMessages | ||
{ | ||
public class ChatGPT | ||
{ | ||
public const string ConnectionAttempt = "Attempting to establish connection with ChatGPT API."; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
namespace CookingApp.Controllers | ||
{ | ||
using CookingApp.Common; | ||
using CookingApp.Models.DTOs; | ||
using CookingApp.Services.ChatHistory; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
[ApiController] | ||
public class ChatController : ControllerBase | ||
{ | ||
private readonly IChatService _chatService; | ||
private readonly ILogger<ChatController> _logger; | ||
|
||
public ChatController(IChatService chatService, ILogger<ChatController> logger) | ||
{ | ||
_chatService = chatService; | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet("chats")] | ||
public async Task<IActionResult> GetChats() | ||
{ | ||
//TODO: implement Azure Entra Id functions | ||
//var user = _userService.GetUser(); | ||
var chats = await _chatService.GetAllByUserId("user.Id"); | ||
return Ok(chats); | ||
} | ||
|
||
[HttpPost("chat-request")] | ||
public async Task<IActionResult> SendQuery([FromBody] string message, [FromHeader] string? chatId = null) | ||
{ | ||
try | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
_logger.LogInformation(TaskInformationMessages.ChatGPT.ConnectionAttempt); | ||
|
||
var result = | ||
String.IsNullOrEmpty(chatId) | ||
? await _chatService.CreateChat(message) | ||
: await _chatService.UpdateChat(message, chatId); | ||
|
||
if (result == null) | ||
{ | ||
_logger.LogError(ExceptionMessages.ChatGPT.ConnectionError); | ||
_logger.LogError(ExceptionMessages.ChatGPT.ResponseError); | ||
|
||
return NoContent(); | ||
} | ||
|
||
_logger.LogInformation(SuccessMessages.ChatGPT.ResponseSuccess); | ||
// To display the message you need to get into result.Choices[0].Message.Content. | ||
// The chat id is also contained inside the result | ||
|
||
return Ok(result); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(ExceptionMessages.ChatGPT.ConnectionError); | ||
_logger.LogError($"{e.Message}"); | ||
|
||
return BadRequest(); | ||
} | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace CookingApp.Models.DTOs | ||
{ | ||
using MongoDB.Bson.Serialization.Attributes; | ||
|
||
public class CreateChatDTO | ||
{ | ||
public string Id { get; set; } | ||
public string? Title { get; set; } | ||
|
||
public string? UserId { get; set; } | ||
|
||
public DateTime CreatedTime { get; set; } | ||
|
||
public List<Request> Requests { get; set; } = new List<Request>(); | ||
|
||
public List<Response> Responses { get; set; } = new List<Response>(); | ||
} | ||
} |
Oops, something went wrong.