feat(glm): max_tokens 可选透传(site-import 前置)
max_tokens 探针结论: 8192 可用(glm-4-flash 实测 max_tokens=8192 调用成功返回,finish_reason=stop;Task 5 可按 8192 取值) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""GLMProvider max_tokens 透传(site-import spec §3.2)。"""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from app.engine.providers.glm import GLMProvider
|
||||
|
||||
|
||||
def _provider(**kw):
|
||||
with patch("app.engine.providers.glm.ZhipuAI"):
|
||||
return GLMProvider(api_key="k", **kw)
|
||||
|
||||
|
||||
def _ok(cli):
|
||||
cli.chat.completions.create.return_value.choices = [
|
||||
MagicMock(message=MagicMock(content="ok"))]
|
||||
|
||||
|
||||
class TestMaxTokensPassthrough:
|
||||
def test_默认不传_调用无max_tokens参数(self):
|
||||
import asyncio
|
||||
p = _provider()
|
||||
with patch.object(p, "client") as cli:
|
||||
_ok(cli)
|
||||
asyncio.run(p.chat([{"role": "user", "content": "hi"}], "sys"))
|
||||
_, kwargs = cli.chat.completions.create.call_args
|
||||
assert "max_tokens" not in kwargs
|
||||
|
||||
def test_传入max_tokens_透传到create(self):
|
||||
import asyncio
|
||||
p = _provider(max_tokens=4096)
|
||||
with patch.object(p, "client") as cli:
|
||||
_ok(cli)
|
||||
asyncio.run(p.chat([{"role": "user", "content": "hi"}], "sys"))
|
||||
_, kwargs = cli.chat.completions.create.call_args
|
||||
assert kwargs.get("max_tokens") == 4096
|
||||
Reference in New Issue
Block a user