From 8318b5258efbe689bc02115a701a7474f00cab93 Mon Sep 17 00:00:00 2001 From: WMC001 <46217886+WMC001@users.noreply.github.com> Date: Wed, 26 Aug 2026 10:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20logprobs=20param=20to=20llm?= =?UTF-8?q?=20if=20its=20config=20has=20been=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/agents/create_agent_info.py | 11 ++++++++--- backend/consts/const.py | 5 +++++ deploy/env/.env.example | 5 +++++ sdk/nexent/core/models/openai_llm.py | 9 +++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/backend/agents/create_agent_info.py b/backend/agents/create_agent_info.py index 0854d7cef..0ea6865be 100644 --- a/backend/agents/create_agent_info.py +++ b/backend/agents/create_agent_info.py @@ -74,6 +74,7 @@ AIDP_TENANT_ID, DATA_PROCESS_SERVICE, LANGUAGE, + LLM_INCLUDE_LOGPROBS, LOCAL_MCP_SERVER, MINIO_DEFAULT_BUCKET, MODEL_CONFIG_MAPPING, @@ -856,6 +857,7 @@ def _get_skill_script_tools( async def create_model_config_list(tenant_id): records = get_model_records({"model_type": "llm"}, tenant_id) model_list = [] + extra_body = {"logprobs": True} if LLM_INCLUDE_LOGPROBS else None for record in records: model_list.append( ModelConfig(cite_name=record["display_name"], @@ -880,7 +882,8 @@ async def create_model_config_list(tenant_id): default_output_reserve_tokens=record.get("default_output_reserve_tokens"), tokenizer_family=record.get("tokenizer_family"), capacity_source=record.get("capacity_source"), - capability_profile_version=record.get("capability_profile_version"))) + capability_profile_version=record.get("capability_profile_version"), + extra_body=extra_body)) # fit for old version, main_model and sub_model use default model main_model_config = tenant_config_manager.get_model_config( key=MODEL_CONFIG_MAPPING["llm"], tenant_id=tenant_id) @@ -896,7 +899,8 @@ async def create_model_config_list(tenant_id): model_factory=main_model_config.get("model_factory"), timeout_seconds=main_model_config.get("timeout_seconds"), concurrency_limit=main_model_config.get("concurrency_limit"), - prompt_cache=main_prompt_cache)) + prompt_cache=main_prompt_cache, + extra_body=extra_body)) model_list.append( ModelConfig(cite_name="sub_model", api_key=main_model_config.get("api_key", ""), @@ -907,7 +911,8 @@ async def create_model_config_list(tenant_id): model_factory=main_model_config.get("model_factory"), timeout_seconds=main_model_config.get("timeout_seconds"), concurrency_limit=main_model_config.get("concurrency_limit"), - prompt_cache=main_prompt_cache)) + prompt_cache=main_prompt_cache, + extra_body=extra_body)) return model_list diff --git a/backend/consts/const.py b/backend/consts/const.py index 8af7ad322..7500a8315 100644 --- a/backend/consts/const.py +++ b/backend/consts/const.py @@ -756,5 +756,10 @@ def _resolve_app_version(default: str = "v2.2.1") -> str: "execution_logs", ]) +# LLM Model Configuration +LLM_INCLUDE_LOGPROBS = os.getenv("LLM_INCLUDE_LOGPROBS", "false").lower() == "true" +"""When True, adds logprobs=true to every chat.completions.create request body, +enabling the provider to return log probability information in the response.""" + # SSE streaming event type for status messages STREAM_STATUS_EVENT = "event: stream_status\n" diff --git a/deploy/env/.env.example b/deploy/env/.env.example index 6ce269eb2..7af82e043 100644 --- a/deploy/env/.env.example +++ b/deploy/env/.env.example @@ -150,6 +150,11 @@ DISABLE_CELERY_FLOWER=true DOCKER_ENVIRONMENT=false ENABLE_UPLOAD_IMAGE=false +# LLM Model Configuration +# When true, adds logprobs=true to every chat.completions.create request body, +# enabling the provider to return log probability information in the response. +# Default: false (logprobs disabled, backward-compatible behaviour). +LLM_INCLUDE_LOGPROBS=false # Celery Configuration CELERY_WORKER_PREFETCH_MULTIPLIER=1 diff --git a/sdk/nexent/core/models/openai_llm.py b/sdk/nexent/core/models/openai_llm.py index f749f75b0..7cc1bc161 100644 --- a/sdk/nexent/core/models/openai_llm.py +++ b/sdk/nexent/core/models/openai_llm.py @@ -623,6 +623,15 @@ def _dispatch_chat_completion( caller_value=caller_max_tokens, ) completion_kwargs["max_tokens"] = trusted_max_tokens + logger.info( + "event=chat_completion_create model_id=%s kwargs=%s", + self.model_id, + json.dumps( + {k: v for k, v in completion_kwargs.items() if k != "messages"}, + ensure_ascii=False, + default=str, + ), + ) return self.client.chat.completions.create(**completion_kwargs) @staticmethod