Skip to content

Commit 9091749

Browse files
committed
wrap serialize to use alias
1 parent 8a52e8e commit 9091749

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ollama/_types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ class Function(SubscriptableBaseModel):
308308

309309
class Parameters(SubscriptableBaseModel):
310310
model_config = ConfigDict(populate_by_name=True)
311-
312311
type: Optional[Literal['object']] = 'object'
313312
defs: Optional[Any] = Field(None, alias='$defs')
314313
items: Optional[Any] = None
@@ -330,6 +329,15 @@ class Property(SubscriptableBaseModel):
330329

331330

332331
class ChatRequest(BaseGenerateRequest):
332+
@model_serializer(mode='wrap')
333+
def serialize_model(self, nxt):
334+
output = nxt(self)
335+
if 'tools' in output and output['tools']:
336+
for tool in output['tools']:
337+
if 'function' in tool and 'parameters' in tool['function'] and 'defs' in tool['function']['parameters']:
338+
tool['function']['parameters']['$defs'] = tool['function']['parameters'].pop('defs')
339+
return output
340+
333341
messages: Optional[Sequence[Union[Mapping[str, Any], Message]]] = None
334342
'Messages to chat with.'
335343

0 commit comments

Comments
 (0)