Switch LLM provider to z.ai GLM

This commit is contained in:
Azimkin
2026-09-21 20:35:08 +02:00
parent 0df55d295c
commit 316eefe58a
10 changed files with 219 additions and 35 deletions

View File

@@ -10,7 +10,7 @@ from llm_trade_bot.config import (
AppConfig,
BraveConfig,
BybitConfig,
DeepSeekConfig,
ZaiConfig,
PromptsConfig,
RiskConfig,
ScannerConfig,
@@ -48,7 +48,7 @@ class FakeBybit:
def make_config(database_path: Path) -> AppConfig:
return AppConfig(
DeepSeekConfig("key"),
ZaiConfig("key"),
BybitConfig("key", "secret"),
TelegramConfig(1, "hash", "token", frozenset({1})),
BraveConfig("key"),

View File

@@ -5,8 +5,8 @@ import pytest
from llm_trade_bot.config import ConfigError, load_config
CONFIG = """
[deepseek]
api_key = "deepseek-key"
[zai]
api_key = "zai-key"
[bybit]
api_key = "bybit-key"
api_secret = "bybit-secret"
@@ -51,7 +51,7 @@ def write_config(tmp_path: Path, content: str = CONFIG) -> Path:
def test_loads_and_resolves_database_path(tmp_path: Path):
path = write_config(tmp_path)
config = load_config(path)
assert config.deepseek.model == "deepseek-flash"
assert config.zai.model == "glm-4.6"
assert config.telegram.admin_user_ids == frozenset({42})
assert config.storage.database_path == tmp_path / "state.db"
assert config.prompts.file_path == tmp_path / "prompts.md"
@@ -63,8 +63,8 @@ def test_rejects_risk_above_hard_limit(tmp_path: Path):
load_config(path)
def test_rejects_non_official_deepseek_endpoint(tmp_path: Path):
changed = CONFIG.replace("api_key = \"deepseek-key\"", 'api_key = "deepseek-key"\nbase_url = "https://example.com"', 1)
def test_rejects_non_official_zai_endpoint(tmp_path: Path):
changed = CONFIG.replace("api_key = \"zai-key\"", 'api_key = "zai-key"\nbase_url = "https://example.com"', 1)
path = write_config(tmp_path, changed)
with pytest.raises(ConfigError, match="base_url"):
load_config(path)

34
tests/test_zai_llm.py Normal file
View File

@@ -0,0 +1,34 @@
from micro_agents.conversation import Conversation, ReasoningMessage, ToolCallMessage, ToolCallResponseMessage, UserMessage
from llm_trade_bot.zai_llm import ZaiLLM
def test_serializes_glm_tool_round_in_chat_completions_format():
conversation = Conversation(
[
UserMessage("analyse BTC"),
ReasoningMessage("I need market data."),
ToolCallMessage("call-1", "get_market_data", {"symbol": "BTCUSDT"}),
ToolCallResponseMessage("call-1", '{"last_price":"100000"}'),
]
)
messages = ZaiLLM._serialize_conversation(conversation, "Follow the risk limits.")
assert messages == [
{"role": "system", "content": "Follow the risk limits."},
{"role": "user", "content": "analyse BTC"},
{
"role": "assistant",
"content": None,
"reasoning_content": "I need market data.",
"tool_calls": [
{
"id": "call-1",
"type": "function",
"function": {"name": "get_market_data", "arguments": '{"symbol":"BTCUSDT"}'},
}
],
},
{"role": "tool", "tool_call_id": "call-1", "content": '{"last_price":"100000"}'},
]