Skip to content

Commit cbcd26e

Browse files
committed
types: allow allow single or multiple types tool property
1 parent 3eaa837 commit cbcd26e

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

ollama/_client.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ipaddress
22
import json
3+
from rich import print
34
import os
45
import platform
56
import sys
@@ -330,19 +331,21 @@ def add_two_numbers(a: int, b: int) -> int:
330331
331332
Returns `ChatResponse` if `stream` is `False`, otherwise returns a `ChatResponse` generator.
332333
"""
334+
request_data = ChatRequest(
335+
model=model,
336+
messages=[message for message in _copy_messages(messages)],
337+
tools=[tool for tool in _copy_tools(tools)],
338+
stream=stream,
339+
format=format,
340+
options=options,
341+
keep_alive=keep_alive,
342+
).model_dump(exclude_none=True)
343+
print('Sending chat request to Ollama API:', request_data)
333344
return self._request(
334345
ChatResponse,
335346
'POST',
336347
'/api/chat',
337-
json=ChatRequest(
338-
model=model,
339-
messages=[message for message in _copy_messages(messages)],
340-
tools=[tool for tool in _copy_tools(tools)],
341-
stream=stream,
342-
format=format,
343-
options=options,
344-
keep_alive=keep_alive,
345-
).model_dump(exclude_none=True),
348+
json=request_data,
346349
stream=stream,
347350
)
348351

ollama/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class Parameters(SubscriptableBaseModel):
313313
class Property(SubscriptableBaseModel):
314314
model_config = ConfigDict(arbitrary_types_allowed=True)
315315

316-
type: Optional[str] = None
316+
type: Optional[Union[str, Sequence[str]]] = None
317317
description: Optional[str] = None
318318

319319
properties: Optional[Mapping[str, Property]] = None

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def func2(y: str) -> int:
11391139
'description': 'Test function',
11401140
'parameters': {
11411141
'type': 'object',
1142-
'properties': {'x': {'type': 'string', 'description': 'A string'}},
1142+
'properties': {'x': {'type': 'string', 'description': 'A string', 'enum': ['a', 'b', 'c']}, 'y': {'type': ['integer', 'number'], 'description': 'An integer'}},
11431143
'required': ['x'],
11441144
},
11451145
},

0 commit comments

Comments
 (0)