0
0
LangChainframework~10 mins

Graph nodes and edges in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a graph node with a unique identifier.

LangChain
from langchain.graphs import Node

node = Node(id=[1])
Drag options to blanks, or click blank then click option'
A'node1'
Bnode1
C1
D"node1"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the node ID
Using a variable name without defining it
2fill in blank
medium

Complete the code to add an edge connecting two nodes in the graph.

LangChain
from langchain.graphs import Edge

edge = Edge(source=[1], target="node2")
Drag options to blanks, or click blank then click option'
A"node1"
B'node1'
Cnode1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a variable name instead of a string
Using single quotes inconsistently
3fill in blank
hard

Fix the error in creating a graph node with metadata.

LangChain
node = Node(id="node3", metadata=[1])
Drag options to blanks, or click blank then click option'
A'color: blue'
B['color', 'blue']
C{'color': 'blue'}
D"color: blue"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a dictionary
Passing a string instead of a dictionary
4fill in blank
hard

Fill both blanks to create a graph with two nodes and an edge connecting them.

LangChain
from langchain.graphs import Graph, Node, Edge

node1 = Node(id=[1])
node2 = Node(id=[2])
graph = Graph(nodes=[node1, node2], edges=[Edge(source="node1", target="node2")])
Drag options to blanks, or click blank then click option'
A"node1"
B"node2"
C'node1'
D'node2'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing single and double quotes
Using variable names without quotes
5fill in blank
hard

Fill all three blanks to create a graph with nodes having metadata and an edge connecting them.

LangChain
node1 = Node(id=[1], metadata=[2])
node2 = Node(id="node2", metadata={'type': 'end'})
graph = Graph(nodes=[node1, node2], edges=[Edge(source=[3], target="node2")])
Drag options to blanks, or click blank then click option'
A"node1"
B{'type': 'start'}
D'node1'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of dictionaries for metadata
Not quoting node IDs properly