Skip to content

Commit f72ad2f

Browse files
authored
Parse '<think>' tags in streamed text as thinking parts (HuggingFace) (#2292)
1 parent 22e8778 commit f72ad2f

File tree

5 files changed

+1215
-7
lines changed

5 files changed

+1215
-7
lines changed

pydantic_ai_slim/pydantic_ai/models/huggingface.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,12 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
426426

427427
# Handle the text part of the response
428428
content = choice.delta.content
429-
if content is not None:
430-
yield self._parts_manager.handle_text_delta(vendor_part_id='content', content=content)
429+
if content:
430+
maybe_event = self._parts_manager.handle_text_delta(
431+
vendor_part_id='content', content=content, extract_think_tags=True
432+
)
433+
if maybe_event is not None: # pragma: no branch
434+
yield maybe_event
431435

432436
for dtc in choice.delta.tool_calls or []:
433437
maybe_event = self._parts_manager.handle_tool_call_delta(

pydantic_ai_slim/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ anthropic = ["anthropic>=0.52.0"]
7070
groq = ["groq>=0.19.0"]
7171
mistral = ["mistralai>=1.9.2"]
7272
bedrock = ["boto3>=1.37.24"]
73-
huggingface = ["huggingface-hub[inference]>=0.33.2"]
73+
huggingface = ["huggingface-hub[inference]>=0.33.5"]
7474
# Tools
7575
duckduckgo = ["ddgs>=9.0.0"]
7676
tavily = ["tavily-python>=0.5.0"]

0 commit comments

Comments
 (0)