Skip to content

Commit 664847f

Browse files
committed
chore: update graphai docs
1 parent 97320a6 commit 664847f

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,4 @@
246246
"youtube": "https://www.youtube.com/@jamesbriggs"
247247
}
248248
}
249-
}
249+
}

graphai/client-reference/callback.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ conversation/session ID could be used.
2424
- `params` (`dict[str, Any] | None`): The parameters associated with the event, such as tool call parameters
2525
or event metadata.
2626

27+
#### encode
28+
29+
```python
30+
def encode(charset: str = "utf-8") -> bytes
31+
```
32+
33+
Encodes the event as a JSON string, important for compatability with FastAPI
34+
35+
and starlette.
36+
37+
**Arguments**:
38+
39+
- `charset` (`str`): The character set to use for encoding the event.
40+
2741
## Callback Objects
2842

2943
```python

graphai/user-guide/faqs.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
## TypeError: object dict can't be used in 'await' expression
3+
4+
This is a common mistake when defining the graph. The internals of `graphai` expect _all_ nodes to be defined with `async def`. When defining a node with `def` we will see this error:
5+
6+
```
7+
Traceback (most recent call last):
8+
File "/app/.venv/lib/python3.13/site-packages/graphai/graph.py", line 351, in execute
9+
output = await current_node.invoke(input=state, state=self.state)
10+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
File "/app/.venv/lib/python3.13/site-packages/graphai/nodes/base.py", line 152, in invoke
12+
out = await instance.execute(**input)
13+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
File "/app/.venv/lib/python3.13/site-packages/graphai/nodes/base.py", line 74, in execute
15+
return await func(**params_dict) # Pass only the necessary arguments
16+
^^^^^^^^^^^^^^^^^^^^^^^^^
17+
TypeError: object dict can't be used in 'await' expression
18+
```
19+
20+
The solution is to always define nodes using `async def`. For example:
21+
22+
```python
23+
24+
# WRONG:
25+
@node
26+
def my_node(input: dict) -> dict:
27+
return {"output": "Hello, world!"}
28+
29+
# DO THIS INSTEAD:
30+
@node
31+
async def my_node(input: dict) -> dict:
32+
return {"output": "Hello, world!"}
33+
```

0 commit comments

Comments
 (0)