From f8bbb91b7db71f156f05190ec0474cb0f1f087c2 Mon Sep 17 00:00:00 2001
From: meelstorm <8780022+TesAnti@users.noreply.github.com>
Date: Thu, 18 Jan 2024 19:48:06 +0100
Subject: [PATCH 1/3] fixed error in Retreival chain
---
src/libs/LangChain.Core/Chains/Chain.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libs/LangChain.Core/Chains/Chain.cs b/src/libs/LangChain.Core/Chains/Chain.cs
index bc7a2b23..6f6caee3 100644
--- a/src/libs/LangChain.Core/Chains/Chain.cs
+++ b/src/libs/LangChain.Core/Chains/Chain.cs
@@ -95,7 +95,7 @@ public static RetrieveDocumentsChain RetrieveDocuments(
VectorStoreIndexWrapper index,
int amount = 4,
string inputKey = "text",
- string outputKey = "text")
+ string outputKey = "docs")
{
return new RetrieveDocumentsChain(index, inputKey, outputKey, amount);
}
From 1b0584aa9ab882ec36636ef3640f8d444f4b47a9 Mon Sep 17 00:00:00 2001
From: meelstorm <8780022+TesAnti@users.noreply.github.com>
Date: Thu, 18 Jan 2024 19:49:03 +0100
Subject: [PATCH 2/3] set ollama instruction model url to default value
---
.../OllamaLanguageModelInstruction.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/libs/Providers/LangChain.Providers.Ollama/OllamaLanguageModelInstruction.cs b/src/libs/Providers/LangChain.Providers.Ollama/OllamaLanguageModelInstruction.cs
index 738491b2..0c4fbbbd 100644
--- a/src/libs/Providers/LangChain.Providers.Ollama/OllamaLanguageModelInstruction.cs
+++ b/src/libs/Providers/LangChain.Providers.Ollama/OllamaLanguageModelInstruction.cs
@@ -37,12 +37,12 @@ public class OllamaLanguageModelInstruction : IChatModel
///
public OllamaLanguageModelInstruction(
string modelName,
- string? url = null,
+ string url = "http://localhost:11434",
OllamaLanguageModelOptions? options = null)
{
_modelName = modelName;
Options = options ?? new OllamaLanguageModelOptions();
- _api = new OllamaApiClient(url ?? "http://localhost:11434");
+ _api = new OllamaApiClient(url);
}
///
From 275f9f878d8ce83e7693eacdb6b45eee87aa8f92 Mon Sep 17 00:00:00 2001
From: meelstorm <8780022+TesAnti@users.noreply.github.com>
Date: Wed, 24 Jan 2024 15:19:27 +0100
Subject: [PATCH 3/3] cleaner chat memory
---
src/libs/LangChain.Core/Chains/Chain.cs | 9 ++++++-
.../Chains/StackableChains/LoadMemoryChain.cs | 27 +++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs
diff --git a/src/libs/LangChain.Core/Chains/Chain.cs b/src/libs/LangChain.Core/Chains/Chain.cs
index 6f6caee3..51532376 100644
--- a/src/libs/LangChain.Core/Chains/Chain.cs
+++ b/src/libs/LangChain.Core/Chains/Chain.cs
@@ -121,13 +121,20 @@ public static StuffDocumentsChain StuffDocuments(
///
///
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);
+ }
+
///
///
///
diff --git a/src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs b/src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs
new file mode 100644
index 00000000..7224b8d8
--- /dev/null
+++ b/src/libs/LangChain.Core/Chains/StackableChains/LoadMemoryChain.cs
@@ -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 InternalCall(IChainValues values)
+ {
+ values.Value[_outputKey] = _chatMemory.BufferAsString;
+ return Task.FromResult(values);
+ }
+}
\ No newline at end of file