fix(chat): simplify header cards and llm fallback
This commit is contained in:
@@ -526,7 +526,7 @@ def test_chat_page_shows_upload_entry_and_dynamic_context_cards(client, db):
|
||||
assert "飞书通知 / 待处理" in content
|
||||
|
||||
|
||||
def test_chat_page_shows_top_context_and_recommended_prompts(client, db):
|
||||
def test_chat_page_keeps_prompts_inside_chat_thread_without_top_cards(client, db):
|
||||
batch, conversation = _create_conversation_with_batch()
|
||||
conversation.task_status = "processing"
|
||||
conversation.node_results = [
|
||||
@@ -545,13 +545,10 @@ def test_chat_page_shows_top_context_and_recommended_prompts(client, db):
|
||||
|
||||
content = response.content.decode("utf-8")
|
||||
assert response.status_code == 200
|
||||
assert "顶部对话上下文" in content
|
||||
assert "当前流程类型" in content
|
||||
assert "registration" in content
|
||||
assert "当前审核阶段" in content
|
||||
assert "顶部对话上下文" not in content
|
||||
assert "推荐提问模板" not in content
|
||||
assert "对话区与节点导航" in content
|
||||
assert "处理中" in content
|
||||
assert "当前最高风险等级" in content
|
||||
assert "推荐提问模板" in content
|
||||
assert "请汇总当前资料包的章节点、页数和目录覆盖情况" in content
|
||||
assert "请给出当前资料包的高风险项、责任人和整改建议" in content
|
||||
|
||||
@@ -583,16 +580,12 @@ def test_chat_page_explicitly_shows_batch_product_stage_and_export_context(clien
|
||||
assert f"批次:{batch.batch_id}" in content
|
||||
assert f"产品:{batch.product_name}" in content
|
||||
assert "阶段:处理中" in content
|
||||
assert "批次编号" in content
|
||||
assert batch.batch_id in content
|
||||
assert "产品名称" in content
|
||||
assert batch.product_name in content
|
||||
assert "当前审核阶段" in content
|
||||
assert "处理中" in content
|
||||
assert "当前最高风险等级" in content
|
||||
assert ">高<" in content
|
||||
assert "批次编号" not in content
|
||||
assert "当前审核阶段" not in content
|
||||
assert "最高风险等级" in content
|
||||
assert "高" in content
|
||||
assert "是否允许正式导出" in content
|
||||
assert ">否<" in content
|
||||
assert "否" in content
|
||||
|
||||
|
||||
def test_chat_page_shows_overview_card_from_conversation_summary(client, db):
|
||||
|
||||
@@ -5,6 +5,8 @@ from agent_core.llm_provider import (
|
||||
create_llm_provider,
|
||||
get_runtime_llm_config,
|
||||
)
|
||||
from urllib.error import HTTPError
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
def test_create_llm_provider_requires_api_key_for_openai_compatible():
|
||||
@@ -72,6 +74,53 @@ def test_openai_compatible_provider_posts_chat_completion(monkeypatch):
|
||||
assert captured["headers"]["Authorization"] == "Bearer sk-test"
|
||||
|
||||
|
||||
def test_openai_compatible_provider_falls_back_when_response_format_is_rejected(monkeypatch):
|
||||
captured_bodies = []
|
||||
|
||||
class FakeResponse:
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, traceback):
|
||||
return False
|
||||
|
||||
def read(self):
|
||||
return b'{"choices":[{"message":{"content":"fallback ok"}}],"model":"demo-model"}'
|
||||
|
||||
def fake_urlopen(request, timeout):
|
||||
body = request.data.decode("utf-8")
|
||||
captured_bodies.append(body)
|
||||
if len(captured_bodies) == 1:
|
||||
raise HTTPError(
|
||||
request.full_url,
|
||||
400,
|
||||
"Bad Request",
|
||||
hdrs=None,
|
||||
fp=BytesIO(b'{"error":{"message":"response_format is not supported"}}'),
|
||||
)
|
||||
return FakeResponse()
|
||||
|
||||
monkeypatch.setattr("agent_core.llm_provider.urlopen", fake_urlopen)
|
||||
provider = create_llm_provider(
|
||||
{
|
||||
"LLM_PROVIDER": "openai_compatible",
|
||||
"LLM_API_KEY": "sk-test",
|
||||
"LLM_BASE_URL": "https://api.siliconflow.cn/v1",
|
||||
"LLM_MODEL": "demo-model",
|
||||
}
|
||||
)
|
||||
|
||||
response = provider.generate(
|
||||
[{"role": "user", "content": "hello"}],
|
||||
response_format={"type": "json_object"},
|
||||
)
|
||||
|
||||
assert response.success is True
|
||||
assert response.content == "fallback ok"
|
||||
assert '"response_format"' in captured_bodies[0]
|
||||
assert '"response_format"' not in captured_bodies[1]
|
||||
|
||||
|
||||
def test_embedding_provider_uses_openai_compatible_embeddings(monkeypatch):
|
||||
class FakeResponse:
|
||||
def __enter__(self):
|
||||
|
||||
Reference in New Issue
Block a user