Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The parser module contains streaming-aware data types and the core parser for pr

### Key Features

- **Event Callbacks**: All streaming types support `on_start`, `on_append`, and `on_complete` callbacks
- **Event Callbacks**: All streaming types support `on_start` and `on_complete` callbacks. Additionally, `Object` supports `on_update`, while `List` and `String` support `on_append`
- **Type Safety**: Full type hints and generic support for compile-time checking
- **Pydantic Integration**: Convert streaming models to Pydantic models via `to_pydantic()`

Expand Down
21 changes: 17 additions & 4 deletions docs/api/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ response_format = BlogPost.to_pydantic()

client = openai.OpenAI()
with client.chat.completions.stream(
model="gpt-4o-mini",
model="gpt-5-mini",
messages=[{"role": "user", "content": "Write a blog post"}],
response_format=response_format,
) as stream:
Expand All @@ -130,7 +130,7 @@ with client.chat.completions.stream(

## Event System

All streaming types support three main events:
All streaming types support common events, with type-specific additional events:

### on_start()
Called when streaming begins for a value:
Expand All @@ -142,12 +142,25 @@ def on_title_start():
```

### on_append()
Called as new data is appended:
Called as new data is appended (supported by `String` and `List` types):

```python
@response.content.on_append
@response.content.on_append # String type
def on_content_chunk(chunk: str):
print(f"New content: {chunk}")

@response.items.on_append # List type
def on_item_append(item: ld.String, index: int):
print(f"New item at index {index}")
```

### on_update()
Called when an object is updated (supported by `Object` type only):

```python
@response.on_update # Object type
def on_object_update(data: dict):
print(f"Object updated: {data}")
```

### on_complete()
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LangDiff provides intelligent partial parsing with granular, type-safe events as

### Streaming Parsing
- Define schemas for streaming structured outputs using Pydantic-style models
- Receive granular, type-safe callbacks (`on_append`, `on_update`, `on_complete`) as tokens stream in
- Receive granular, type-safe callbacks (`on_append`, `on_update`, `on_complete`) as tokens stream in.
- Derive Pydantic models from LangDiff models for seamless interop with existing libraries and SDKs like OpenAI SDK

### Change Tracking
Expand Down Expand Up @@ -69,7 +69,7 @@ def on_section_append(section: ld.String, index: int):
# Stream from OpenAI
client = openai.OpenAI()
with client.chat.completions.stream(
model="gpt-4o-mini",
model="gpt-5-mini",
messages=[{"role": "user", "content": "Write a short article about Python"}],
response_format=ArticleResponse.to_pydantic(),
) as stream:
Expand Down