Skip to content

Commit 4cba52d

Browse files
cosminachoclaude
andcommitted
feat: set default max_tokens, temperature, and max_retries in chat model factory
Restores the historical max_tokens=1000 default from UiPathRequestMixin and adds temperature=0.0 and max_retries=3 defaults so callers no longer get underlying-library defaults (which can be wildly inconsistent across vendors, e.g. Gemini running out of reasoning tokens on small prompts). Also fixes a dead-code fallback in the legacy path that mapped an unset max_tokens to 0 instead of a usable default. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5e8b146 commit 4cba52d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/uipath_langchain/chat/chat_model_factory.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
_UNSET: Final[Any] = object()
2727
DEFAULT_TIMEOUT_SECONDS: Final[float] = 300.0
28+
DEFAULT_MAX_TOKENS: Final[int] = 1000
29+
DEFAULT_TEMPERATURE: Final[float] = 0.0
30+
DEFAULT_MAX_RETRIES: Final[int] = 3
2831

2932

3033
def get_chat_model(
@@ -36,10 +39,10 @@ def get_chat_model(
3639
vendor_type: VendorType | str | None = None,
3740
api_flavor: ApiFlavor | str | None = None,
3841
custom_class: type[UiPathBaseChatModel] | None = None,
39-
temperature: float | None = _UNSET,
40-
max_tokens: int | None = _UNSET,
42+
temperature: float | None = DEFAULT_TEMPERATURE,
43+
max_tokens: int | None = DEFAULT_MAX_TOKENS,
4144
timeout: float | None = DEFAULT_TIMEOUT_SECONDS,
42-
max_retries: int | None = _UNSET,
45+
max_retries: int | None = DEFAULT_MAX_RETRIES,
4346
callbacks: Callbacks = _UNSET,
4447
# Legacy-only arguments
4548
agenthub_config: str | None = None,
@@ -58,10 +61,13 @@ def get_chat_model(
5861
Converse). Auto-detected when omitted.
5962
custom_class: Custom ``UiPathBaseChatModel`` subclass to instantiate
6063
instead of the auto-detected one.
61-
temperature: Sampling temperature. Forwarded only when explicitly set.
62-
max_tokens: Maximum output tokens. Forwarded only when explicitly set.
64+
temperature: Sampling temperature. Defaults to 0.0. Pass ``None`` to
65+
omit the parameter when the underlying client supports it.
66+
max_tokens: Maximum output tokens. Defaults to 1000 to match the
67+
historical default from ``UiPathRequestMixin``. Pass ``None`` to
68+
omit the limit when the underlying client supports it.
6369
timeout: Request timeout in seconds. Defaults to 300 seconds.
64-
max_retries: Max retry count. Forwarded only when explicitly set.
70+
max_retries: Max retry count. Defaults to 3.
6571
callbacks: LangChain callbacks (handlers or a manager) attached to the
6672
returned chat model. Accepts ``list[BaseCallbackHandler]`` or a
6773
``BaseCallbackManager``. Forwarded only when explicitly set.
@@ -132,7 +138,7 @@ def _legacy_chat_model(
132138
return _legacy_get_chat_model(
133139
model,
134140
temperature if temperature is not _UNSET and temperature is not None else 0.0,
135-
max_tokens if max_tokens is not _UNSET and max_tokens is not None else 0,
141+
max_tokens if max_tokens is not _UNSET and max_tokens is not None else DEFAULT_MAX_TOKENS,
136142
agenthub_config,
137143
byo_connection_id,
138144
**kwargs,

0 commit comments

Comments
 (0)