Skip to content

Commit

Permalink
Update CoreClient library with new message rating endpoint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhulen committed Dec 12, 2024
1 parent 44c6304 commit 43e68d4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public async Task<IEnumerable<Conversation>> GetAllChatSessionsAsync()
}

/// <inheritdoc/>
public async Task<Message> RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating)
public async Task RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating)
{
if (string.IsNullOrWhiteSpace(sessionId))
{
Expand All @@ -149,10 +149,6 @@ public async Task<Message> RateMessageAsync(string sessionId, string messageId,
{
throw new Exception($"Failed to rate message. Status code: {responseMessage.StatusCode}. Reason: {responseMessage.ReasonPhrase}");
}

var responseContent = await responseMessage.Content.ReadAsStringAsync();
var message = JsonSerializer.Deserialize<Message>(responseContent, SerializerOptions);
return message ?? throw new InvalidOperationException("The returned Message is invalid.");
}

/// <inheritdoc/>
Expand Down
5 changes: 2 additions & 3 deletions src/dotnet/CoreClient/CoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ public async Task<string> CreateChatSessionAsync(ChatSessionProperties chatSessi
return sessionId;
}

public async Task<Message> RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating)
public async Task RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating)
{
if (string.IsNullOrWhiteSpace(sessionId))
throw new ArgumentException("A session ID must be provided when rating a message.");
if (string.IsNullOrWhiteSpace(messageId))
throw new ArgumentException("A message ID must be provided when rating a message.");
if (rating == null)
throw new ArgumentException("A rating must be provided when rating a message.");
var message = await _coreRestClient.Sessions.RateMessageAsync(sessionId, messageId, rating);
return message;
await _coreRestClient.Sessions.RateMessageAsync(sessionId, messageId, rating);
}

/// <inheritdoc/>
Expand Down
3 changes: 1 addition & 2 deletions src/dotnet/CoreClient/Interfaces/ICoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ Task<Message> AttachFileAndAskQuestionAsync(Stream fileStream, string fileName,
/// <param name="sessionId">The chat session ID that contains the message to rate.</param>
/// <param name="messageId">The ID of the message to rate.</param>
/// <param name="rating">The rating and optional comments to assign to the message.</param>
/// <returns>Returns the Message object, including its updated rating.</returns>
Task<Message> RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating);
Task RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating);

/// <summary>
/// Retrieves agents available to the user for orchestration and session-based requests.
Expand Down
3 changes: 1 addition & 2 deletions src/dotnet/CoreClient/Interfaces/ISessionRESTClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public interface ISessionRESTClient
/// <param name="sessionId">The chat session ID that contains the message to rate.</param>
/// <param name="messageId">The ID of the message to rate.</param>
/// <param name="rating">The rating and optional comments to assign to the message.</param>
/// <returns>Returns the Message object, including its updated rating.</returns>
Task<Message> RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating);
Task RateMessageAsync(string sessionId, string messageId, MessageRatingRequest rating);

/// <summary>
/// Creates a new session with the specified name.
Expand Down
19 changes: 2 additions & 17 deletions tests/dotnet/Core.Client.Tests/CoreClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task CreateChatSessionAsync_WithName_CreatesAndRenamesSession()
}

[Fact]
public async Task RateMessageAsync_ShouldReturnMessage_WhenSuccessful()
public async Task RateMessageAsync_ShouldSucceed()
{
// Arrange
var sessionId = "test-session-id";
Expand All @@ -47,26 +47,11 @@ public async Task RateMessageAsync_ShouldReturnMessage_WhenSuccessful()
Rating = true,
Comments = "Great response!"
};
var expectedMessage = new Message
{
Id = messageId,
RatingComments = "This is a test message.",
Rating = ratingRequest.Rating
};

_coreRestClient.Sessions
.RateMessageAsync(sessionId, messageId, ratingRequest)
.Returns(Task.FromResult(expectedMessage));

// Act
var result = await _coreClient.RateMessageAsync(sessionId, messageId, ratingRequest);
await _coreClient.RateMessageAsync(sessionId, messageId, ratingRequest);

// Assert
Assert.NotNull(result);
Assert.Equal(expectedMessage.Id, result.Id);
Assert.Equal(expectedMessage.RatingComments, result.RatingComments);
Assert.Equal(expectedMessage.Rating, result.Rating);

await _coreRestClient.Sessions.Received(1).RateMessageAsync(sessionId, messageId, ratingRequest);
}

Expand Down

0 comments on commit 43e68d4

Please sign in to comment.