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
|