diff --git a/docs/ChatGptNet/IChatGptClient/AddFunctionResponseAsync.md b/docs/ChatGptNet/IChatGptClient/AddFunctionResponseAsync.md index 5abdc79..52268c5 100644 --- a/docs/ChatGptNet/IChatGptClient/AddFunctionResponseAsync.md +++ b/docs/ChatGptNet/IChatGptClient/AddFunctionResponseAsync.md @@ -22,6 +22,7 @@ The Task corresponding to the asynchronous operation. | exception | condition | | --- | --- | +| ArgumentNullException | *functionName* or *content* are `null`. | | InvalidOperationException | The conversation history is empty. | ## See Also diff --git a/src/ChatGptNet/ChatGptClient.cs b/src/ChatGptNet/ChatGptClient.cs index d7d4e76..d7e84e2 100644 --- a/src/ChatGptNet/ChatGptClient.cs +++ b/src/ChatGptNet/ChatGptClient.cs @@ -221,22 +221,17 @@ public async Task LoadConversationAsync(Guid conversationId, IEnumerable ChatGptOptions.MessageLimit, the UpdateCacheAsync method takes care of taking only the last messages. - await UpdateCacheAsync(conversationId, messages, cancellationToken); - } - else - { - // Retrieves the current history and adds new messages. + // Otherwise, retrieves the current history and adds the messages. var conversationHistory = await cache.GetAsync(conversationId, cancellationToken) ?? Enumerable.Empty(); - conversationHistory = conversationHistory.Union(messages); - - // If messages.Count() > ChatGptOptions.MessageLimit, the UpdateCacheAsync method takes care of taking only the last messages. - await UpdateCacheAsync(conversationId, conversationHistory, cancellationToken); + messages = conversationHistory.Union(messages); } + // If messages.Count() > ChatGptOptions.MessageLimit, the UpdateCacheAsync method takes care of taking only the last messages. + await UpdateCacheAsync(conversationId, messages.ToList(), cancellationToken); + return conversationId; } @@ -265,6 +260,9 @@ public async Task AddInteractionAsync(Guid conversationId, string question, stri public async Task AddFunctionResponseAsync(Guid conversationId, string functionName, string content, CancellationToken cancellationToken = default) { + ArgumentNullException.ThrowIfNull(functionName); + ArgumentNullException.ThrowIfNull(content); + var messages = await cache.GetAsync(conversationId, cancellationToken); if (!messages?.Any() ?? true) { diff --git a/src/ChatGptNet/IChatGptClient.cs b/src/ChatGptNet/IChatGptClient.cs index c3de536..d47d82a 100644 --- a/src/ChatGptNet/IChatGptClient.cs +++ b/src/ChatGptNet/IChatGptClient.cs @@ -226,6 +226,7 @@ Task LoadConversationAsync(IEnumerable messages, Cancellat /// The content of the function response. /// The token to monitor for cancellation requests. /// The corresponding to the asynchronous operation. + /// or are . /// The conversation history is empty. /// ///