From 4e6febfe7cc95dad0dd22854aeac1f07d0942825 Mon Sep 17 00:00:00 2001 From: Chanwoo Noh Date: Wed, 20 Aug 2025 15:20:03 +0900 Subject: [PATCH 1/3] Fix model name inconsistency in documentation --- docs/api/parser.md | 2 +- docs/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/parser.md b/docs/api/parser.md index 2bd9a08..5934bea 100644 --- a/docs/api/parser.md +++ b/docs/api/parser.md @@ -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: diff --git a/docs/index.md b/docs/index.md index 38dd5a7..a58dd85 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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: From 932584e0ea7af2a934db4299770276a6eaeacd8b Mon Sep 17 00:00:00 2001 From: Chanwoo Noh Date: Wed, 20 Aug 2025 15:26:20 +0900 Subject: [PATCH 2/3] Fix callback event documentation inaccuracies Correct the documentation to accurately reflect which callback events are supported by each streaming type: - Object: on_start, on_complete, on_update - List: on_start, on_complete, on_append - String: on_start, on_complete, on_append - Atom: on_start, on_complete Previously, documentation incorrectly suggested all types support on_append, on_update, and on_complete uniformly. --- README.md | 2 +- docs/api/overview.md | 2 +- docs/api/parser.md | 19 ++++++++++++++++--- docs/index.md | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d1a3ce7..aa7e0d6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Click the image below. ### 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_start`, `on_complete`, and `on_append`/`on_update` depending on type) as tokens stream in. - Derive Pydantic models from LangDiff models for seamless interop with existing libraries and SDKs like OpenAI SDK. diff --git a/docs/api/overview.md b/docs/api/overview.md index fdc0bf9..ec8198b 100644 --- a/docs/api/overview.md +++ b/docs/api/overview.md @@ -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()` diff --git a/docs/api/parser.md b/docs/api/parser.md index 5934bea..8545b06 100644 --- a/docs/api/parser.md +++ b/docs/api/parser.md @@ -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: @@ -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() diff --git a/docs/index.md b/docs/index.md index a58dd85..b005336 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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_start`, `on_complete`, and `on_append`/`on_update` depending on type) as tokens stream in - Derive Pydantic models from LangDiff models for seamless interop with existing libraries and SDKs like OpenAI SDK ### Change Tracking From ae18548c11da1f2dc18c4e6ef772e54a4233bcbb Mon Sep 17 00:00:00 2001 From: Chanwoo Noh Date: Wed, 20 Aug 2025 17:08:27 +0900 Subject: [PATCH 3/3] fix: preserve the original sentence --- README.md | 2 +- docs/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa7e0d6..d1a3ce7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Click the image below. ### Streaming Parsing - Define schemas for streaming structured outputs using Pydantic-style models. -- Receive granular, type-safe callbacks (`on_start`, `on_complete`, and `on_append`/`on_update` depending on type) 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.
diff --git a/docs/index.md b/docs/index.md index b005336..00b079f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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_start`, `on_complete`, and `on_append`/`on_update` depending on type) 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