|
62 | 62 | convert_to_openai_tool, |
63 | 63 | ) |
64 | 64 | from langchain_core.utils.pydantic import is_basemodel_subclass |
65 | | -from pydantic import AliasChoices, BaseModel, ConfigDict, Field |
| 65 | +from pydantic import AliasChoices, BaseModel, Field |
66 | 66 |
|
67 | 67 | from uipath_langchain_client.base_client import UiPathBaseChatModel |
68 | 68 | from uipath_langchain_client.settings import ApiType, RoutingMode, UiPathAPIConfig |
|
72 | 72 | _DictOrPydantic = Union[dict[str, Any], BaseModel] |
73 | 73 |
|
74 | 74 |
|
75 | | -# Sentinel — params whose value is still _UNSET are omitted from the request payload. |
76 | | -_UNSET: Any = object() |
77 | | - |
78 | | - |
79 | 75 | def _oai_structured_outputs_parser(ai_msg: AIMessage, schema: type[BaseModel]) -> BaseModel: |
80 | 76 | if not ai_msg.content: |
81 | 77 | raise ValueError("Expected non-empty content from model.") |
@@ -162,50 +158,48 @@ class UiPathChat(UiPathBaseChatModel): |
162 | 158 | freeze_base_url=True, |
163 | 159 | ) |
164 | 160 |
|
165 | | - model_config = ConfigDict(validate_default=False) |
166 | | - |
167 | 161 | # Common |
168 | 162 | max_tokens: int | None = Field( |
169 | | - default=_UNSET, |
| 163 | + default=None, |
170 | 164 | validation_alias=AliasChoices("max_tokens", "max_output_tokens", "max_completion_tokens"), |
171 | 165 | ) |
172 | | - temperature: float | None = _UNSET # type: ignore[assignment] |
173 | | - top_p: float | None = _UNSET # type: ignore[assignment] |
174 | | - top_k: int | None = _UNSET # type: ignore[assignment] |
| 166 | + temperature: float | None = None |
| 167 | + top_p: float | None = None |
| 168 | + top_k: int | None = None |
175 | 169 | stop: list[str] | str | None = Field( |
176 | | - default=_UNSET, |
| 170 | + default=None, |
177 | 171 | validation_alias=AliasChoices("stop", "stop_sequences"), |
178 | 172 | ) |
179 | 173 | n: int | None = Field( |
180 | | - default=_UNSET, |
| 174 | + default=None, |
181 | 175 | validation_alias=AliasChoices("n", "candidate_count"), |
182 | 176 | ) |
183 | | - frequency_penalty: float | None = _UNSET # type: ignore[assignment] |
184 | | - presence_penalty: float | None = _UNSET # type: ignore[assignment] |
185 | | - seed: int | None = _UNSET # type: ignore[assignment] |
| 177 | + frequency_penalty: float | None = None |
| 178 | + presence_penalty: float | None = None |
| 179 | + seed: int | None = None |
186 | 180 |
|
187 | 181 | model_kwargs: dict[str, Any] = Field(default_factory=dict) |
188 | 182 | disabled_params: dict[str, Any] | None = None |
189 | 183 |
|
190 | 184 | # OpenAI |
191 | | - logit_bias: dict[str, int] | None = _UNSET # type: ignore[assignment] |
192 | | - logprobs: bool | None = _UNSET # type: ignore[assignment] |
193 | | - top_logprobs: int | None = _UNSET # type: ignore[assignment] |
194 | | - parallel_tool_calls: bool | None = _UNSET # type: ignore[assignment] |
195 | | - reasoning_effort: str | None = _UNSET # type: ignore[assignment] |
196 | | - reasoning: dict[str, Any] | None = _UNSET # type: ignore[assignment] |
| 185 | + logit_bias: dict[str, int] | None = None |
| 186 | + logprobs: bool | None = None |
| 187 | + top_logprobs: int | None = None |
| 188 | + parallel_tool_calls: bool | None = None |
| 189 | + reasoning_effort: str | None = None |
| 190 | + reasoning: dict[str, Any] | None = None |
197 | 191 |
|
198 | 192 | # Anthropic |
199 | | - thinking: dict[str, Any] | None = _UNSET # type: ignore[assignment] |
| 193 | + thinking: dict[str, Any] | None = None |
200 | 194 |
|
201 | 195 | # Google |
202 | | - thinking_level: str | None = _UNSET # type: ignore[assignment] |
203 | | - thinking_budget: int | None = _UNSET # type: ignore[assignment] |
204 | | - include_thoughts: bool | None = _UNSET # type: ignore[assignment] |
205 | | - safety_settings: list[dict[str, Any]] | None = _UNSET # type: ignore[assignment] |
| 196 | + thinking_level: str | None = None |
| 197 | + thinking_budget: int | None = None |
| 198 | + include_thoughts: bool | None = None |
| 199 | + safety_settings: list[dict[str, Any]] | None = None |
206 | 200 |
|
207 | 201 | # Shared |
208 | | - verbosity: str | None = _UNSET # type: ignore[assignment] |
| 202 | + verbosity: str | None = None |
209 | 203 |
|
210 | 204 | @property |
211 | 205 | def _llm_type(self) -> str: |
@@ -248,8 +242,9 @@ def _default_params(self) -> dict[str, Any]: |
248 | 242 | "verbosity": self.verbosity, |
249 | 243 | } |
250 | 244 |
|
| 245 | + set_fields = self.model_fields_set |
251 | 246 | return { |
252 | | - **{k: v for k, v in candidates.items() if v is not _UNSET}, |
| 247 | + **{k: v for k, v in candidates.items() if k in set_fields}, |
253 | 248 | **self.model_kwargs, |
254 | 249 | } |
255 | 250 |
|
|
0 commit comments