mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix(fireworks_ai): strip thinking_blocks from chat messages before Fireworks API call (#27881)
* fix(fireworks_ai): strip thinking_blocks from chat messages before API call Fireworks OpenAI-compatible ChatMessage schema uses additionalProperties:false and rejects Anthropic-style messages[].thinking_blocks (e.g. Claude Code replays), returning invalid_request_error. Remove the field in _transform_messages_helper alongside provider_specific_fields. Adds unit test test_transform_messages_helper_strips_thinking_blocks. Co-authored-by: Cursor <cursoragent@cursor.com> * chore(fireworks_ai): drop inline comments from message sanitization Co-authored-by: Cursor <cursoragent@cursor.com> * docs(fireworks_ai): explain why provider_specific_fields and thinking_blocks are stripped Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
b593b88ec6
commit
6274b4c217
2 changed files with 27 additions and 4 deletions
|
|
@ -241,10 +241,13 @@ class FireworksAIConfig(OpenAIGPTConfig):
|
|||
disable_add_transform_inline_image_block=disable_add_transform_inline_image_block,
|
||||
)
|
||||
filter_value_from_dict(cast(dict, message), "cache_control")
|
||||
# Remove fields not permitted by FireworksAI that may cause:
|
||||
# "Not permitted, field: 'messages[n].provider_specific_fields'"
|
||||
if isinstance(message, dict) and "provider_specific_fields" in message:
|
||||
cast(dict, message).pop("provider_specific_fields", None)
|
||||
# Remove fields not permitted by FireworksAI (additionalProperties: false
|
||||
# on their ChatMessage schema) that may cause:
|
||||
# "Extra inputs are not permitted, field: 'messages[n].<field>'"
|
||||
if isinstance(message, dict):
|
||||
m = cast(dict, message)
|
||||
m.pop("provider_specific_fields", None)
|
||||
m.pop("thinking_blocks", None)
|
||||
|
||||
return messages
|
||||
|
||||
|
|
|
|||
|
|
@ -232,3 +232,23 @@ def test_transform_messages_helper_removes_provider_specific_fields():
|
|||
)
|
||||
for msg in out:
|
||||
assert "provider_specific_fields" not in msg
|
||||
|
||||
|
||||
def test_transform_messages_helper_strips_thinking_blocks():
|
||||
"""thinking_blocks must not be forwarded to Fireworks chat completions."""
|
||||
config = FireworksAIConfig()
|
||||
messages = [
|
||||
{"role": "user", "content": "Translate a poem."},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "I can help.",
|
||||
"thinking_blocks": [
|
||||
{"type": "thinking", "thinking": "internal", "signature": ""}
|
||||
],
|
||||
},
|
||||
]
|
||||
out = config._transform_messages_helper(
|
||||
messages, model="accounts/fireworks/models/glm-5p1", litellm_params={}
|
||||
)
|
||||
assert "thinking_blocks" not in out[1]
|
||||
assert out[1]["content"] == "I can help."
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue