Skip to content

Commit e75dda3

Browse files
committed
fix: make FunctionParameters and LogitBias OpenAI-compatible
Use Pydantic's RootModel to accept bare JSON Schema dicts instead of requiring a non-standard RootModel wrapper field. This makes m serve compatible with standard OpenAI clients. BREAKING CHANGE: FunctionParameters(RootModel={...}) is now FunctionParameters({...}) Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com> Assisted-by: IBM Bob
1 parent e2e1b5d commit e75dda3

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

cli/serve/models.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Literal
22

3-
from pydantic import BaseModel, Field, model_validator
3+
from pydantic import BaseModel, Field
44

55
from mellea.helpers.openai_compatible_helpers import CompletionUsage
66

@@ -13,9 +13,14 @@ class ChatMessage(BaseModel):
1313
function_call: dict[str, Any] | None = None # For function/tool messages
1414

1515

16-
class FunctionParameters(BaseModel):
17-
# Accept any structure for function parameters
18-
RootModel: dict[str, Any]
16+
class FunctionParameters(RootModel[dict[str, Any]]):
17+
"""OpenAI-compatible function parameters as a bare JSON Schema object.
18+
19+
Accepts a standard JSON Schema dict directly without wrapping.
20+
Example: {"type": "object", "properties": {...}, "required": [...]}
21+
"""
22+
23+
root: dict[str, Any]
1924

2025

2126
class FunctionDefinition(BaseModel):
@@ -73,8 +78,10 @@ class StreamOptions(BaseModel):
7378
"""
7479

7580

76-
class LogitBias(BaseModel):
77-
RootModel: dict[str, float]
81+
class LogitBias(RootModel[dict[str, float]]):
82+
"""OpenAI-compatible logit bias as a bare dict mapping token IDs to bias values."""
83+
84+
root: dict[str, float]
7885

7986

8087
class ChatCompletionRequest(BaseModel):

test/cli/test_serve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ async def test_tool_params_passed_to_model_options(self, mock_module):
462462
function=FunctionDefinition(
463463
name="test_func",
464464
description="A test function",
465-
parameters=FunctionParameters(RootModel={"type": "object"}),
465+
parameters=FunctionParameters({"type": "object"}),
466466
),
467467
)
468468
],
@@ -471,7 +471,7 @@ async def test_tool_params_passed_to_model_options(self, mock_module):
471471
FunctionDefinition(
472472
name="legacy_func",
473473
description="A legacy function",
474-
parameters=FunctionParameters(RootModel={"type": "object"}),
474+
parameters=FunctionParameters({"type": "object"}),
475475
)
476476
],
477477
function_call="auto",

0 commit comments

Comments
 (0)