Skip to content

Commit

Permalink
Fix tests, swap IStableDiffusion implementation with WIP AiServerClie…
Browse files Browse the repository at this point in the history
…nt.cs to handle image generation.
  • Loading branch information
Layoric committed Jul 10, 2024
1 parent e9c58ba commit 583c5e3
Show file tree
Hide file tree
Showing 4 changed files with 1,459 additions and 9 deletions.
24 changes: 15 additions & 9 deletions BlazorDiffusion.Tests/CreativeServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using ServiceStack.Auth;
using ServiceStack.Configuration;
using ServiceStack.Data;
using ServiceStack.IO;
using ServiceStack.Messaging;
using ServiceStack.OrmLite;

namespace BlazorDiffusion.Tests;
Expand All @@ -31,9 +33,11 @@ public AppHost() : base(nameof(CreativeServiceTests), typeof(MyServices).Assembl

public override void Configure(Container container)
{
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory("db.sqlite",
SqliteDialect.Provider));
var dbFactory = new OrmLiteConnectionFactory("db.sqlite",
SqliteDialect.Provider);
dbFactory.RegisterConnection(Databases.Analytics, "analytics.sqlite",
SqliteDialect.Provider);
container.Register<IDbConnectionFactory>(dbFactory);

var migrator = CreateMigrator();
migrator.Timeout = TimeSpan.Zero;
Expand Down Expand Up @@ -66,11 +70,13 @@ public override void Configure(Container container)
//IncludeTotal = true,
});

container.Register<IStableDiffusionClient>(new DreamStudioClient
{
ApiKey = Environment.GetEnvironmentVariable("DREAMAI_APIKEY") ?? "<your_api_key>",
OutputPathPrefix = Path.Join(ContentRootDirectory.RealPath.CombineWith("App_Files"),"artifacts")
});
container.Register<IStableDiffusionClient>(
new AiServerClient("https://openai.servicestack.net/",new MemoryVirtualFiles())
{
OutputPathPrefix = Path.Join(ContentRootDirectory.RealPath.CombineWith("App_Files"),"artifacts")
});
container.AddSingleton<AppUserQuotas>();
container.AddSingleton<IMessageFactory>(new InMemoryTransientMessageFactory());
container.AddSingleton<ICrudEvents>(c =>
new OrmLiteCrudEvents(c.Resolve<IDbConnectionFactory>()));
container.Resolve<ICrudEvents>().InitSchema();
Expand Down Expand Up @@ -156,7 +162,7 @@ public CreativeServiceTests()

[Test]
[TestCaseSource("AllGenerationCases")]
[Explicit]
//[Explicit]
public void Can_generate_images(ImageGenerationTestCase testCase)
{
var client = CreateClient();
Expand Down
Loading

0 comments on commit 583c5e3

Please sign in to comment.