2026-08-06 11:12:22 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from rag.advanced_rag.agentic_rag import RAGTools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FakeChatModel:
|
|
|
|
|
max_length = 8192
|
|
|
|
|
|
|
|
|
|
def clone(self):
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
2026-08-07 16:04:19 +08:00
|
|
|
async def test_rag_tool_adds_text_attachment_to_user_question(monkeypatch):
|
2026-08-06 11:12:22 +08:00
|
|
|
captured = {}
|
|
|
|
|
|
|
|
|
|
async def fake_run_agentic_rag(tools, messages):
|
|
|
|
|
captured["messages"] = messages
|
|
|
|
|
yield "answer"
|
|
|
|
|
|
|
|
|
|
monkeypatch.setattr("rag.advanced_rag.agentic_rag_graph.run_agentic_rag", fake_run_agentic_rag)
|
|
|
|
|
|
|
|
|
|
tools = RAGTools([], FakeChatModel(), text_attachments_content="attached facts")
|
|
|
|
|
|
|
|
|
|
assert await tools.rag("What is attached?") == "answer"
|
2026-08-07 16:04:19 +08:00
|
|
|
assert captured["messages"] == [{"role": "user", "content": "What is attached?attached facts"}]
|