-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JSON representation of runnable graph to serialized representation #17745
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
a59a77f
to
b871c58
Compare
"data": node_data_str(node), | ||
} | ||
|
||
|
||
@dataclass | ||
class Graph: | ||
"""Graph of nodes and edges.""" | ||
|
||
nodes: Dict[str, Node] = field(default_factory=dict) | ||
edges: List[Edge] = field(default_factory=list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are edges in both directions allowed simultaneously?
i.e., if there's node 1 and 2
can we get edge 1 -> 2 and edge 2 -> 1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory possible yea
@@ -53,13 +149,13 @@ def remove_node(self, node: Node) -> None: | |||
if edge.source != node.id and edge.target != node.id | |||
] | |||
|
|||
def add_edge(self, source: Node, target: Node) -> Edge: | |||
def add_edge(self, source: Node, target: Node, data: Optional[str] = None) -> Edge: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I generally prefer *
prior to all arguments with None defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such a neat feature!
@dataclass | ||
class Graph: | ||
"""Graph of nodes and edges.""" | ||
|
||
nodes: Dict[str, Node] = field(default_factory=dict) | ||
edges: List[Edge] = field(default_factory=list) | ||
|
||
def to_json(self) -> Dict[str, List[Dict[str, Any]]]: | ||
"""Convert the graph to a JSON-serializable format.""" | ||
stable_node_ids = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does stable mean here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ic, so that two graphs with equivalent objects and edges would have same serialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically if you generate the same chain twice you should get same json graph
@@ -11,11 +12,20 @@ | |||
from langchain_core.runnables.base import Runnable as RunnableType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated but why the rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it cause issues when you actually import in functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea because I need to import the actual class inside a function
Does this indicate that graph will support a load from JSON?!?!?! |
langchain-ai#17745) Sent to LangSmith Thank you for contributing to LangChain! Checklist: - [ ] PR title: Please title your PR "package: description", where "package" is whichever of langchain, community, core, experimental, etc. is being modified. Use "docs: ..." for purely docs changes, "templates: ..." for template changes, "infra: ..." for CI changes. - Example: "community: add foobar LLM" - [ ] PR message: **Delete this entire template message** and replace it with the following bulleted list - **Description:** a description of the change - **Issue:** the issue # it fixes, if applicable - **Dependencies:** any dependencies required for this change - **Twitter handle:** if your PR gets announced, and you'd like a mention, we'll gladly shout you out! - [ ] Pass lint and test: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified to check that you're passing lint and testing. See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/ - [ ] Add tests and docs: If you're adding a new integration, please include 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17.
Sent to LangSmith
Thank you for contributing to LangChain!
Checklist:
make format
,make lint
andmake test
from the root of the package(s) you've modified to check that you're passing lint and testing. See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/docs/docs/integrations
directory.Additional guidelines:
If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17.