From 72f88e1a168d5122a561f5537df793a6b384e23f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 14:36:45 -0300 Subject: [PATCH 01/10] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py)?= =?UTF-8?q?:=20handle=20return=5Ftype=20as=20a=20Union[type1,=20type2]=20a?= =?UTF-8?q?nd=20add=20support=20for=20multiple=20return=20types=20in=20add?= =?UTF-8?q?=5Fbase=5Fclasses=20function=20=F0=9F=90=9B=20fix(types.py):=20?= =?UTF-8?q?handle=20multiple=20return=20types=20in=20add=5Fbase=5Fclasses?= =?UTF-8?q?=20function=20and=20raise=20HTTPException=20with=20appropriate?= =?UTF-8?q?=20error=20message=20if=20return=20type=20is=20invalid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interface/custom/custom_component.py | 10 ++++- src/backend/langflow/interface/types.py | 37 ++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index ce8956660..8c0b2537a 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -117,7 +117,15 @@ class CustomComponent(Component, extra=Extra.allow): return "" build_method = build_methods[0] - + return_type = build_method["return_type"] + # It could be a type or a Union[type1, type2] + if "Union" in return_type: + return_type = ( + return_type.replace("Union", "").replace("[", "").replace("]", "") + ) + return_type = return_type.split(",") + return_type = [item.strip() for item in return_type] + return [item for item in return_type if item in self.return_type_valid_list] return build_method["return_type"] @property diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index 76dc144a0..950f227b4 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -1,6 +1,6 @@ import ast import contextlib -from typing import Any +from typing import Any, List from langflow.api.utils import merge_nested_dicts_with_renaming from langflow.interface.agents.base import agent_creator from langflow.interface.chains.base import chain_creator @@ -257,26 +257,27 @@ def get_field_properties(extra_field): return field_name, field_type, field_value, field_required -def add_base_classes(frontend_node, return_type): +def add_base_classes(frontend_node, return_types: List[str]): """Add base classes to the frontend node""" - if return_type not in CUSTOM_COMPONENT_SUPPORTED_TYPES or return_type is None: - raise HTTPException( - status_code=400, - detail={ - "error": ( - "Invalid return type should be one of: " - f"{list(CUSTOM_COMPONENT_SUPPORTED_TYPES.keys())}" - ), - "traceback": traceback.format_exc(), - }, - ) + for return_type in return_types: + if return_type not in CUSTOM_COMPONENT_SUPPORTED_TYPES or return_type is None: + raise HTTPException( + status_code=400, + detail={ + "error": ( + "Invalid return type should be one of: " + f"{list(CUSTOM_COMPONENT_SUPPORTED_TYPES.keys())}" + ), + "traceback": traceback.format_exc(), + }, + ) - return_type_instance = CUSTOM_COMPONENT_SUPPORTED_TYPES.get(return_type) - base_classes = get_base_classes(return_type_instance) + return_type_instance = CUSTOM_COMPONENT_SUPPORTED_TYPES.get(return_type) + base_classes = get_base_classes(return_type_instance) - for base_class in base_classes: - if base_class not in CLASSES_TO_REMOVE: - frontend_node.get("base_classes").append(base_class) + for base_class in base_classes: + if base_class not in CLASSES_TO_REMOVE: + frontend_node.get("base_classes").append(base_class) def build_langchain_template_custom_component(custom_component: CustomComponent): From b3e512f55f71bf8e713b63280d4bb58353381cef Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 14:37:20 -0300 Subject: [PATCH 02/10] =?UTF-8?q?=E2=9C=A8=20feat(PromptRunner.py):=20add?= =?UTF-8?q?=20PromptRunner=20component=20to=20run=20a=20Chain=20with=20a?= =?UTF-8?q?=20given=20PromptTemplate=20=E2=9C=A8=20feat(Vectara.py):=20add?= =?UTF-8?q?=20VectaraComponent=20to=20implement=20Vector=20Store=20using?= =?UTF-8?q?=20Vectara=20=F0=9F=94=A7=20chore(vectorstores):=20add=20empty?= =?UTF-8?q?=20=5F=5Finit=5F=5F.py=20file=20to=20the=20vectorstores=20direc?= =?UTF-8?q?tory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{prompt_runner.py => PromptRunner.py} | 0 .../components/vectorstores/Vectara.py | 46 +++++++++++++++++++ .../components/vectorstores/__init__.py | 0 3 files changed, 46 insertions(+) rename src/backend/langflow/components/chains/{prompt_runner.py => PromptRunner.py} (100%) create mode 100644 src/backend/langflow/components/vectorstores/Vectara.py create mode 100644 src/backend/langflow/components/vectorstores/__init__.py diff --git a/src/backend/langflow/components/chains/prompt_runner.py b/src/backend/langflow/components/chains/PromptRunner.py similarity index 100% rename from src/backend/langflow/components/chains/prompt_runner.py rename to src/backend/langflow/components/chains/PromptRunner.py diff --git a/src/backend/langflow/components/vectorstores/Vectara.py b/src/backend/langflow/components/vectorstores/Vectara.py new file mode 100644 index 000000000..6092b1b04 --- /dev/null +++ b/src/backend/langflow/components/vectorstores/Vectara.py @@ -0,0 +1,46 @@ +from typing import Optional, Union +from langflow import CustomComponent + +from langchain.vectorstores import Vectara +from langchain.schema import Document +from langchain.vectorstores.base import VectorStore +from langchain.schema import BaseRetriever + + +class VectaraComponent(CustomComponent): + display_name: str = "Vectara" + description: str = "Implementation of Vector Store using Vectara" + documentation = ( + "https://python.langchain.com/docs/integrations/vectorstores/vectara" + ) + beta = True + # api key should be password = True + field_config = { + "vectara_customer_id": {"display_name": "Vectara Customer ID"}, + "vectara_corpus_id": {"display_name": "Vectara Corpus ID"}, + "vectara_api_key": {"display_name": "Vectara API Key", "password": True}, + "code": {"show": False}, + "documents": {"display_name": "Documents"}, + } + + def build( + self, + documents: Optional[Document], + vectara_customer_id: str, + vectara_corpus_id: str, + vectara_api_key: str, + ) -> Union[VectorStore, BaseRetriever]: + # If documents, then we need to create a Vectara instance using .from_documents + if documents: + return Vectara.from_documents( + documents=documents, + vectara_customer_id=vectara_customer_id, + vectara_corpus_id=vectara_corpus_id, + vectara_api_key=vectara_api_key, + ) + + return Vectara( + vectara_customer_id=vectara_customer_id, + vectara_corpus_id=vectara_corpus_id, + vectara_api_key=vectara_api_key, + ) diff --git a/src/backend/langflow/components/vectorstores/__init__.py b/src/backend/langflow/components/vectorstores/__init__.py new file mode 100644 index 000000000..e69de29bb From 639550d53757c2e7ebb1dc152d424f1866368bbc Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:26:51 -0300 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=94=A7=20chore(pyproject.toml):=20a?= =?UTF-8?q?dd=20metaphor-python=20dependency=20to=20improve=20code=20analy?= =?UTF-8?q?sis=20and=20documentation=20generation=20=E2=AC=86=EF=B8=8F=20f?= =?UTF-8?q?eat(pyproject.toml):=20upgrade=20black=20dependency=20to=20vers?= =?UTF-8?q?ion=2023.1.0=20for=20code=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- poetry.lock | 16 +++++++++++++++- pyproject.toml | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 7153e89d5..204cdfad2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3315,6 +3315,20 @@ files = [ {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, ] +[[package]] +name = "metaphor-python" +version = "0.1.11" +description = "A Python package for the Metaphor API." +optional = false +python-versions = "*" +files = [ + {file = "metaphor-python-0.1.11.tar.gz", hash = "sha256:80fd993c44cc9d453d99eb65b95147d305f542fdd6fda699e3852e3100beb6ec"}, + {file = "metaphor_python-0.1.11-py3-none-any.whl", hash = "sha256:0d759ecdf73492a4bafd404d0444935c172bcc4a89334f4f6780863ba488b238"}, +] + +[package.dependencies] +requests = "*" + [[package]] name = "monotonic" version = "1.6" @@ -7579,4 +7593,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.11" -content-hash = "cfce7822aedd150c0bda5f0dbf4ada3a3d80d0a7d968c081a5dfd9a61d5088ad" +content-hash = "53bb67a463c4ad0d3dd30c89e30750fc31be5530ee54539d4df34fd82ecf7bc1" diff --git a/pyproject.toml b/pyproject.toml index 86baa264d..db074bdaa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,7 @@ psycopg = "^3.1.9" psycopg-binary = "^3.1.9" fastavro = "^1.8.0" langchain-experimental = "^0.0.8" +metaphor-python = "^0.1.11" [tool.poetry.group.dev.dependencies] black = "^23.1.0" From d16d916952a728a834ef1677efbf82f3fa5391e5 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:28:39 -0300 Subject: [PATCH 04/10] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py)?= =?UTF-8?q?:=20improve=20parsing=20of=20return=20type=20in=20CustomCompone?= =?UTF-8?q?nt=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ feat(custom_component.py): add support for parsing return type when it is a Union of types in CustomComponent class --- .../interface/custom/custom_component.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 8c0b2537a..15a414050 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -118,15 +118,15 @@ class CustomComponent(Component, extra=Extra.allow): build_method = build_methods[0] return_type = build_method["return_type"] - # It could be a type or a Union[type1, type2] - if "Union" in return_type: - return_type = ( - return_type.replace("Union", "").replace("[", "").replace("]", "") - ) - return_type = return_type.split(",") - return_type = [item.strip() for item in return_type] - return [item for item in return_type if item in self.return_type_valid_list] - return build_method["return_type"] + # If the return type is not a Union, then we just return it as a list + if "Union" not in return_type: + return [return_type] if return_type in self.return_type_valid_list else [] + + # If the return type is a Union, then we need to parse it + return_type = return_type.replace("Union", "").replace("[", "").replace("]", "") + return_type = return_type.split(",") + return_type = [item.strip() for item in return_type] + return [item for item in return_type if item in self.return_type_valid_list] @property def get_main_class_name(self): From 38b6831b579faea15fa66f2d4d2125c6697bc9cf Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:29:11 -0300 Subject: [PATCH 05/10] =?UTF-8?q?=E2=9C=A8=20feat(Metaphor.py):=20add=20Me?= =?UTF-8?q?taphorToolkit=20component=20to=20langflow=20toolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MetaphorToolkit component is added to the langflow toolkit. It provides functionality for searching metaphors using the Metaphor API. The component includes three tools: search, get_contents, and find_similar. The search tool allows users to search for metaphors using a query. The get_contents tool retrieves the contents of a webpage based on the ids returned from the search tool. The find_similar tool finds search results similar to a given URL returned from the search tool. The MetaphorToolkit component is still in beta and requires a Metaphor API key to function. The API key is stored securely and can be configured in the field_config of the component. For more information, refer to the documentation: [Metaphor Toolkit Documentation](https://python.langchain.com/docs/integrations/tools/metaphor_search) --- .../langflow/components/toolkits/Metaphor.py | 51 +++++++++++++++++++ .../langflow/components/toolkits/__init__.py | 0 2 files changed, 51 insertions(+) create mode 100644 src/backend/langflow/components/toolkits/Metaphor.py create mode 100644 src/backend/langflow/components/toolkits/__init__.py diff --git a/src/backend/langflow/components/toolkits/Metaphor.py b/src/backend/langflow/components/toolkits/Metaphor.py new file mode 100644 index 000000000..aff949312 --- /dev/null +++ b/src/backend/langflow/components/toolkits/Metaphor.py @@ -0,0 +1,51 @@ +from typing import List, Union +from langflow import CustomComponent + +from metaphor_python import Metaphor +from langchain.tools import Tool +from langchain.agents import tool +from langchain.agents.agent_toolkits.base import BaseToolkit + + +class MetaphorToolkit(CustomComponent): + display_name: str = "Metaphor" + description: str = "Metaphor Toolkit" + documentation = ( + "https://python.langchain.com/docs/integrations/tools/metaphor_search" + ) + beta = True + # api key should be password = True + field_config = { + "metaphor_api_key": {"display_name": "Metaphor API Key", "password": True}, + "code": {"advanced": True}, + } + + def build( + self, + metaphor_api_key: str, + ) -> Union[Tool, BaseToolkit]: + # If documents, then we need to create a Vectara instance using .from_documents + client = Metaphor(api_key=metaphor_api_key) + + @tool + def search(query: str): + """Call search engine with a query.""" + return client.search(query, use_autoprompt=True, num_results=5) + + @tool + def get_contents(ids: List[str]): + """Get contents of a webpage. + + The ids passed in should be a list of ids as fetched from `search`. + """ + return client.get_contents(ids) + + @tool + def find_similar(url: str): + """Get search results similar to a given URL. + + The url passed in should be a URL returned from `search` + """ + return client.find_similar(url, num_results=5) + + return [search, get_contents, find_similar] diff --git a/src/backend/langflow/components/toolkits/__init__.py b/src/backend/langflow/components/toolkits/__init__.py new file mode 100644 index 000000000..e69de29bb From e5e23a1da6e34f4950c601c7ab712fac4cc479e1 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:32:41 -0300 Subject: [PATCH 06/10] =?UTF-8?q?=F0=9F=90=9B=20fix(component.py):=20add?= =?UTF-8?q?=20support=20for=20"documentation"=20field=20in=20template=5Fco?= =?UTF-8?q?nfig=20to=20properly=20handle=20component=20documentation=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20update=5Fattributes=20function?= =?UTF-8?q?=20now=20updates=20frontend=5Fnode=20with=20"documentation"=20f?= =?UTF-8?q?ield=20from=20template=5Fconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/custom/component.py | 3 +++ src/backend/langflow/interface/types.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/backend/langflow/interface/custom/component.py b/src/backend/langflow/interface/custom/component.py index d122eb6da..06db5bd46 100644 --- a/src/backend/langflow/interface/custom/component.py +++ b/src/backend/langflow/interface/custom/component.py @@ -66,6 +66,9 @@ class Component(BaseModel): elif "beta" in item_name: template_config["beta"] = ast.literal_eval(item_value) + elif "documentation" in item_name: + template_config["documentation"] = ast.literal_eval(item_value) + return template_config def build(self, *args: Any, **kwargs: Any) -> Any: diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index 950f227b4..885e33694 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -199,6 +199,9 @@ def update_attributes(frontend_node, template_config): if "beta" in template_config: frontend_node["beta"] = template_config["beta"] + if "documentation" in template_config: + frontend_node["documentation"] = template_config["documentation"] + def build_field_config(custom_component: CustomComponent): """Build the field configuration for a custom component""" From 9bbdd9465b6fc910d594ecd61d4e623ec7b69f13 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:47:22 -0300 Subject: [PATCH 07/10] =?UTF-8?q?=F0=9F=94=A8=20refactor(Vectara.py):=20re?= =?UTF-8?q?organize=20function=20parameters=20for=20better=20readability?= =?UTF-8?q?=20and=20maintainability=20=F0=9F=94=A7=20chore(Vectara.py):=20?= =?UTF-8?q?add=20"embedding"=20parameter=20to=20the=20build=20function=20t?= =?UTF-8?q?o=20support=20custom=20embeddings=20in=20VectaraComponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/components/vectorstores/Vectara.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/components/vectorstores/Vectara.py b/src/backend/langflow/components/vectorstores/Vectara.py index 6092b1b04..6576d146d 100644 --- a/src/backend/langflow/components/vectorstores/Vectara.py +++ b/src/backend/langflow/components/vectorstores/Vectara.py @@ -5,6 +5,7 @@ from langchain.vectorstores import Vectara from langchain.schema import Document from langchain.vectorstores.base import VectorStore from langchain.schema import BaseRetriever +from langchain.embeddings.base import Embeddings class VectaraComponent(CustomComponent): @@ -21,14 +22,16 @@ class VectaraComponent(CustomComponent): "vectara_api_key": {"display_name": "Vectara API Key", "password": True}, "code": {"show": False}, "documents": {"display_name": "Documents"}, + "embedding": {"display_name": "Embedding"}, } def build( self, - documents: Optional[Document], vectara_customer_id: str, vectara_corpus_id: str, vectara_api_key: str, + embedding: Optional[Embeddings] = None, + documents: Optional[Document] = None, ) -> Union[VectorStore, BaseRetriever]: # If documents, then we need to create a Vectara instance using .from_documents if documents: @@ -37,6 +40,7 @@ class VectaraComponent(CustomComponent): vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, + embedding=embedding, ) return Vectara( From 29766ecaf0044bdff053f843141d85bfdf9b194b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:53:18 -0300 Subject: [PATCH 08/10] =?UTF-8?q?=F0=9F=90=9B=20fix(Metaphor.py):=20ignore?= =?UTF-8?q?=20type=20error=20for=20importing=20Metaphor=20from=20metaphor?= =?UTF-8?q?=5Fpython=20=F0=9F=90=9B=20fix(Metaphor.py):=20ignore=20type=20?= =?UTF-8?q?error=20for=20returning=20a=20list=20with=20mixed=20types=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(Vectara.py):=20add=20condition=20to=20check?= =?UTF-8?q?=20if=20documents=20and=20embedding=20are=20not=20None=20before?= =?UTF-8?q?=20creating=20Vectara=20instance=20=F0=9F=90=9B=20fix(CustomCom?= =?UTF-8?q?ponent.py):=20change=20return=20type=20of=20get=5Ffunction=5Fen?= =?UTF-8?q?trypoint=5Freturn=5Ftype=20to=20List[str]=20to=20match=20the=20?= =?UTF-8?q?actual=20return=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/components/toolkits/Metaphor.py | 4 ++-- src/backend/langflow/components/vectorstores/Vectara.py | 4 ++-- src/backend/langflow/interface/custom/custom_component.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backend/langflow/components/toolkits/Metaphor.py b/src/backend/langflow/components/toolkits/Metaphor.py index aff949312..567071278 100644 --- a/src/backend/langflow/components/toolkits/Metaphor.py +++ b/src/backend/langflow/components/toolkits/Metaphor.py @@ -1,7 +1,7 @@ from typing import List, Union from langflow import CustomComponent -from metaphor_python import Metaphor +from metaphor_python import Metaphor # type: ignore from langchain.tools import Tool from langchain.agents import tool from langchain.agents.agent_toolkits.base import BaseToolkit @@ -48,4 +48,4 @@ class MetaphorToolkit(CustomComponent): """ return client.find_similar(url, num_results=5) - return [search, get_contents, find_similar] + return [search, get_contents, find_similar] # type: ignore diff --git a/src/backend/langflow/components/vectorstores/Vectara.py b/src/backend/langflow/components/vectorstores/Vectara.py index 6576d146d..6edc69822 100644 --- a/src/backend/langflow/components/vectorstores/Vectara.py +++ b/src/backend/langflow/components/vectorstores/Vectara.py @@ -34,9 +34,9 @@ class VectaraComponent(CustomComponent): documents: Optional[Document] = None, ) -> Union[VectorStore, BaseRetriever]: # If documents, then we need to create a Vectara instance using .from_documents - if documents: + if documents is not None and embedding is not None: return Vectara.from_documents( - documents=documents, + documents=documents, # type: ignore vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 15a414050..d7dd280e6 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -92,9 +92,9 @@ class CustomComponent(Component, extra=Extra.allow): return build_method["args"] @property - def get_function_entrypoint_return_type(self) -> str: + def get_function_entrypoint_return_type(self) -> List[str]: if not self.code: - return "" + return [] tree = self.get_code_tree(self.code) component_classes = [ @@ -103,7 +103,7 @@ class CustomComponent(Component, extra=Extra.allow): if self.code_class_base_inheritance in cls["bases"] ] if not component_classes: - return "" + return [] # Assume the first Component class is the one we're interested in component_class = component_classes[0] @@ -114,7 +114,7 @@ class CustomComponent(Component, extra=Extra.allow): ] if not build_methods: - return "" + return [] build_method = build_methods[0] return_type = build_method["return_type"] From 89c3306512b987892203ce535e7dccd5f8889704 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 15:53:45 -0300 Subject: [PATCH 09/10] =?UTF-8?q?=F0=9F=94=92=20chore(poetry.lock):=20upda?= =?UTF-8?q?te=20aiofiles=20version=20from=2023.2.0=20to=2023.2.1=20to=20fi?= =?UTF-8?q?x=20a=20bug=20related=20to=20file=20support=20for=20asyncio=20?= =?UTF-8?q?=F0=9F=94=92=20chore(poetry.lock):=20update=20dnspython=20versi?= =?UTF-8?q?on=20from=202.4.1=20to=202.4.2=20to=20fix=20a=20bug=20related?= =?UTF-8?q?=20to=20DNS=20toolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- poetry.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index 204cdfad2..42ea2c718 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,13 +2,13 @@ [[package]] name = "aiofiles" -version = "23.2.0" +version = "23.2.1" description = "File support for asyncio." optional = false python-versions = ">=3.7" files = [ - {file = "aiofiles-23.2.0-py3-none-any.whl", hash = "sha256:d7adbeef4bada163e70bd3163866680332f622b4437d9d8246bd74b6d791d83a"}, - {file = "aiofiles-23.2.0.tar.gz", hash = "sha256:7a321e787cb3839e7d70f56121bf9197a1980609a0fe06a6f96c573406ce4fca"}, + {file = "aiofiles-23.2.1-py3-none-any.whl", hash = "sha256:19297512c647d4b27a2cf7c34caa7e405c0d60b5560618a29a9fe027b18b0107"}, + {file = "aiofiles-23.2.1.tar.gz", hash = "sha256:84ec2218d8419404abcb9f0c02df3f34c6e0a68ed41072acfb1cef5cbc29051a"}, ] [[package]] @@ -1065,13 +1065,13 @@ files = [ [[package]] name = "dnspython" -version = "2.4.1" +version = "2.4.2" description = "DNS toolkit" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "dnspython-2.4.1-py3-none-any.whl", hash = "sha256:5b7488477388b8c0b70a8ce93b227c5603bc7b77f1565afe8e729c36c51447d7"}, - {file = "dnspython-2.4.1.tar.gz", hash = "sha256:c33971c79af5be968bb897e95c2448e11a645ee84d93b265ce0b7aabe5dfdca8"}, + {file = "dnspython-2.4.2-py3-none-any.whl", hash = "sha256:57c6fbaaeaaf39c891292012060beb141791735dbb4004798328fc2c467402d8"}, + {file = "dnspython-2.4.2.tar.gz", hash = "sha256:8dcfae8c7460a2f84b4072e26f1c9f4101ca20c071649cb7c34e8b6a93d58984"}, ] [package.extras] From e1407d059592591d630d7fa88f06498656dc4db3 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Aug 2023 17:12:22 -0300 Subject: [PATCH 10/10] =?UTF-8?q?=F0=9F=94=A7=20chore(Metaphor.py):=20refa?= =?UTF-8?q?ctor=20build=20method=20to=20accept=20additional=20parameters?= =?UTF-8?q?=20for=20improved=20configurability=20=F0=9F=94=A7=20chore(Meta?= =?UTF-8?q?phor.py):=20update=20search=20method=20to=20use=20the=20provide?= =?UTF-8?q?d=20parameters=20for=20use=5Fautoprompt=20and=20search=5Fnum=5F?= =?UTF-8?q?results=20=F0=9F=94=A7=20chore(Metaphor.py):=20update=20find=5F?= =?UTF-8?q?similar=20method=20to=20use=20the=20provided=20parameter=20for?= =?UTF-8?q?=20similar=5Fnum=5Fresults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/components/toolkits/Metaphor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/components/toolkits/Metaphor.py b/src/backend/langflow/components/toolkits/Metaphor.py index 567071278..6f43d24b4 100644 --- a/src/backend/langflow/components/toolkits/Metaphor.py +++ b/src/backend/langflow/components/toolkits/Metaphor.py @@ -23,6 +23,9 @@ class MetaphorToolkit(CustomComponent): def build( self, metaphor_api_key: str, + use_autoprompt: bool = True, + search_num_results: int = 5, + similar_num_results: int = 5, ) -> Union[Tool, BaseToolkit]: # If documents, then we need to create a Vectara instance using .from_documents client = Metaphor(api_key=metaphor_api_key) @@ -30,7 +33,9 @@ class MetaphorToolkit(CustomComponent): @tool def search(query: str): """Call search engine with a query.""" - return client.search(query, use_autoprompt=True, num_results=5) + return client.search( + query, use_autoprompt=use_autoprompt, num_results=search_num_results + ) @tool def get_contents(ids: List[str]): @@ -46,6 +51,6 @@ class MetaphorToolkit(CustomComponent): The url passed in should be a URL returned from `search` """ - return client.find_similar(url, num_results=5) + return client.find_similar(url, num_results=similar_num_results) return [search, get_contents, find_similar] # type: ignore