Skip to content

Commit

Permalink
Do not register factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Feb 1, 2025
1 parent 3ef5ac7 commit 8379620
Show file tree
Hide file tree
Showing 107 changed files with 361 additions and 366 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dotnet_diagnostic.MA0004.severity = none
dotnet_diagnostic.MA0006.severity = none

# MA0007: Add a comma after the last value
dotnet_diagnostic.MA0007.severity = none
dotnet_diagnostic.MA0007.severity = warning

# MA0008: Add StructLayoutAttribute
dotnet_diagnostic.MA0008.severity = none
Expand Down
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.28.0</Version>
<Version>6.29.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
2 changes: 0 additions & 2 deletions ai/Squidex.AI.EntityFramework/EFChatServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public static AIBuilder AddEntityFrameworkChatStore<T>(this AIBuilder builder)
builder.Services.AddSingletonAs<EFChatStore<T>>()
.As<IChatStore>();

builder.Services.AddDbContextFactory<T>();

return builder;
}
}
2 changes: 1 addition & 1 deletion ai/Squidex.AI.EntityFramework/EFChatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task StoreAsync(string conversationId, Conversation conversation, D
Id = conversationId,
LastUpdated = now,
Version = Guid.NewGuid(),
Value = json
Value = json,
};

await context.Set<EFChatEntity>().AddAsync(entity, ct);
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI.Mongo/MongoChatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Task StoreAsync(string conversationId, Conversation conversation, DateTim
.Set(x => x.LastUpdated, now),
new UpdateOptions
{
IsUpsert = true
IsUpsert = true,
},
ct);
}
Expand Down
4 changes: 2 additions & 2 deletions ai/Squidex.AI.Tests/ChatCleanerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Should_delete_conversations()
new[]
{
(conversationId1, conversation1),
(conversationId2, conversation2)
(conversationId2, conversation2),
}.ToAsyncEnumerable());

await sut.CleanupAsync(default);
Expand All @@ -91,7 +91,7 @@ public async Task Should_call_tools_conversations()
new[]
{
(conversationId1, conversation1),
(conversationId2, conversation2)
(conversationId2, conversation2),
}.ToAsyncEnumerable());

await sut.CleanupAsync(default);
Expand Down
8 changes: 4 additions & 4 deletions ai/Squidex.AI.Tests/ChatStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public async Task Should_insert_conversation()
],
ToolData = new Dictionary<string, string>
{
["Key"] = "Value"
}
["Key"] = "Value",
},
};

await sut.StoreAsync(conversationId, conversation, DateTime.UtcNow, default);
Expand Down Expand Up @@ -87,8 +87,8 @@ public async Task Should_update_conversation()
],
ToolData = new Dictionary<string, string>
{
["Key"] = "Value"
}
["Key"] = "Value",
},
};

await sut.StoreAsync(conversationId, conversation0, DateTime.UtcNow, default);
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI.Tests/DallEPipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task Should_create_article_with_image()
SystemMessages =
[
"You are a fiendly agent. Always use the result from the tool if you have called one.",
"When you are asked to generate content such as articles, add placeholders for image, describe and use the following pattern: <IMG>{description}</IMG>. {description} is the generated image description."
"When you are asked to generate content such as articles, add placeholders for image, describe and use the following pattern: <IMG>{description}</IMG>. {description} is the generated image description.",
],
};
})
Expand Down
4 changes: 2 additions & 2 deletions ai/Squidex.AI.Tests/DallETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task Should_generate_image()
},
ChatAgent = null!,
Context = new ChatContext(),
ToolData = []
ToolData = [],
};

var result = await sut.ExecuteAsync(ctx, default);
Expand Down Expand Up @@ -129,7 +129,7 @@ private static void AssertImageFromTool(ChatResult result)
SystemMessages =
[
"You are a fiendly agent. Always use the result from the tool if you have called one.",
"Say hello to the user."
"Say hello to the user.",
],
};
})
Expand Down
2 changes: 1 addition & 1 deletion ai/Squidex.AI.Tests/EFChatStoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task InitializeAsync()
await postgresSql.StartAsync();

Services = new ServiceCollection()
.AddDbContext<AppDbContext>(b =>
.AddDbContextFactory<AppDbContext>(b =>
{
b.UseNpgsql(postgresSql.GetConnectionString());
})
Expand Down
14 changes: 7 additions & 7 deletions ai/Squidex.AI.Tests/ImagePipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ImagePipeTests()
History = [],
Tool = null,
ToolData = [],
Tools = []
Tools = [],
};

sut = new ImagePipe(tool);
Expand Down Expand Up @@ -75,7 +75,7 @@ public async Task Should_skip_interrupted_marker()
{
CreateEvents("<IMG>Small "),
[new ToolStartEvent { Tool = null!, Arguments = null! }],
CreateEvents("Puppet</IMG>")
CreateEvents("Puppet</IMG>"),
}.SelectMany(x => x).ToAsyncEnumerable();

var resultStream = await sut.StreamAsync(source, request).ToListAsync();
Expand Down Expand Up @@ -140,17 +140,17 @@ public async Task Should_replace_image_marker_with_text_before_as_stream()
Tool = tool,
Arguments = new Dictionary<string, ToolValue>
{
["query"] = new ToolStringValue("Puppy")
}
["query"] = new ToolStringValue("Puppy"),
},
},
new ToolEndEvent
{
Tool = tool,
Result = "URL_TO_PUPPY_IMAGE"
Result = "URL_TO_PUPPY_IMAGE",
},
],
[new ChunkEvent { Content = "URL_TO_PUPPY_IMAGE" }],
CreateEvents(" Text After")
CreateEvents(" Text After"),
}.SelectMany(x => x).ToList();

resultStream.Should().BeEquivalentTo(expectedStream,
Expand Down Expand Up @@ -189,7 +189,7 @@ private ToolContext CreateContext(string query)
},
ChatAgent = null!,
Context = request.Context,
ToolData = request.ToolData
ToolData = request.ToolData,
};
}
}
26 changes: 13 additions & 13 deletions ai/Squidex.AI.Tests/OpenAITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Should_throw_exception_on_invalid_configuration()

var request = new ChatRequest
{
Prompt = "Hello"
Prompt = "Hello",
};

await Assert.ThrowsAsync<ChatException>(() => sut.PromptAsync(request, context));
Expand All @@ -87,7 +87,7 @@ public async Task Should_throw_exception_on_invalid_configuration_when_streaming

var request = new ChatRequest
{
Prompt = "Hello"
Prompt = "Hello",
};

await Assert.ThrowsAsync<ChatException>(() => sut.StreamAsync(request, context).ToListAsync().AsTask());
Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task Should_say_hello_by_configuration()
var request1 = new ChatRequest
{
Prompt = string.Empty,
Configuration = "images"
Configuration = "images",
};

var message1 = await sut.PromptAsync(request1, context);
Expand All @@ -147,7 +147,7 @@ public async Task Should_ask_simple_question()

var request1 = new ChatRequest
{
Prompt = "Write an interesting article about Paris in 5 words."
Prompt = "Write an interesting article about Paris in 5 words.",
};

var message1 = await sut.PromptAsync(request1, context);
Expand Down Expand Up @@ -213,7 +213,7 @@ public async Task Should_not_use_tool_for_configuration()
var request1 = new ChatRequest
{
Prompt = "What is the current temperature in Berlin?",
Configuration = "notool"
Configuration = "notool",
};

var message1 = await sut.PromptAsync(request1, context);
Expand Down Expand Up @@ -294,8 +294,8 @@ public Task Should_ask_question_with_tool_as_streaming() => UseConversationId(as
Arguments = new Dictionary<string, ToolValue>
{
["lhs"] = new ToolNumberValue(10),
["rhs"] = new ToolNumberValue(42)
}
["rhs"] = new ToolNumberValue(42),
},
},
new ToolEndEvent
{
Expand All @@ -321,9 +321,9 @@ public Task Should_ask_question_with_tool_as_streaming() => UseConversationId(as
{
CostsInEUR = 0.001175M,
NumInputTokens = 349,
NumOutputTokens = 32
}
}
NumOutputTokens = 32,
},
},
};

stream1.Should().BeEquivalentTo(expectedStream,
Expand Down Expand Up @@ -364,7 +364,7 @@ private static async Task UseConversationId(Func<string, IChatAgent, IServicePro
SystemMessages =
[
"You are a fiendly agent. Always use the result from the tool if you have called one.",
"Say hello to the user."
"Say hello to the user.",
],
};
options.Configurations = new Dictionary<string, ChatConfiguration>
Expand All @@ -374,12 +374,12 @@ private static async Task UseConversationId(Func<string, IChatAgent, IServicePro
SystemMessages =
[
"You are a bot to generate images. Tell the user about your capabilities in a single, short sentence.",
]
],
},
["notool"] = new ChatConfiguration
{
Tools = [],
}
},
};
})
.BuildServiceProvider();
Expand Down
Loading

0 comments on commit 8379620

Please sign in to comment.