mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix: also strip extra fields in image/file message paths for Mistral
_extract_fields helper now also runs in _transform_messages_sync and _transform_messages_async for the image/file early-return path, preventing the same "Extra inputs are not permitted" error when messages mix image/file content with extra fields.
This commit is contained in:
parent
d19d83925c
commit
159a5e47f7
1 changed files with 11 additions and 1 deletions
|
|
@ -287,7 +287,7 @@ class MistralConfig(OpenAIGPTConfig):
|
|||
# and then apply Mistral-specific handling for files
|
||||
messages = await super()._transform_messages(messages, model, True)
|
||||
messages = self._handle_message_with_file(messages)
|
||||
return messages
|
||||
return self._strip_extra_fields(messages)
|
||||
|
||||
def _transform_messages_sync(self, messages: List[AllMessageValues], model: str) -> List[AllMessageValues]:
|
||||
"""Handle modification of messages for Mistral API in a sync context."""
|
||||
|
|
@ -296,6 +296,16 @@ class MistralConfig(OpenAIGPTConfig):
|
|||
# This is the sync version of the async method above
|
||||
messages = super()._transform_messages(messages, model, False)
|
||||
messages = self._handle_message_with_file(messages)
|
||||
return self._strip_extra_fields(messages)
|
||||
|
||||
@staticmethod
|
||||
def _strip_extra_fields(messages: List[AllMessageValues]) -> List[AllMessageValues]:
|
||||
for m in messages:
|
||||
if isinstance(m, dict):
|
||||
m.pop("metadata", None)
|
||||
m.pop("provider_specific_fields", None)
|
||||
m.pop("thinking_blocks", None)
|
||||
m.pop("cache_control", None)
|
||||
return messages
|
||||
|
||||
def _handle_message_with_file(self, messages: List[AllMessageValues]) -> List[AllMessageValues]:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue