mirror of
https://github.com/ollama/ollama-python.git
synced 2026-10-06 09:07:23 +00:00
client: widen sync generate think type to accept string levels (#697)
This commit is contained in:
+3
-3
@@ -209,7 +209,7 @@ class Client(BaseClient):
|
|||||||
template: str = '',
|
template: str = '',
|
||||||
context: Optional[Sequence[int]] = None,
|
context: Optional[Sequence[int]] = None,
|
||||||
stream: Literal[False] = False,
|
stream: Literal[False] = False,
|
||||||
think: Optional[bool] = None,
|
think: Optional[Union[bool, Literal['low', 'medium', 'high']]] = None,
|
||||||
logprobs: Optional[bool] = None,
|
logprobs: Optional[bool] = None,
|
||||||
top_logprobs: Optional[int] = None,
|
top_logprobs: Optional[int] = None,
|
||||||
raw: bool = False,
|
raw: bool = False,
|
||||||
@@ -233,7 +233,7 @@ class Client(BaseClient):
|
|||||||
template: str = '',
|
template: str = '',
|
||||||
context: Optional[Sequence[int]] = None,
|
context: Optional[Sequence[int]] = None,
|
||||||
stream: Literal[True] = True,
|
stream: Literal[True] = True,
|
||||||
think: Optional[bool] = None,
|
think: Optional[Union[bool, Literal['low', 'medium', 'high']]] = None,
|
||||||
logprobs: Optional[bool] = None,
|
logprobs: Optional[bool] = None,
|
||||||
top_logprobs: Optional[int] = None,
|
top_logprobs: Optional[int] = None,
|
||||||
raw: bool = False,
|
raw: bool = False,
|
||||||
@@ -256,7 +256,7 @@ class Client(BaseClient):
|
|||||||
template: Optional[str] = None,
|
template: Optional[str] = None,
|
||||||
context: Optional[Sequence[int]] = None,
|
context: Optional[Sequence[int]] = None,
|
||||||
stream: bool = False,
|
stream: bool = False,
|
||||||
think: Optional[bool] = None,
|
think: Optional[Union[bool, Literal['low', 'medium', 'high']]] = None,
|
||||||
logprobs: Optional[bool] = None,
|
logprobs: Optional[bool] = None,
|
||||||
top_logprobs: Optional[int] = None,
|
top_logprobs: Optional[int] = None,
|
||||||
raw: Optional[bool] = None,
|
raw: Optional[bool] = None,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import base64
|
import base64
|
||||||
|
import inspect
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -1486,3 +1487,13 @@ async def test_async_client_context_manager():
|
|||||||
assert not client._client.is_closed
|
assert not client._client.is_closed
|
||||||
|
|
||||||
assert client._client.is_closed
|
assert client._client.is_closed
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_think_annotation_matches_chat():
|
||||||
|
# The `think` parameter accepts bool or the 'low'/'medium'/'high' string levels.
|
||||||
|
# Client.generate must keep the same annotation as Client.chat and
|
||||||
|
# AsyncClient.generate so passing a string level does not raise a false type
|
||||||
|
# error (regression guard for the sync generate overloads/implementation).
|
||||||
|
expected = inspect.signature(Client.chat).parameters['think'].annotation
|
||||||
|
assert inspect.signature(Client.generate).parameters['think'].annotation == expected
|
||||||
|
assert inspect.signature(AsyncClient.generate).parameters['think'].annotation == expected
|
||||||
|
|||||||
Reference in New Issue
Block a user