|
24 | 24 | from langchain_core.messages.tool import ToolCallChunk
|
25 | 25 | from langchain_core.messages.tool import ToolMessage
|
26 | 26 | from langchain_core.prompt_values import PromptValue
|
| 27 | +from litellm.utils import get_supported_openai_params |
27 | 28 |
|
28 | 29 | from onyx.configs.app_configs import LOG_DANSWER_MODEL_INTERACTIONS
|
29 | 30 | from onyx.configs.app_configs import MOCK_LLM_RESPONSE
|
|
52 | 53 | _LLM_PROMPT_LONG_TERM_LOG_CATEGORY = "llm_prompt"
|
53 | 54 | VERTEX_CREDENTIALS_FILE_KWARG = "vertex_credentials"
|
54 | 55 | VERTEX_LOCATION_KWARG = "vertex_location"
|
| 56 | +LEGACY_MAX_TOKENS_KWARG = "max_tokens" |
| 57 | +STANDARD_MAX_TOKENS_KWARG = "max_completion_tokens" |
55 | 58 |
|
56 | 59 |
|
57 | 60 | class LLMTimeoutError(Exception):
|
@@ -313,6 +316,14 @@ def __init__(
|
313 | 316 |
|
314 | 317 | self._model_kwargs = model_kwargs
|
315 | 318 |
|
| 319 | + self._max_token_param = LEGACY_MAX_TOKENS_KWARG |
| 320 | + try: |
| 321 | + params = get_supported_openai_params(model_name, model_provider) |
| 322 | + if STANDARD_MAX_TOKENS_KWARG in (params or []): |
| 323 | + self._max_token_param = STANDARD_MAX_TOKENS_KWARG |
| 324 | + except Exception as e: |
| 325 | + logger.warning(f"Error getting supported openai params: {e}") |
| 326 | + |
316 | 327 | def _safe_model_config(self) -> dict:
|
317 | 328 | dump = self.config.model_dump()
|
318 | 329 | dump["api_key"] = mask_string(dump.get("api_key", ""))
|
@@ -393,7 +404,6 @@ def _completion(
|
393 | 404 | messages=processed_prompt,
|
394 | 405 | tools=tools,
|
395 | 406 | tool_choice=tool_choice if tools else None,
|
396 |
| - max_tokens=max_tokens, |
397 | 407 | # streaming choice
|
398 | 408 | stream=stream,
|
399 | 409 | # model params
|
@@ -426,6 +436,7 @@ def _completion(
|
426 | 436 | if structured_response_format
|
427 | 437 | else {}
|
428 | 438 | ),
|
| 439 | + **({self._max_token_param: max_tokens} if max_tokens else {}), |
429 | 440 | **self._model_kwargs,
|
430 | 441 | )
|
431 | 442 | except Exception as e:
|
|
0 commit comments