0d6a82ba14
max_tokens 探针结论: 8192 可用(glm-4-flash 实测 max_tokens=8192 调用成功返回,finish_reason=stop;Task 5 可按 8192 取值) Co-Authored-By: Claude Code <noreply@anthropic.com>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""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
|