[Bug Fix] [Bug]: New Databricks Foundation Models databricks-gpt-oss-20b and databricks-gpt-oss-120b failed with error: litellm.APIConnectionError: 'signature' (#13318)

* test_transform_choices_without_signature

* fix ChatCompletionThinkingBlock

* extract_reasoning_content
This commit is contained in:
Ishaan Jaff 2025-08-05 17:46:40 -07:00 committed by GitHub
parent dab8ba03e3
commit b455ada161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 4 deletions

View file

@ -371,8 +371,8 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig):
reasoning_content += sum["text"]
thinking_block = ChatCompletionThinkingBlock(
type="thinking",
thinking=sum["text"],
signature=sum["signature"],
thinking=sum.get("text", ""),
signature=sum.get("signature", ""),
)
if thinking_blocks is None:
thinking_blocks = []

View file

@ -1,6 +1,6 @@
model_list:
- model_name: vertex_ai/*
- model_name: anthropic/*
litellm_params:
model: vertex_ai/*
model: anthropic/*

View file

@ -45,3 +45,48 @@ def test_transform_choices():
assert choices[0].message.reasoning_content == "i'm thinking."
assert choices[0].message.thinking_blocks is not None
assert choices[0].message.tool_calls is None
def test_transform_choices_without_signature():
"""
Test that the transformation works correctly when the signature field is missing
from the summary, which occurs with new Databricks Foundation Models like
databricks-gpt-oss-20b and databricks-gpt-oss-120b.
"""
config = DatabricksConfig()
databricks_choices = [
{
"message": {
"role": "assistant",
"content": [
{
"type": "reasoning",
"summary": [
{
"type": "summary_text",
"text": "i'm thinking without signature.",
# Note: no signature field here
}
],
},
{"type": "text", "text": "Response without signature"},
],
},
"index": 0,
"finish_reason": "stop",
}
]
# This should not raise a KeyError for missing signature
choices = config._transform_dbrx_choices(choices=databricks_choices)
assert len(choices) == 1
assert choices[0].message.content == "Response without signature"
assert choices[0].message.reasoning_content == "i'm thinking without signature."
assert choices[0].message.thinking_blocks is not None
assert len(choices[0].message.thinking_blocks) == 1
# Verify the thinking block was created successfully without signature
thinking_block = choices[0].message.thinking_blocks[0]
assert thinking_block["type"] == "thinking"
assert thinking_block["thinking"] == "i'm thinking without signature."