mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-11 05:45:01 +00:00
Handle Ollama tool raw schema in llmgraphtransformer (#25752)
This commit is contained in:
parent
30f1bf24ac
commit
6703d795c5
@ -479,7 +479,7 @@ def _parse_and_clean_json(
|
|||||||
nodes.append(
|
nodes.append(
|
||||||
Node(
|
Node(
|
||||||
id=node["id"],
|
id=node["id"],
|
||||||
type=node.get("type"),
|
type=node.get("type", "Node"),
|
||||||
properties=node_properties,
|
properties=node_properties,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -584,8 +584,19 @@ def _convert_to_graph_document(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
except Exception: # Google type response
|
except Exception: # Google type response
|
||||||
|
try:
|
||||||
argument_json = json.loads(
|
argument_json = json.loads(
|
||||||
raw_schema["raw"].additional_kwargs["function_call"]["arguments"]
|
raw_schema["raw"].additional_kwargs["function_call"][
|
||||||
|
"arguments"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
except Exception: # Ollama type response
|
||||||
|
argument_json = raw_schema["raw"].tool_calls[0]["args"]
|
||||||
|
if isinstance(argument_json["nodes"], str):
|
||||||
|
argument_json["nodes"] = json.loads(argument_json["nodes"])
|
||||||
|
if isinstance(argument_json["relationships"], str):
|
||||||
|
argument_json["relationships"] = json.loads(
|
||||||
|
argument_json["relationships"]
|
||||||
)
|
)
|
||||||
|
|
||||||
nodes, relationships = _parse_and_clean_json(argument_json)
|
nodes, relationships = _parse_and_clean_json(argument_json)
|
||||||
|
Loading…
Reference in New Issue
Block a user