Skip to content

Commit 65cb2ca

Browse files
committed
max tokens param
1 parent bacee0d commit 65cb2ca

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

backend/onyx/llm/chat_llm.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from langchain_core.messages.tool import ToolCallChunk
2525
from langchain_core.messages.tool import ToolMessage
2626
from langchain_core.prompt_values import PromptValue
27+
from litellm.utils import get_supported_openai_params
2728

2829
from onyx.configs.app_configs import LOG_DANSWER_MODEL_INTERACTIONS
2930
from onyx.configs.app_configs import MOCK_LLM_RESPONSE
@@ -52,6 +53,8 @@
5253
_LLM_PROMPT_LONG_TERM_LOG_CATEGORY = "llm_prompt"
5354
VERTEX_CREDENTIALS_FILE_KWARG = "vertex_credentials"
5455
VERTEX_LOCATION_KWARG = "vertex_location"
56+
LEGACY_MAX_TOKENS_KWARG = "max_tokens"
57+
STANDARD_MAX_TOKENS_KWARG = "max_completion_tokens"
5558

5659

5760
class LLMTimeoutError(Exception):
@@ -313,6 +316,14 @@ def __init__(
313316

314317
self._model_kwargs = model_kwargs
315318

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+
316327
def _safe_model_config(self) -> dict:
317328
dump = self.config.model_dump()
318329
dump["api_key"] = mask_string(dump.get("api_key", ""))
@@ -393,7 +404,6 @@ def _completion(
393404
messages=processed_prompt,
394405
tools=tools,
395406
tool_choice=tool_choice if tools else None,
396-
max_tokens=max_tokens,
397407
# streaming choice
398408
stream=stream,
399409
# model params
@@ -426,6 +436,7 @@ def _completion(
426436
if structured_response_format
427437
else {}
428438
),
439+
**({self._max_token_param: max_tokens} if max_tokens else {}),
429440
**self._model_kwargs,
430441
)
431442
except Exception as e:

0 commit comments

Comments
 (0)