fix(ai): clarify config save feedback and model selection
This commit was merged in pull request #10.
This commit is contained in:
@@ -71,6 +71,7 @@ def test_model_intent_polls_in_progress_and_retries_invalid_response(workspace,
|
||||
polled["posts"] += 1
|
||||
# 第一次 POST 返回损坏文本(触发整体重试),第二次 POST 返回 in_progress
|
||||
if polled["posts"] == 1:
|
||||
|
||||
class Bad:
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
@@ -87,7 +88,9 @@ def test_model_intent_polls_in_progress_and_retries_invalid_response(workspace,
|
||||
def get(self, *args, **kwargs):
|
||||
polled["n"] += 1
|
||||
assert args[0].endswith("/responses/resp-1")
|
||||
return completed_response({"action": "anomalies", "metric": "revenue", "group": "department", "filters": []})
|
||||
return completed_response(
|
||||
{"action": "anomalies", "metric": "revenue", "group": "department", "filters": []}
|
||||
)
|
||||
|
||||
with patch("finance.assistant.httpx.Client", ClientMock):
|
||||
intent = model_intent("看异常", ds, {"metric": "revenue", "group": "department", "filters": {}})
|
||||
@@ -152,6 +155,34 @@ def test_ai_config_requires_full_admin_and_masks_key(workspace):
|
||||
assert Audit.objects.filter(action="ai_config.update").exists()
|
||||
|
||||
|
||||
def test_ai_config_save_returns_saved_config_and_preserves_masked_key(workspace):
|
||||
ds, _, client, _, _ = workspace
|
||||
payload = {
|
||||
"enabled": True,
|
||||
"provider": "local",
|
||||
"base_url": "http://127.0.0.1:11434/v1/",
|
||||
"api_key": "saved-config-test-secret",
|
||||
"model": "qwen2.5:7b",
|
||||
}
|
||||
|
||||
for api_key, model in [(payload["api_key"], "qwen2.5:7b"), ("", "llama3.1:8b")]:
|
||||
payload.update(api_key=api_key, model=model)
|
||||
response = client.put("/api/ai-config", data=payload, content_type="application/json")
|
||||
assert response.status_code == 200
|
||||
saved = response.json()
|
||||
shown = client.get("/api/ai-config").json()
|
||||
assert saved == {"ok": True, **shown}
|
||||
assert saved["enabled"] is True
|
||||
assert saved["provider"] == "local"
|
||||
assert saved["base_url"] == "http://127.0.0.1:11434/v1"
|
||||
assert saved["model"] == model
|
||||
assert saved["api_key_set"] is True
|
||||
assert saved["updated_at"]
|
||||
assert "api_key" not in saved
|
||||
assert "saved-config-test-secret" not in response.content.decode()
|
||||
assert AIConfig.objects.get(organization=ds.organization).api_key == "saved-config-test-secret"
|
||||
|
||||
|
||||
def test_ai_models_lists_local_models(workspace):
|
||||
ds, _, client, _, _ = workspace
|
||||
client.put(
|
||||
|
||||
Reference in New Issue
Block a user