Skip to content

Commit fe93dad

Browse files
committed
Fix RetryPromptPart
1 parent d933b2c commit fe93dad

File tree

1 file changed

+12
-0
lines changed
  • pydantic_ai_slim/pydantic_ai/models

1 file changed

+12
-0
lines changed

pydantic_ai_slim/pydantic_ai/models/xai.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from dataclasses import dataclass
66
from typing import Any, Literal, cast
77

8+
from typing_extensions import assert_never
9+
810
try:
911
import xai_sdk.chat as chat_types
1012

@@ -34,6 +36,7 @@
3436
ModelResponse,
3537
ModelResponsePart,
3638
ModelResponseStreamEvent,
39+
RetryPromptPart,
3740
SystemPromptPart,
3841
TextPart,
3942
ThinkingPart,
@@ -122,6 +125,15 @@ def _map_request_parts(self, parts: Sequence[ModelRequestPart]) -> list[chat_typ
122125
xai_messages.append(user_msg)
123126
elif isinstance(part, ToolReturnPart):
124127
xai_messages.append(tool_result(part.model_response_str()))
128+
elif isinstance(part, RetryPromptPart):
129+
if part.tool_name is None:
130+
# Retry prompt as user message
131+
xai_messages.append(user(part.model_response()))
132+
else:
133+
# Retry prompt as tool result
134+
xai_messages.append(tool_result(part.model_response()))
135+
else:
136+
assert_never(part)
125137

126138
return xai_messages
127139

0 commit comments

Comments
 (0)