From e0b859ddd1002c856369c72378a638d81b08c107 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:10:02 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- .../components/chains/ConversationChain.py | 20 ++-------- .../components/chains/LLMCheckerChain.py | 18 ++------- .../components/chains/LLMMathChain.py | 16 ++------ .../langflow/components/chains/RetrievalQA.py | 31 ++++------------ .../components/chains/SQLGenerator.py | 37 ++++--------------- 5 files changed, 25 insertions(+), 97 deletions(-) diff --git a/src/backend/base/langflow/components/chains/ConversationChain.py b/src/backend/base/langflow/components/chains/ConversationChain.py index b7c84aee0b0c..a3c4580ba59d 100644 --- a/src/backend/base/langflow/components/chains/ConversationChain.py +++ b/src/backend/base/langflow/components/chains/ConversationChain.py @@ -1,5 +1,3 @@ -from typing import Optional - from langchain.chains import ConversationChain from langflow.custom import Component @@ -15,27 +13,17 @@ class ConversationChainComponent(Component): inputs = [ MultilineInput( - name="input_value", - display_name="Input", - info="The input value to pass to the chain.", - required=True - ), - HandleInput( - name="llm", - display_name="Language Model", - input_types=["LanguageModel"], - required=True + name="input_value", display_name="Input", info="The input value to pass to the chain.", required=True ), + HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True), HandleInput( name="memory", display_name="Memory", input_types=["BaseChatMemory"], - ) + ), ] - outputs = [ - Output(display_name="Text", name="text", method="invoke_chain") - ] + outputs = [Output(display_name="Text", name="text", method="invoke_chain")] def invoke_chain(self) -> Message: if not self.memory: diff --git a/src/backend/base/langflow/components/chains/LLMCheckerChain.py b/src/backend/base/langflow/components/chains/LLMCheckerChain.py index f0cace3ce15f..802cd63553b9 100644 --- a/src/backend/base/langflow/components/chains/LLMCheckerChain.py +++ b/src/backend/base/langflow/components/chains/LLMCheckerChain.py @@ -14,22 +14,12 @@ class LLMCheckerChainComponent(Component): inputs = [ MultilineInput( - name="input_value", - display_name="Input", - info="The input value to pass to the chain.", - required=True - ), - HandleInput( - name="llm", - display_name="Language Model", - input_types=["LanguageModel"], - required=True + name="input_value", display_name="Input", info="The input value to pass to the chain.", required=True ), + HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True), ] - outputs = [ - Output(display_name="Text", name="text", method="invoke_chain") - ] + outputs = [Output(display_name="Text", name="text", method="invoke_chain")] def invoke_chain(self) -> Message: chain = LLMCheckerChain.from_llm(llm=self.llm) @@ -37,4 +27,4 @@ def invoke_chain(self) -> Message: result = response.get(chain.output_key, "") result = str(result) self.status = result - return Message(text=result) \ No newline at end of file + return Message(text=result) diff --git a/src/backend/base/langflow/components/chains/LLMMathChain.py b/src/backend/base/langflow/components/chains/LLMMathChain.py index dfb948571b7a..2d4508aff1c1 100644 --- a/src/backend/base/langflow/components/chains/LLMMathChain.py +++ b/src/backend/base/langflow/components/chains/LLMMathChain.py @@ -14,22 +14,12 @@ class LLMMathChainComponent(Component): inputs = [ MultilineInput( - name="input_value", - display_name="Input", - info="The input value to pass to the chain.", - required=True - ), - HandleInput( - name="llm", - display_name="Language Model", - input_types=["LanguageModel"], - required=True + name="input_value", display_name="Input", info="The input value to pass to the chain.", required=True ), + HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True), ] - outputs = [ - Output(display_name="Text", name="text", method="invoke_chain") - ] + outputs = [Output(display_name="Text", name="text", method="invoke_chain")] def invoke_chain(self) -> Message: chain = LLMMathChain.from_llm(llm=self.llm) diff --git a/src/backend/base/langflow/components/chains/RetrievalQA.py b/src/backend/base/langflow/components/chains/RetrievalQA.py index 9744784107e4..6991e15d4771 100644 --- a/src/backend/base/langflow/components/chains/RetrievalQA.py +++ b/src/backend/base/langflow/components/chains/RetrievalQA.py @@ -1,4 +1,4 @@ -from langchain.chains import RetrievalQA, RetrievalQAWithSourcesChain +from langchain.chains import RetrievalQA from langflow.custom import Component from langflow.field_typing import Message from langflow.inputs import HandleInput, MultilineInput, BoolInput, DropdownInput @@ -12,10 +12,7 @@ class RetrievalQAComponent(Component): inputs = [ MultilineInput( - name="input_value", - display_name="Input", - info="The input value to pass to the chain.", - required=True + name="input_value", display_name="Input", info="The input value to pass to the chain.", required=True ), DropdownInput( name="chain_type", @@ -25,18 +22,8 @@ class RetrievalQAComponent(Component): value="Stuff", advanced=True, ), - HandleInput( - name="llm", - display_name="Language Model", - input_types=["LanguageModel"], - required=True - ), - HandleInput( - name="retriever", - display_name="Retriever", - input_types=["Retriever"], - required=True - ), + HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True), + HandleInput(name="retriever", display_name="Retriever", input_types=["Retriever"], required=True), HandleInput( name="memory", display_name="Memory", @@ -46,12 +33,10 @@ class RetrievalQAComponent(Component): name="return_source_documents", display_name="Return Source Documents", value=False, - ) + ), ] - outputs = [ - Output(display_name="Text", name="text", method="invoke_chain") - ] + outputs = [Output(display_name="Text", name="text", method="invoke_chain")] def invoke_chain(self) -> Message: chain_type = self.chain_type.lower().replace(" ", "_") @@ -66,7 +51,7 @@ def invoke_chain(self) -> Message: memory=self.memory, # always include to help debugging # - return_source_documents=True + return_source_documents=True, ) result = runnable.invoke({"query": self.input_value}) @@ -79,5 +64,3 @@ def invoke_chain(self) -> Message: # put the entire result to debug history, query and content self.status = {**result, "source_documents": source_docs, "output": result_str} return result_str - - diff --git a/src/backend/base/langflow/components/chains/SQLGenerator.py b/src/backend/base/langflow/components/chains/SQLGenerator.py index 9eb14d89c53f..96e9e1f680e3 100644 --- a/src/backend/base/langflow/components/chains/SQLGenerator.py +++ b/src/backend/base/langflow/components/chains/SQLGenerator.py @@ -15,40 +15,17 @@ class SQLGeneratorComponent(Component): inputs = [ MultilineInput( - name="input_value", - display_name="Input", - info="The input value to pass to the chain.", - required=True - ), - HandleInput( - name="llm", - display_name="Language Model", - input_types=["LanguageModel"], - required=True - ), - HandleInput( - name="db", - display_name="SQLDatabase", - input_types=["SQLDatabase"], - required=True + name="input_value", display_name="Input", info="The input value to pass to the chain.", required=True ), + HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True), + HandleInput(name="db", display_name="SQLDatabase", input_types=["SQLDatabase"], required=True), IntInput( - name="top_k", - display_name="Top K", - info="The number of results per select statement to return.", - value=5 - ), - MultilineInput( - name="prompt", - display_name="Prompt", - info="The prompt must contain `{question}`." + name="top_k", display_name="Top K", info="The number of results per select statement to return.", value=5 ), + MultilineInput(name="prompt", display_name="Prompt", info="The prompt must contain `{question}`."), ] - outputs = [ - Output(display_name="Text", name="text", method="invoke_chain") - ] - + outputs = [Output(display_name="Text", name="text", method="invoke_chain")] def invoke_chain(self) -> Message: if self.prompt: @@ -70,4 +47,4 @@ def invoke_chain(self) -> Message: response = query_writer.invoke({"question": self.input_value}) query = response.get("query") self.status = query - return query \ No newline at end of file + return query