fix(agent): v4.13.1 - actions contenu document (resume/traduire/ameliorer/meeting) sans outils, apercu + appliquer/rejeter, mock ignore contexte
This commit is contained in:
+50
-1
@@ -661,4 +661,53 @@ def test_router_user_key_test_failure(client, monkeypatch):
|
||||
|
||||
prov = client.get("/api/agent/providers").json()
|
||||
p = [x for x in prov["providers"] if x["id"] == "openai"][0]
|
||||
assert p["functional"] is False
|
||||
assert p["functional"] is False
|
||||
|
||||
|
||||
def test_generate_endpoint_returns_text(client, monkeypatch):
|
||||
"""/api/agent/generate performs headless text generation (no tools)."""
|
||||
from app.routers import agent as agent_router
|
||||
from app.services.llm_client import LLMResponse
|
||||
|
||||
class FakeLLM(agent_router.LLMClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
async def complete(self, messages, *, model=None, tools=None, stream=False):
|
||||
# The tool schema must never be offered for content generation.
|
||||
assert tools is None
|
||||
return LLMResponse(text="Voici le document traduit en anglais.", model="gpt-4o-mini")
|
||||
|
||||
monkeypatch.setattr(agent_router, "LLMClient", FakeLLM)
|
||||
|
||||
r = client.post("/api/agent/generate", json={
|
||||
"prompt": "Traduis ce document en anglais.",
|
||||
"context": "Titre du document : Doc\nContenu en français.",
|
||||
"model": "gpt-4o-mini",
|
||||
})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["ok"] is True
|
||||
assert "traduit en anglais" in body["text"]
|
||||
|
||||
|
||||
def test_generate_endpoint_requires_prompt(client):
|
||||
r = client.post("/api/agent/generate", json={"prompt": " "})
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
def test_mock_planner_ignores_context_keywords(client):
|
||||
"""Document context words (ex: 'cherche', 'collection') must not trigger
|
||||
tool intents — the planner only inspects the user objective."""
|
||||
import asyncio
|
||||
from app.services.llm_client import LLMClient
|
||||
|
||||
llm = LLMClient(provider="offline")
|
||||
resp = asyncio.run(llm.complete(
|
||||
[{"role": "system", "content": "x"},
|
||||
{"role": "user", "content": "Résume ce document.\n\n# Contexte\n"
|
||||
"Le rapport mentionne une recherche sur la collection Z."}],
|
||||
model="gpt-4o", tools=[{"type": "function"}],
|
||||
))
|
||||
assert resp.tool_calls == []
|
||||
assert resp.text
|
||||
Reference in New Issue
Block a user