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

added hook for chain links #125

Merged
merged 1 commit into from
Feb 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public Task<IChainValues> CallAsync(IChainValues values, ICallbacks? callbacks =

try
{
return InternalCall(values);
var res= InternalCall(values);
if (_hook!=null)
{
_hook(values);
}
return res;
}
catch (StackableChainException)
{
Expand Down Expand Up @@ -217,4 +222,10 @@ public async Task<string> Run(

return res.Value[OutputKeys[0]].ToString() ?? string.Empty;
}

private Action<IChainValues>? _hook;
public void SetHook(Action<IChainValues> hook)
{
_hook = hook;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using LangChain.Abstractions.Schema;
using LangChain.Chains.HelperChains;

namespace LangChain.Chains.StackableChains.Extensions;

public static class HookExtension
{
public static T Hook<T>(this T chain, Action<IChainValues> hook) where T : BaseStackableChain
{
chain.SetHook(hook);

Check warning on line 10 in src/libs/LangChain.Core/Chains/StackableChains/Extensions/HookExtension.cs

View workflow job for this annotation

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

In externally visible method 'T HookExtension.Hook<T>(T chain, Action<IChainValues> hook)', validate parameter 'chain' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
return chain;
}
}
Loading