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

Resolves #135 - Adds propers async/await to LLMChain ParseResult #136

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
34 changes: 17 additions & 17 deletions src/libs/LangChain.Core/Chains/LLM/LLMChain.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using LangChain.Abstractions.Schema;
using LangChain.Base;
using LangChain.Callback;
Expand Down Expand Up @@ -154,7 +155,7 @@ public override async Task<List<IChainValues>> ApplyAsync(IReadOnlyList<ChainVal
throw;
}

var outputs = CreateOutputs(response);
var outputs = await CreateOutputs(response).ConfigureAwait(false);
await runManager.HandleChainEndAsync(new ChainValues("inputs", inputs), new ChainValues("outputs", outputs)).ConfigureAwait(false);

return outputs;
Expand Down Expand Up @@ -237,30 +238,29 @@ private async Task<LlmResult> GenerateAsync(IReadOnlyList<ChainValues> inputs, C
}

/// <summary> Create outputs from response. </summary>
private List<IChainValues> CreateOutputs(LlmResult llmResult)
private async Task<List<IChainValues>> CreateOutputs(LlmResult llmResult)
{
var chainValues = new List<IChainValues>();
// Get the text of the top generated string.
var result = llmResult.Generations
.Select(generation =>
foreach (var generation in llmResult.Generations)
{
var dictionary = new Dictionary<string, object>
{
var dictionary = new Dictionary<string, object>
{
[OutputKey] = OutputParser.ParseResult(generation)
};
[OutputKey] = await OutputParser.ParseResult(generation).ConfigureAwait(false)
};

if (!ReturnFinalOnly)
{
dictionary["full_generation"] = generation;
}
if (!ReturnFinalOnly)
{
dictionary["full_generation"] = generation;
}

return new ChainValues(dictionary);
})
.Cast<IChainValues>()
.ToList();
chainValues.Add(new ChainValues(dictionary));
}

return result;
return chainValues;
}


/// <summary>
///
/// </summary>
Expand Down
Loading