mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 14:49:29 +00:00
Add the option to ignore structured output method to LLM graph transf… (#26013)
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
This commit is contained in:
parent
34fc00aff1
commit
c649b449d7
@ -650,6 +650,10 @@ class LLMGraphTransformer:
|
|||||||
any relationship properties from text. Alternatively, a list of valid
|
any relationship properties from text. Alternatively, a list of valid
|
||||||
properties can be provided for the LLM to extract, restricting extraction to
|
properties can be provided for the LLM to extract, restricting extraction to
|
||||||
those specified.
|
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:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
@ -675,12 +679,14 @@ class LLMGraphTransformer:
|
|||||||
strict_mode: bool = True,
|
strict_mode: bool = True,
|
||||||
node_properties: Union[bool, List[str]] = False,
|
node_properties: Union[bool, List[str]] = False,
|
||||||
relationship_properties: Union[bool, List[str]] = False,
|
relationship_properties: Union[bool, List[str]] = False,
|
||||||
|
ignore_tool_usage: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.allowed_nodes = allowed_nodes
|
self.allowed_nodes = allowed_nodes
|
||||||
self.allowed_relationships = allowed_relationships
|
self.allowed_relationships = allowed_relationships
|
||||||
self.strict_mode = strict_mode
|
self.strict_mode = strict_mode
|
||||||
self._function_call = True
|
self._function_call = not ignore_tool_usage
|
||||||
# Check if the LLM really supports structured output
|
# Check if the LLM really supports structured output
|
||||||
|
if self._function_call:
|
||||||
try:
|
try:
|
||||||
llm.with_structured_output(_Graph)
|
llm.with_structured_output(_Graph)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
|
Loading…
Reference in New Issue
Block a user