Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image generation small fix to match results of AUTOMATIC1111 UI #97

Merged
merged 17 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libs/LangChain.Core/Chains/Chain.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LangChain.Chains.HelperChains;
using LangChain.Chains.HelperChains;
using LangChain.Chains.StackableChains;
using LangChain.Chains.StackableChains.Agents;
using LangChain.Chains.StackableChains.Files;
Expand Down Expand Up @@ -228,4 +228,4 @@ public static SaveIntoFileChain SaveIntoFile(
{
return new SaveIntoFileChain(path, inputKey);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LangChain.Abstractions.Schema;
using LangChain.Abstractions.Schema;
using LangChain.Chains.HelperChains;

namespace LangChain.Chains.StackableChains.Files;
Expand Down Expand Up @@ -58,4 +58,4 @@ Task<IChainValues> InternalCall(IChainValues values)
return Task.FromResult(values);
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LangChain.Abstractions.Schema;
using LangChain.Abstractions.Schema;
using LangChain.Chains.HelperChains;
using LangChain.Providers;

Expand Down Expand Up @@ -39,4 +39,4 @@ protected override async Task<IChainValues> InternalCall(IChainValues values)
values.Value[OutputKeys[0]] = image;
return values;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LangChain.Providers;
using LangChain.Providers;

namespace StableDiffusion;

Expand Down Expand Up @@ -28,6 +28,8 @@
_client = new StableDiffusionClient(url, httpClient);
}

public event Action<string> PromptSent = delegate { };

Check warning on line 31 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'Automatic1111Model.PromptSent'

Check warning on line 31 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'Automatic1111Model.PromptSent'

Check warning on line 31 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'Automatic1111Model.PromptSent'

Check warning on line 31 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'Automatic1111Model.PromptSent'

/// <inheritdoc />
public Task<Uri> GenerateImageAsUrlAsync(string prompt, CancellationToken cancellationToken = default)
{
Expand All @@ -44,6 +46,9 @@
/// <inheritdoc />
public async Task<byte[]> GenerateImageAsBytesAsync(string prompt, CancellationToken cancellationToken = default)
{
PromptSent(prompt);

var samplers = await _client.Get_samplers_sdapi_v1_samplers_getAsync();

Check warning on line 51 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Forward the 'cancellationToken' parameter to the 'Get_samplers_sdapi_v1_samplers_getAsync' method or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2016)

Check warning on line 51 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Consider calling ConfigureAwait on the awaited task (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2007)

Check warning on line 51 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Forward the 'cancellationToken' parameter to the 'Get_samplers_sdapi_v1_samplers_getAsync' method or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2016)

Check warning on line 51 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Consider calling ConfigureAwait on the awaited task (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2007)

Check warning on line 51 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Forward the 'cancellationToken' parameter to the 'Get_samplers_sdapi_v1_samplers_getAsync' method or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2016)

Check warning on line 51 in src/libs/Providers/LangChain.Providers.Automatic1111/Automatic1111Model.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Consider calling ConfigureAwait on the awaited task (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2007)
var response = await _client.Text2imgapi_sdapi_v1_txt2img_postAsync(
new StableDiffusionProcessingTxt2Img
{
Expand All @@ -54,6 +59,8 @@
Steps = Options.Steps,
Seed = Options.Seed,
Cfg_scale = Options.CfgScale,
Sampler_index = Options.Sampler,
Sampler_name = Options.Sampler,
}, cancellationToken).ConfigureAwait(false);

var encoded = response.Images.First();
Expand All @@ -62,4 +69,4 @@
var bytes = Convert.FromBase64String(encoded);
return bytes;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace StableDiffusion;
namespace StableDiffusion;

/// <summary>
///
Expand All @@ -23,7 +23,7 @@ public class Automatic1111ModelOptions
/// <summary>
///
/// </summary>
public double CfgScale { get; set; } = 7;
public float CfgScale { get; set; } = 6.0F;

/// <summary>
///
Expand All @@ -34,6 +34,9 @@ public class Automatic1111ModelOptions
///
/// </summary>
public int Height { get; set; } = 512;


}

/// <summary>
///
/// </summary>
public string Sampler { get; set; } = "Euler a";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="LLamaSharp" />
<PackageReference Include="Newtonsoft.Json" OverrideVersion="13.0.3" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.Net.Http" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//----------------------

#pragma warning disable CS3008 // Identifier is not CLS-compliant

#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended."
#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword."
#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?'
Expand Down Expand Up @@ -12562,10 +12562,10 @@ public partial class StableDiffusionProcessingTxt2Img
public bool Do_not_save_grid { get; set; } = false;

[Newtonsoft.Json.JsonProperty("eta", Required = Newtonsoft.Json.Required.AllowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double Eta { get; set; }
public double? Eta { get; set; }=null;

[Newtonsoft.Json.JsonProperty("denoising_strength", Required = Newtonsoft.Json.Required.AllowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double Denoising_strength { get; set; } = 0D;
public double? Denoising_strength { get; set; } = null;

[Newtonsoft.Json.JsonProperty("s_min_uncond", Required = Newtonsoft.Json.Required.AllowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double S_min_uncond { get; set; }
Expand Down Expand Up @@ -12949,4 +12949,4 @@ public ApiException(string message, int statusCode, string response, System.Coll
#pragma warning restore 114
#pragma warning restore 108
#pragma warning restore 3016
#pragma warning restore 8603
#pragma warning restore 8603
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -137,6 +137,4 @@ public async Task<GenerateEmbeddingResponse> GenerateEmbeddings(GenerateEmbeddin
var streamedResponse = JsonSerializer.Deserialize<GenerateEmbeddingResponse>(line) ?? throw new InvalidOperationException("Response body was null");
return streamedResponse;
}


}
}