Skip to content

Commit

Permalink
Fix deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Mar 24, 2024
1 parent 9a0b901 commit 674c754
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://github.com/squidex/squidex</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>6.6.3</Version>
<Version>6.6.4</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
38 changes: 30 additions & 8 deletions ai/Squidex.AI.Tests/OpenAIChatAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Squidex.AI.SemanticKernel;
using Xunit;

namespace Squidex.AI;
Expand Down Expand Up @@ -82,17 +83,38 @@ public void Should_be_configured_if_open_ai_is_added()
[Trait("Category", "Dependencies")]
public async Task Should_ask_questions_without_conversation()
{
var sut = CreateSut();
var (sut, _) = CreateSut();

var message1 = await sut.PromptAsync("Write an interesting article about Paris in 5 words.");
AssertMessage("Paris: City of Love and Lights", message1);
}

[Fact]
[Trait("Category", "Dependencies")]
public async Task Should_delete_conversation()
{
var (sut, services) = CreateSut();

var conversationId = Guid.NewGuid().ToString();
try
{
await sut.PromptAsync(string.Empty, conversationId);
}
finally
{
await sut.StopConversationAsync(conversationId);
}

var store = services.GetRequiredService<IChatStore>();

Assert.Null(await store.GetAsync(conversationId, default));
}

[Fact]
[Trait("Category", "Dependencies")]
public async Task Should_ask_questions()
{
var sut = CreateSut();
var (sut, _) = CreateSut();

var conversationId = Guid.NewGuid().ToString();
try
Expand All @@ -113,7 +135,7 @@ public async Task Should_ask_questions()
[Trait("Category", "Dependencies")]
public async Task Should_ask_question_with_tool()
{
var sut = CreateSut();
var (sut, _) = CreateSut();

var conversationId = Guid.NewGuid().ToString();
try
Expand All @@ -134,7 +156,7 @@ public async Task Should_ask_question_with_tool()
[Trait("Category", "Dependencies")]
public async Task Should_ask_question_with_tool2()
{
var sut = CreateSut();
var (sut, _) = CreateSut();

var conversationId = Guid.NewGuid().ToString();
try
Expand All @@ -155,7 +177,7 @@ public async Task Should_ask_question_with_tool2()
[Trait("Category", "Dependencies")]
public async Task Should_ask_multiple_question_with_tools()
{
var sut = CreateSut();
var (sut, _) = CreateSut();

var conversationId = Guid.NewGuid().ToString();
try
Expand All @@ -176,7 +198,7 @@ public async Task Should_ask_multiple_question_with_tools()
[Trait("Category", "Dependencies")]
public async Task Should_ask_multiple_question_with_tools2()
{
var sut = CreateSut();
var (sut, _) = CreateSut();

var conversationId = Guid.NewGuid().ToString();
try
Expand All @@ -193,7 +215,7 @@ public async Task Should_ask_multiple_question_with_tools2()
}
}

private static IChatAgent CreateSut()
private static (IChatAgent, IServiceProvider) CreateSut()
{
var services =
new ServiceCollection()
Expand All @@ -212,7 +234,7 @@ private static IChatAgent CreateSut()
})
.BuildServiceProvider();

return services.GetRequiredService<IChatAgent>();
return (services.GetRequiredService<IChatAgent>(), services);
}

private static void AssertMessage(string text, ChatBotResponse message)
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI/SemanticKernel/IChatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Squidex.AI.SemanticKernel;

public interface IChatStore
{
Task ClearAsync(string conversationId,
Task RemoveAsync(string conversationId,
CancellationToken ct);

Task StoreAsync(string conversationId, string value, DateTime expires,
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI/SemanticKernel/InMemoryChatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class InMemoryChatStore : IChatStore
{
private readonly ConcurrentDictionary<string, string> values = new ConcurrentDictionary<string, string>();

public Task ClearAsync(string conversationId,
public Task RemoveAsync(string conversationId,
CancellationToken ct)
{
values.Remove(conversationId, out _);
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI/SemanticKernel/Mongo/MongoChatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Task InitializeAsync(
cancellationToken: ct);
}

public Task ClearAsync(string conversationId,
public Task RemoveAsync(string conversationId,
CancellationToken ct)
{
return collection.DeleteOneAsync(x => x.Id == conversationId, ct);
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI/SemanticKernel/OpenAIChatAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ private Task StoreHistoryAsync(ChatHistory history, string conversationId,
public Task StopConversationAsync(string conversationId,
CancellationToken ct = default)
{
return store.GetAsync(conversationId, ct);
return store.RemoveAsync(conversationId, ct);
}
}

0 comments on commit 674c754

Please sign in to comment.