Skip to content

Commit

Permalink
Merge branch 'chat_update'
Browse files Browse the repository at this point in the history
  • Loading branch information
TesAnti committed Jan 24, 2024
2 parents cf1719d + 275f9f8 commit abb1c16
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libs/LangChain.Core/Chains/Chain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,20 @@ public static StuffDocumentsChain CombineDocuments(
/// <param name="responseKey"></param>
/// <returns></returns>
public static UpdateMemoryChain UpdateMemory(
BaseChatMemory memory,
ConversationBufferMemory memory,
string requestKey = "text",
string responseKey = "text")
{
return new UpdateMemoryChain(memory, requestKey, responseKey);
}

public static LoadMemoryChain LoadMemory(
ConversationBufferMemory memory,
string outputKey = "text")
{
return new LoadMemoryChain(memory, outputKey);
}

/// <summary>
///
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using LangChain.Abstractions.Schema;
using LangChain.Chains.HelperChains;
using LangChain.Memory;

namespace LangChain.Chains.StackableChains;

public class LoadMemoryChain: BaseStackableChain
{

private readonly ConversationBufferMemory _chatMemory;
private readonly string _outputKey;

public LoadMemoryChain(ConversationBufferMemory chatMemory,string outputKey)
{

_chatMemory = chatMemory;
_outputKey = outputKey;

OutputKeys = new[] {_outputKey};
}

protected override Task<IChainValues> InternalCall(IChainValues values)
{
values.Value[_outputKey] = _chatMemory.BufferAsString;

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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)

Check warning on line 24 in src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs

View workflow job for this annotation

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

In externally visible method 'Task<IChainValues> LoadMemoryChain.InternalCall(IChainValues values)', validate parameter 'values' 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 Task.FromResult(values);
}
}

0 comments on commit abb1c16

Please sign in to comment.