From c649b449d71efdde03a6d9b74e04029d62858c9f Mon Sep 17 00:00:00 2001 From: Tomaz Bratanic Date: Wed, 4 Sep 2024 22:15:43 +0900 Subject: [PATCH] =?UTF-8?q?Add=20the=20option=20to=20ignore=20structured?= =?UTF-8?q?=20output=20method=20to=20LLM=20graph=20transf=E2=80=A6=20(#260?= =?UTF-8?q?13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Open source models like Llama3.1 have function calling, but it's not that great. Therefore, we introduce the option to ignore model's function calling and just use the prompt-based approach --- .../graph_transformers/llm.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/experimental/langchain_experimental/graph_transformers/llm.py b/libs/experimental/langchain_experimental/graph_transformers/llm.py index 61997a8715d..24b8bff5d13 100644 --- a/libs/experimental/langchain_experimental/graph_transformers/llm.py +++ b/libs/experimental/langchain_experimental/graph_transformers/llm.py @@ -650,6 +650,10 @@ class LLMGraphTransformer: any relationship properties from text. Alternatively, a list of valid properties can be provided for the LLM to extract, restricting extraction to those specified. + ignore_tool_usage (bool): Indicates whether the transformer should + bypass the use of structured output functionality of the language model. + If set to True, the transformer will not use the language model's native + function calling capabilities to handle structured output. Defaults to False. Example: .. code-block:: python @@ -675,16 +679,18 @@ class LLMGraphTransformer: strict_mode: bool = True, node_properties: Union[bool, List[str]] = False, relationship_properties: Union[bool, List[str]] = False, + ignore_tool_usage: bool = False, ) -> None: self.allowed_nodes = allowed_nodes self.allowed_relationships = allowed_relationships self.strict_mode = strict_mode - self._function_call = True + self._function_call = not ignore_tool_usage # Check if the LLM really supports structured output - try: - llm.with_structured_output(_Graph) - except NotImplementedError: - self._function_call = False + if self._function_call: + try: + llm.with_structured_output(_Graph) + except NotImplementedError: + self._function_call = False if not self._function_call: if node_properties or relationship_properties: raise ValueError(