diff --git a/src/dotnet/Common/Models/Chat/SessionProperties.cs b/src/dotnet/Common/Models/Chat/ChatSessionProperties.cs similarity index 65% rename from src/dotnet/Common/Models/Chat/SessionProperties.cs rename to src/dotnet/Common/Models/Chat/ChatSessionProperties.cs index 4650ac2cf3..97e1384bf0 100644 --- a/src/dotnet/Common/Models/Chat/SessionProperties.cs +++ b/src/dotnet/Common/Models/Chat/ChatSessionProperties.cs @@ -5,12 +5,12 @@ namespace FoundationaLLM.Common.Models.Chat /// /// The session properties object. /// - public class SessionProperties + public class ChatSessionProperties { /// /// The session name. /// - [JsonPropertyName("session_name")] - public required string SessionName { get; set; } + [JsonPropertyName("name")] + public required string Name { get; set; } } } diff --git a/src/dotnet/Core/Interfaces/ICoreService.cs b/src/dotnet/Core/Interfaces/ICoreService.cs index f5cc441036..1915ae7b0f 100644 --- a/src/dotnet/Core/Interfaces/ICoreService.cs +++ b/src/dotnet/Core/Interfaces/ICoreService.cs @@ -26,16 +26,16 @@ public interface ICoreService /// Creates a new chat session. /// /// The instance Id. - /// The session properties. - Task CreateNewChatSessionAsync(string instanceId, SessionProperties sessionProperties); + /// The session properties. + Task CreateNewChatSessionAsync(string instanceId, ChatSessionProperties chatSessionProperties); /// /// Rename the chat session from its default (eg., "New Chat") to the summary provided by OpenAI. /// /// The instance id. /// The session id to rename. - /// The session properties. - Task RenameChatSessionAsync(string instanceId, string sessionId, SessionProperties sessionProperties); + /// The session properties. + Task RenameChatSessionAsync(string instanceId, string sessionId, ChatSessionProperties chatSessionProperties); /// /// Delete a chat session and related messages. diff --git a/src/dotnet/Core/Services/CoreService.cs b/src/dotnet/Core/Services/CoreService.cs index 059afbaf83..c14b2e4bce 100644 --- a/src/dotnet/Core/Services/CoreService.cs +++ b/src/dotnet/Core/Services/CoreService.cs @@ -65,13 +65,13 @@ public async Task> GetChatSessionMessagesAsync(string instanceId, } /// - public async Task CreateNewChatSessionAsync(string instanceId, SessionProperties sessionProperties) + public async Task CreateNewChatSessionAsync(string instanceId, ChatSessionProperties chatSessionProperties) { - ArgumentException.ThrowIfNullOrEmpty(sessionProperties.SessionName); + ArgumentException.ThrowIfNullOrEmpty(chatSessionProperties.Name); Session session = new() { - Name = sessionProperties.SessionName, + Name = chatSessionProperties.Name, Type = _sessionType, UPN = _callContext.CurrentUserIdentity?.UPN ?? throw new InvalidOperationException("Failed to retrieve the identity of the signed in user when creating a new chat session.") }; @@ -79,12 +79,12 @@ public async Task CreateNewChatSessionAsync(string instanceId, SessionP } /// - public async Task RenameChatSessionAsync(string instanceId, string sessionId, SessionProperties sessionProperties) + public async Task RenameChatSessionAsync(string instanceId, string sessionId, ChatSessionProperties chatSessionProperties) { ArgumentNullException.ThrowIfNull(sessionId); - ArgumentException.ThrowIfNullOrEmpty(sessionProperties.SessionName); + ArgumentException.ThrowIfNullOrEmpty(chatSessionProperties.Name); - return await _cosmosDbService.UpdateSessionNameAsync(sessionId, sessionProperties.SessionName); + return await _cosmosDbService.UpdateSessionNameAsync(sessionId, chatSessionProperties.Name); } /// diff --git a/src/dotnet/CoreAPI/Controllers/SessionsController.cs b/src/dotnet/CoreAPI/Controllers/SessionsController.cs index b297580141..2bb45ecb18 100644 --- a/src/dotnet/CoreAPI/Controllers/SessionsController.cs +++ b/src/dotnet/CoreAPI/Controllers/SessionsController.cs @@ -68,20 +68,20 @@ public async Task GetCompletionPrompt(string instanceId, strin /// Creates a new chat session. /// /// The id of the instance. - /// The session properties. + /// The session properties. [HttpPost(Name = "CreateNewChatSession")] - public async Task CreateNewChatSession(string instanceId, [FromBody] SessionProperties sessionProperties) => - await _coreService.CreateNewChatSessionAsync(instanceId, sessionProperties); + public async Task CreateNewChatSession(string instanceId, [FromBody] ChatSessionProperties chatSessionProperties) => + await _coreService.CreateNewChatSessionAsync(instanceId, chatSessionProperties); /// /// Rename the chat session. /// /// The id of the instance. /// The id of the session to rename. - /// The session properties. + /// The session properties. [HttpPost("{sessionId}/rename", Name = "RenameChatSession")] - public async Task RenameChatSession(string instanceId, string sessionId, [FromBody] SessionProperties sessionProperties) => - await _coreService.RenameChatSessionAsync(instanceId, sessionId, sessionProperties); + public async Task RenameChatSession(string instanceId, string sessionId, [FromBody] ChatSessionProperties chatSessionProperties) => + await _coreService.RenameChatSessionAsync(instanceId, sessionId, chatSessionProperties); /// /// Delete a chat session and related messages. diff --git a/src/dotnet/CoreClient/Clients/RESTClients/SessionRESTClient.cs b/src/dotnet/CoreClient/Clients/RESTClients/SessionRESTClient.cs index 0068c62c84..4ea6a3841e 100644 --- a/src/dotnet/CoreClient/Clients/RESTClients/SessionRESTClient.cs +++ b/src/dotnet/CoreClient/Clients/RESTClients/SessionRESTClient.cs @@ -17,12 +17,12 @@ internal class SessionRESTClient( private readonly string _instanceId = instanceId ?? throw new ArgumentNullException(nameof(instanceId)); /// - public async Task CreateSessionAsync(SessionProperties sessionProperties) + public async Task CreateSessionAsync(ChatSessionProperties chatSessionProperties) { var coreClient = await GetCoreClientAsync(); var responseSession = await coreClient.PostAsync( $"instances/{_instanceId}/sessions", - JsonContent.Create(sessionProperties)); + JsonContent.Create(chatSessionProperties)); if (responseSession.IsSuccessStatusCode) { @@ -38,16 +38,16 @@ public async Task CreateSessionAsync(SessionProperties sessionProperties } /// - public async Task RenameChatSession(string sessionId, SessionProperties sessionProperties) + public async Task RenameChatSession(string sessionId, ChatSessionProperties chatSessionProperties) { var coreClient = await GetCoreClientAsync(); var response = await coreClient.PostAsync( $"instances/{_instanceId}/sessions/{sessionId}/rename", - JsonContent.Create(sessionProperties)); + JsonContent.Create(chatSessionProperties)); if (response.IsSuccessStatusCode) { - return sessionProperties.SessionName; + return chatSessionProperties.Name; } throw new Exception($"Failed to rename chat session. Status code: {response.StatusCode}. Reason: {response.ReasonPhrase}"); diff --git a/src/dotnet/CoreClient/CoreClient.cs b/src/dotnet/CoreClient/CoreClient.cs index cea16f6ffe..af77270477 100644 --- a/src/dotnet/CoreClient/CoreClient.cs +++ b/src/dotnet/CoreClient/CoreClient.cs @@ -54,29 +54,29 @@ public CoreClient( _coreRestClient = new CoreRESTClient(coreUri, credential, instanceId, options); /// - public async Task CreateChatSessionAsync(SessionProperties sessionProperties) + public async Task CreateChatSessionAsync(ChatSessionProperties chatSessionProperties) { - if (string.IsNullOrWhiteSpace(sessionProperties.SessionName)) + if (string.IsNullOrWhiteSpace(chatSessionProperties.Name)) throw new ArgumentException("A session name must be provided when creating a new session."); - var sessionId = await _coreRestClient.Sessions.CreateSessionAsync(sessionProperties); + var sessionId = await _coreRestClient.Sessions.CreateSessionAsync(chatSessionProperties); return sessionId; } /// - public async Task GetCompletionWithSessionAsync(string? sessionId, SessionProperties? sessionProperties, + public async Task GetCompletionWithSessionAsync(string? sessionId, ChatSessionProperties? chatSessionProperties, string userPrompt, string agentName) { if (string.IsNullOrWhiteSpace(sessionId)) { - if (sessionProperties == null) + if (chatSessionProperties == null) { throw new ArgumentException( "The completion request must contain a session name if no session Id is provided. " + "A new session will be created with the provided session name."); } - sessionId = await CreateChatSessionAsync(sessionProperties); + sessionId = await CreateChatSessionAsync(chatSessionProperties); } var orchestrationRequest = new CompletionRequest @@ -132,7 +132,7 @@ public async Task GetCompletionAsync(CompletionRequest completionReq /// public async Task AttachFileAndAskQuestionAsync(Stream fileStream, string fileName, string contentType, - string agentName, string question, bool useSession, string? sessionId, SessionProperties? sessionProperties) + string agentName, string question, bool useSession, string? sessionId, ChatSessionProperties? chatSessionProperties) { if (fileStream == null) { @@ -145,14 +145,14 @@ public async Task AttachFileAndAskQuestionAsync(Stream fileStream, s { if (string.IsNullOrWhiteSpace(sessionId)) { - if (sessionProperties == null) + if (chatSessionProperties == null) { throw new ArgumentException( "The completion request must contain a session name if no session Id is provided. " + "A new session will be created with the provided session name."); } - sessionId = await CreateChatSessionAsync(sessionProperties); + sessionId = await CreateChatSessionAsync(chatSessionProperties); } var orchestrationRequest = new CompletionRequest diff --git a/src/dotnet/CoreClient/Interfaces/ICoreClient.cs b/src/dotnet/CoreClient/Interfaces/ICoreClient.cs index 7149a1d5c5..d3d5a23401 100644 --- a/src/dotnet/CoreClient/Interfaces/ICoreClient.cs +++ b/src/dotnet/CoreClient/Interfaces/ICoreClient.cs @@ -16,7 +16,7 @@ public interface ICoreClient /// /// The session properties. /// The new chat session ID. - Task CreateChatSessionAsync(SessionProperties sessionProperties); + Task CreateChatSessionAsync(ChatSessionProperties sessionProperties); /// /// Runs a single completion request with an agent using the Core API and a chat session. @@ -30,7 +30,7 @@ public interface ICoreClient /// The name of the FoundationaLLM agent that will handle the /// completion request. /// A completion from the designated FoundationaLLM agent. - Task GetCompletionWithSessionAsync(string? sessionId, SessionProperties? sessionProperties, + Task GetCompletionWithSessionAsync(string? sessionId, ChatSessionProperties? sessionProperties, string userPrompt, string agentName); /// @@ -83,11 +83,11 @@ Task GetCompletionWithSessionAsync(string? sessionId, SessionPropert /// false, no session is created and the sessionless orchestration flow is used. /// The ID of an existing session. If null or empty, a new session /// is created first. - /// Optional session properties. + /// Optional session properties. /// A completion from the designated FoundationaLLM agent. /// A completion from the designated FoundationaLLM agent. Task AttachFileAndAskQuestionAsync(Stream fileStream, string fileName, string contentType, - string agentName, string question, bool useSession, string? sessionId, SessionProperties? sessionProperties); + string agentName, string question, bool useSession, string? sessionId, ChatSessionProperties? chatSessionProperties); /// /// Returns the chat messages related to an existing session. diff --git a/src/dotnet/CoreClient/Interfaces/ISessionRESTClient.cs b/src/dotnet/CoreClient/Interfaces/ISessionRESTClient.cs index 0258c0ad3a..7b20dcd538 100644 --- a/src/dotnet/CoreClient/Interfaces/ISessionRESTClient.cs +++ b/src/dotnet/CoreClient/Interfaces/ISessionRESTClient.cs @@ -25,17 +25,17 @@ public interface ISessionRESTClient /// /// Creates a new session with the specified name. /// - /// The session properties. + /// The session properties. /// Returns the new Session ID. - Task CreateSessionAsync(SessionProperties sessionProperties); + Task CreateSessionAsync(ChatSessionProperties chatSessionProperties); /// /// Renames a chat session. /// /// The chat session ID. - /// The session properties. + /// The session properties. /// - Task RenameChatSession(string sessionId, SessionProperties sessionProperties); + Task RenameChatSession(string sessionId, ChatSessionProperties chatSessionProperties); /// /// Gets a completion prompt by session ID and completion prompt ID. diff --git a/tests/dotnet/Core.Client.Tests/CoreClientTests.cs b/tests/dotnet/Core.Client.Tests/CoreClientTests.cs index 22a3997901..60233562f0 100644 --- a/tests/dotnet/Core.Client.Tests/CoreClientTests.cs +++ b/tests/dotnet/Core.Client.Tests/CoreClientTests.cs @@ -24,16 +24,16 @@ public CoreClientTests() public async Task CreateChatSessionAsync_WithName_CreatesAndRenamesSession() { // Arrange - var sessionProperties = new SessionProperties() { SessionName = "TestSession" }; + var chatSessionProperties = new ChatSessionProperties() { Name = "TestSession" }; var sessionId = "session-id"; - _coreRestClient.Sessions.CreateSessionAsync(sessionProperties).Returns(Task.FromResult(sessionId)); + _coreRestClient.Sessions.CreateSessionAsync(chatSessionProperties).Returns(Task.FromResult(sessionId)); // Act - var result = await _coreClient.CreateChatSessionAsync(sessionProperties); + var result = await _coreClient.CreateChatSessionAsync(chatSessionProperties); // Assert Assert.Equal(sessionId, result); - await _coreRestClient.Sessions.Received(1).CreateSessionAsync(sessionProperties); + await _coreRestClient.Sessions.Received(1).CreateSessionAsync(chatSessionProperties); } [Fact] @@ -42,18 +42,18 @@ public async Task GetCompletionWithSessionAsync_WithNewSession_CreatesSessionAnd // Arrange var userPrompt = "Hello, World!"; var agentName = "TestAgent"; - var sessionProperties = new SessionProperties() { SessionName = "TestSession" }; + var chatSessionProperties = new ChatSessionProperties() { Name = "TestSession" }; var sessionId = "new-session-id"; var completion = new Completion(); - _coreRestClient.Sessions.CreateSessionAsync(sessionProperties).Returns(Task.FromResult(sessionId)); + _coreRestClient.Sessions.CreateSessionAsync(chatSessionProperties).Returns(Task.FromResult(sessionId)); _coreRestClient.Completions.GetChatCompletionAsync(Arg.Any()).Returns(Task.FromResult(completion)); // Act - var result = await _coreClient.GetCompletionWithSessionAsync(null, sessionProperties, userPrompt, agentName); + var result = await _coreClient.GetCompletionWithSessionAsync(null, chatSessionProperties, userPrompt, agentName); // Assert Assert.Equal(completion, result); - await _coreRestClient.Sessions.Received(1).CreateSessionAsync(sessionProperties); + await _coreRestClient.Sessions.Received(1).CreateSessionAsync(chatSessionProperties); await _coreRestClient.Completions.GetChatCompletionAsync(Arg.Is( r => r.SessionId == sessionId && r.AgentName == agentName && r.UserPrompt == userPrompt)); } @@ -100,21 +100,21 @@ public async Task AttachFileAndAskQuestionAsync_UsesSession_UploadsFileAndSendsS var contentType = "text/plain"; var agentName = "TestAgent"; var question = "What is this file about?"; - var sessionProperties = new SessionProperties() { SessionName = "TestSession" }; + var chatSessionProperties = new ChatSessionProperties() { Name = "TestSession" }; var sessionId = "session-id"; var objectId = "object-id"; var completion = new Completion(); _coreRestClient.Attachments.UploadAttachmentAsync(fileStream, fileName, contentType).Returns(Task.FromResult(objectId)); - _coreRestClient.Sessions.CreateSessionAsync(sessionProperties).Returns(Task.FromResult(sessionId)); + _coreRestClient.Sessions.CreateSessionAsync(chatSessionProperties).Returns(Task.FromResult(sessionId)); _coreRestClient.Completions.GetChatCompletionAsync(Arg.Any()).Returns(Task.FromResult(completion)); // Act - var result = await _coreClient.AttachFileAndAskQuestionAsync(fileStream, fileName, contentType, agentName, question, true, null, sessionProperties); + var result = await _coreClient.AttachFileAndAskQuestionAsync(fileStream, fileName, contentType, agentName, question, true, null, chatSessionProperties); // Assert Assert.Equal(completion, result); await _coreRestClient.Attachments.Received(1).UploadAttachmentAsync(fileStream, fileName, contentType); - await _coreRestClient.Sessions.Received(1).CreateSessionAsync(sessionProperties); + await _coreRestClient.Sessions.Received(1).CreateSessionAsync(chatSessionProperties); await _coreRestClient.Completions.GetChatCompletionAsync(Arg.Is( r => r.AgentName == agentName && r.SessionId == sessionId && r.UserPrompt == question && r.Attachments.Contains(objectId))); } @@ -126,7 +126,7 @@ public async Task AttachFileAndAskQuestionAsync_ThrowsException_WhenFileStreamIs await Assert.ThrowsAsync(() => _coreClient.AttachFileAndAskQuestionAsync( null!, "file.txt", "text/plain", "agent", "question", true, "session-id", - new SessionProperties() { SessionName = "session-name" })); + new ChatSessionProperties() { Name = "session-name" })); } [Fact] diff --git a/tests/dotnet/Core.Examples/Services/AgentConversationTestService.cs b/tests/dotnet/Core.Examples/Services/AgentConversationTestService.cs index 13cdad8495..0c10326d71 100644 --- a/tests/dotnet/Core.Examples/Services/AgentConversationTestService.cs +++ b/tests/dotnet/Core.Examples/Services/AgentConversationTestService.cs @@ -36,7 +36,7 @@ public async Task> RunAgentConversationWithSession( if (string.IsNullOrWhiteSpace(sessionId)) { // Create a new session since an existing ID was not provided. - sessionId = await coreClient.CreateChatSessionAsync(new SessionProperties() { SessionName = "Test" }); + sessionId = await coreClient.CreateChatSessionAsync(new ChatSessionProperties() { Name = "Test" }); sessionCreated = true; } @@ -74,7 +74,7 @@ public async Task RunAgentCompletionWithSession(string agentName, if (string.IsNullOrWhiteSpace(sessionId)) { // Create a new session since an existing ID was not provided. - sessionId = await coreClient.CreateChatSessionAsync(new SessionProperties() { SessionName = "Test" }); + sessionId = await coreClient.CreateChatSessionAsync(new ChatSessionProperties() { Name = "Test" }); sessionCreated = true; } @@ -148,7 +148,7 @@ public async Task RunAgentCompletionWithQual if (string.IsNullOrWhiteSpace(sessionId)) { // Create a new session since an existing ID was not provided. - sessionId = await coreClient.CreateChatSessionAsync(new SessionProperties() { SessionName = "Test" }); + sessionId = await coreClient.CreateChatSessionAsync(new ChatSessionProperties() { Name = "Test" }); sessionCreated = true; } diff --git a/tests/dotnet/Core.Tests/Services/CoreServiceTests.cs b/tests/dotnet/Core.Tests/Services/CoreServiceTests.cs index a870443755..5d2a242e0d 100644 --- a/tests/dotnet/Core.Tests/Services/CoreServiceTests.cs +++ b/tests/dotnet/Core.Tests/Services/CoreServiceTests.cs @@ -123,8 +123,8 @@ public async Task CreateNewChatSessionAsync_ShouldReturnANewChatSession() // Arrange var currentUserUPN = "testuser@example.com"; var sessionType = "Test_type"; - var sessionProperties = new SessionProperties() { SessionName = "Test_name" }; - var newSession = new Session { Name = sessionProperties.SessionName, Type = sessionType, UPN = currentUserUPN }; + var chatSessionProperties = new ChatSessionProperties() { Name = "Test_name" }; + var newSession = new Session { Name = chatSessionProperties.Name, Type = sessionType, UPN = currentUserUPN }; // Set up mock returns _callContext.CurrentUserIdentity.Returns(new UnifiedUserIdentity { UPN = currentUserUPN }); @@ -133,13 +133,13 @@ public async Task CreateNewChatSessionAsync_ShouldReturnANewChatSession() .Returns(Task.FromResult(newSession)); // Act - var resultSession = await _testedService.CreateNewChatSessionAsync(_instanceId, sessionProperties); + var resultSession = await _testedService.CreateNewChatSessionAsync(_instanceId, chatSessionProperties); // Assert Assert.NotNull(resultSession); Assert.Equal(sessionType, resultSession.Type); Assert.Equal(currentUserUPN, resultSession.UPN); - Assert.Equal(sessionProperties.SessionName, resultSession.Name); + Assert.Equal(chatSessionProperties.Name, resultSession.Name); } #endregion @@ -151,37 +151,37 @@ public async Task RenameChatSessionAsync_ShouldReturnTheRenamedChatSession() { // Arrange var session = new Session() { Name = "OldName" }; - var sessionProperties = new SessionProperties() { SessionName = "NewName" }; + var chatSessionProperties = new ChatSessionProperties() { Name = "NewName" }; var expectedSession = new Session() { Id = session.Id, Messages = session.Messages, - Name = sessionProperties.SessionName, + Name = chatSessionProperties.Name, SessionId = session.SessionId, TokensUsed = session.TokensUsed, Type = session.Type, }; - _cosmosDbService.UpdateSessionNameAsync(session.Id, sessionProperties.SessionName).Returns(expectedSession); + _cosmosDbService.UpdateSessionNameAsync(session.Id, chatSessionProperties.Name).Returns(expectedSession); // Act - var actualSession = await _testedService.RenameChatSessionAsync(_instanceId, session.Id, sessionProperties); + var actualSession = await _testedService.RenameChatSessionAsync(_instanceId, session.Id, chatSessionProperties); // Assert Assert.Equivalent(expectedSession, actualSession); - Assert.Equal(sessionProperties.SessionName, actualSession.Name); + Assert.Equal(chatSessionProperties.Name, actualSession.Name); } [Fact] public async Task RenameChatSessionAsync_ShouldThrowExceptionWhenSessionIdIsNull() { // Arrange - var sessionProperties = new SessionProperties() { SessionName = "NewName" }; + var chatSessionProperties = new ChatSessionProperties() { Name = "NewName" }; // Assert await Assert.ThrowsAsync(async () => { - await _testedService.RenameChatSessionAsync(_instanceId, null!, sessionProperties); + await _testedService.RenameChatSessionAsync(_instanceId, null!, chatSessionProperties); }); } @@ -199,7 +199,7 @@ await Assert.ThrowsAsync(async () => await Assert.ThrowsAsync(async () => { - await _testedService.RenameChatSessionAsync(_instanceId, sessionId, new SessionProperties() { SessionName = string.Empty }); + await _testedService.RenameChatSessionAsync(_instanceId, sessionId, new ChatSessionProperties() { Name = string.Empty }); }); }