mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-08 13:12:08 +00:00
fix(custom-provider): emit reasoning_effort at the live profile path
PR #57601's original branch added a top-level reasoning_effort emit to the LEGACY build_kwargs path (agent/transports/chat_completions.py), but provider=custom resolves to CustomProfile (plugins/model-providers/custom/), so chat_completion_helpers takes the profile path and returns early — the added branch was unreachable dead code for every custom endpoint. Move the fix to its real site, CustomProfile.build_api_kwargs_extras(), and follow the DeepSeek/Zai profile precedent: - disabled -> extra_body.think = False (unchanged) - enabled + effort -> TOP-LEVEL reasoning_effort (the OpenAI-compatible format GLM-5.2/ARK expect), passed through verbatim incl. max/xhigh - enabled + no effort -> omit, so the endpoint's server default applies (avoids silently forcing 'medium' as the original branch did) Deliberately does NOT force think=True on enable — that flag is Ollama-only and risks a 400 on GLM/vLLM endpoints that don't recognize it; thinking is already server-default-on for these backends. Verified end-to-end through the real profile dispatch (temp HERMES_HOME): custom+high -> reasoning_effort=high; custom+max -> reasoning_effort=max; custom+none -> think=False; custom+unset -> nothing; num_ctx composes. Adds tests/plugins/model_providers/test_custom_profile.py (13 cases). Addresses the custom-provider half of #55276. Co-authored-by: huanshan5195 <huanshan5195@users.noreply.github.com>
This commit is contained in:
parent
a1c17edcbb
commit
67df958dbe
3 changed files with 141 additions and 19 deletions
|
|
@ -1,9 +1,13 @@
|
|||
"""Custom / Ollama (local) provider profile.
|
||||
|
||||
Covers any endpoint registered as provider="custom", including local
|
||||
Ollama instances. Key quirks:
|
||||
Ollama instances and OpenAI-compatible reasoning endpoints (GLM-5.2 on
|
||||
Volcengine ARK, vLLM, llama.cpp). Key quirks:
|
||||
- ollama_num_ctx → extra_body.options.num_ctx (local context window)
|
||||
- reasoning_config disabled → extra_body.think = False
|
||||
- reasoning_config enabled + effort → top-level reasoning_effort
|
||||
(the native OpenAI-compatible format GLM/ARK expect; unset omits it
|
||||
so the endpoint's server default applies)
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
|
@ -23,6 +27,7 @@ class CustomProfile(ProviderProfile):
|
|||
**ctx: Any,
|
||||
) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
extra_body: dict[str, Any] = {}
|
||||
top_level: dict[str, Any] = {}
|
||||
|
||||
# Ollama context window
|
||||
if ollama_num_ctx:
|
||||
|
|
@ -30,14 +35,29 @@ class CustomProfile(ProviderProfile):
|
|||
options["num_ctx"] = ollama_num_ctx
|
||||
extra_body["options"] = options
|
||||
|
||||
# Disable thinking when reasoning is turned off
|
||||
# Reasoning / thinking control for custom OpenAI-compatible endpoints
|
||||
# (GLM-5.2 on Volcengine ARK, vLLM, Ollama, llama.cpp, …).
|
||||
#
|
||||
# - disabled → extra_body.think = False (Ollama's thinking-off flag)
|
||||
# - enabled + effort set → TOP-LEVEL reasoning_effort string, the
|
||||
# format GLM-5.2/ARK and other OpenAI-compatible reasoning APIs
|
||||
# expect (GLM documents "high" and "max"; "max" is its default).
|
||||
# - enabled + no effort → omit both, so the endpoint applies its own
|
||||
# server-side default (do NOT force a level the user didn't pick).
|
||||
#
|
||||
# We deliberately do NOT emit ``think=True`` on enable: it is an
|
||||
# Ollama-only flag and thinking is already server-default-on for these
|
||||
# backends, so forcing it risks a 400 on GLM/vLLM endpoints that don't
|
||||
# recognize it. Mirrors the DeepSeek/Zai profile precedent.
|
||||
if reasoning_config and isinstance(reasoning_config, dict):
|
||||
_effort = (reasoning_config.get("effort") or "").strip().lower()
|
||||
_enabled = reasoning_config.get("enabled", True)
|
||||
if _effort == "none" or _enabled is False:
|
||||
extra_body["think"] = False
|
||||
elif _effort:
|
||||
top_level["reasoning_effort"] = _effort
|
||||
|
||||
return extra_body, {}
|
||||
return extra_body, top_level
|
||||
|
||||
def fetch_models(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue