Skip to content

Commit 4a35644

Browse files
committed
fixed style
1 parent afab5ad commit 4a35644

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

  • src/pydantic_ai_lightspeed/llamastack

src/pydantic_ai_lightspeed/llamastack/_model.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from pydantic_ai import UnexpectedModelBehavior
2727
from pydantic_ai._run_context import RunContext
2828
from pydantic_ai._utils import PeekableAsyncStream, Unset, number_to_datetime
29-
from pydantic_ai.messages import ModelMessage
29+
from pydantic_ai.messages import ModelMessage, ModelResponse
3030
from pydantic_ai.models import (
3131
ModelRequestParameters,
3232
StreamedResponse,
@@ -181,7 +181,7 @@ class LlamaStackResponsesModel(OpenAIResponsesModel):
181181
before the corresponding ``McpCall`` or ``ResponseFunctionToolCall`` item.
182182
"""
183183

184-
async def request(
184+
async def request( # pylint: disable=unused-argument
185185
self,
186186
messages: list[ModelMessage],
187187
model_settings: ModelSettings | None,
@@ -199,9 +199,7 @@ async def request(
199199
messages, model_settings = self._prepare_conversation_continuation(
200200
messages, model_settings
201201
)
202-
return await super().request(
203-
messages, model_settings, model_request_parameters
204-
)
202+
return await super().request(messages, model_settings, model_request_parameters)
205203

206204
def _prepare_conversation_continuation(
207205
self,
@@ -221,25 +219,24 @@ def _prepare_conversation_continuation(
221219
the new input items. Llama Stack reconstructs prior history from the
222220
conversation and appends the new input correctly.
223221
"""
224-
from pydantic_ai.messages import ModelResponse # noqa: PLC0415
225-
226222
if not model_settings or not isinstance(model_settings, dict):
227223
return messages, model_settings
228224

229225
extra_body = model_settings.get("extra_body")
230-
if not extra_body or "conversation" not in extra_body:
226+
if not isinstance(extra_body, dict) or "conversation" not in extra_body:
231227
return messages, model_settings
232228

233229
last_response_idx = None
234230
for i in range(len(messages) - 1, -1, -1):
235-
if isinstance(messages[i], ModelResponse) and messages[i].provider_response_id:
231+
msg = messages[i]
232+
if isinstance(msg, ModelResponse) and msg.provider_response_id:
236233
last_response_idx = i
237234
break
238235

239236
if last_response_idx is None:
240237
return messages, model_settings
241238

242-
trimmed_messages = messages[last_response_idx + 1:]
239+
trimmed_messages = messages[last_response_idx + 1 :]
243240

244241
new_settings = dict(model_settings)
245242
new_settings.pop("openai_previous_response_id", None)

0 commit comments

Comments
 (0)