Skip to content

Commit

Permalink
📦 chore(ConversationChain.py): add ConversationChain component to han…
Browse files Browse the repository at this point in the history
…dle conversations and load context from memory

📦 chore(LLMChain.py): add optional memory parameter to LLMChain build method to support loading context from memory
  • Loading branch information
ogabrielluiz committed Nov 3, 2023
1 parent c23d797 commit 941cdd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/backend/langflow/components/chains/ConversationChain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from langflow import CustomComponent
from langchain.chains import ConversationChain
from typing import Optional, Union, Callable
from langflow.field_typing import BaseLanguageModel, BaseMemory, Chain


class ConversationChainComponent(CustomComponent):
display_name = "ConversationChain"
description = "Chain to have a conversation and load context from memory."

def build_config(self):
return {
"prompt": {"display_name": "Prompt"},
"llm": {"display_name": "LLM"},
"memory": {"display_name": "Memory"},
"code": {"show": False},
}

def build(
self,
llm: BaseLanguageModel,
memory: Optional[BaseMemory] = None,
) -> Union[Chain, Callable]:
return ConversationChain(llm=llm, memory=memory)
3 changes: 2 additions & 1 deletion src/backend/langflow/components/chains/LLMChain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ def build_config(self):
"prompt": {"display_name": "Prompt"},
"llm": {"display_name": "LLM"},
"memory": {"display_name": "Memory"},
"code": {"show": False},
}

def build(
self,
prompt: PromptTemplate,
llm: BaseLanguageModel,
memory: Optional[BaseMemory],
memory: Optional[BaseMemory] = None,
) -> Union[Chain, Callable]:
return LLMChain(prompt=prompt, llm=llm, memory=memory)

0 comments on commit 941cdd4

Please sign in to comment.