Skip to content

Commit 024b1e2

Browse files
authored
add note to docs about .stream_text(delta=True) (#178)
1 parent c496394 commit 024b1e2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/message-history.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult] (returned by [`A
1414
* [`new_messages()`][pydantic_ai.result.RunResult.new_messages]: returns only the messages from the current run, excluding system prompts, this is generally the data you want when you want to use the messages in further runs to continue the conversation. There's also a variant that returns JSON bytes, [`new_messages_json()`][pydantic_ai.result.RunResult.new_messages_json].
1515

1616
!!! info "StreamedRunResult and complete messages"
17-
On [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult], the messages returned from these methods will only include the final response message once the stream has finished.
17+
On [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult], the messages returned from these methods will only include the final result message once the stream has finished.
1818

1919
E.g. you've awaited one of the following coroutines:
2020

@@ -23,6 +23,8 @@ and [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult] (returned by [`A
2323
* [`StreamedRunResult.stream_structured()`][pydantic_ai.result.StreamedRunResult.stream_structured]
2424
* [`StreamedRunResult.get_data()`][pydantic_ai.result.StreamedRunResult.get_data]
2525

26+
**Note:** The final result message will NOT be added to result messages if you use [`.stream_text(delta=True)`][pydantic_ai.result.StreamedRunResult.stream_text] since in this case the result content is never built as one string.
27+
2628
Example of accessing methods on a [`RunResult`][pydantic_ai.result.RunResult] :
2729

2830
```py title="run_result_messages.py" hl_lines="10 28"

docs/results.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ async def main():
214214

215215
_(This example is complete, it can be run "as is")_
216216

217+
!!! warning "Result message not included in `messages`"
218+
The final result message will **NOT** be added to result messages if you use `.stream_text(delta=True)`,
219+
see [Messages and chat history](message-history.md) for more information.
220+
217221
### Streaming Structured Responses
218222

219223
Not all types are supported with partial validation in Pydantic, see [pydantic/pydantic#10748](https://github.com/pydantic/pydantic/pull/10748), generally for model-like structures it's currently best to use `TypeDict`.

0 commit comments

Comments
 (0)