(page: Page, live_server_url: str)
| 57 | |
| 58 | |
| 59 | def test_chat(page: Page, live_server_url: str): |
| 60 | # Set up a mock route to the /chat endpoint with streaming results |
| 61 | def handle(route: Route): |
| 62 | # Read the JSONL from our snapshot results and return as the response |
| 63 | f = open( |
| 64 | "tests/snapshots/test_api_routes/test_advanced_chat_streaming_flow/advanced_chat_streaming_flow_response.jsonlines" |
| 65 | ) |
| 66 | jsonl = f.read() |
| 67 | f.close() |
| 68 | route.fulfill(body=jsonl, status=200, headers={"Transfer-encoding": "Chunked"}) |
| 69 | |
| 70 | page.route("*/**/chat/stream", handle) |
| 71 | |
| 72 | # Check initial page state |
| 73 | page.goto(live_server_url) |
| 74 | expect(page).to_have_title("RAG on PostgreSQL") |
| 75 | expect(page.get_by_role("heading", name="Product chat")).to_be_visible() |
| 76 | expect(page.get_by_role("button", name="Clear chat")).to_be_disabled() |
| 77 | expect(page.get_by_role("button", name="Developer settings")).to_be_enabled() |
| 78 | |
| 79 | # Ask a question and wait for the message to appear |
| 80 | page.get_by_placeholder("Type a new question (e.g. does my plan cover annual eye exams?)").click() |
| 81 | page.get_by_placeholder("Type a new question (e.g. does my plan cover annual eye exams?)").fill( |
| 82 | "Whats the dental plan?" |
| 83 | ) |
| 84 | page.get_by_role("button", name="Ask question button").click() |
| 85 | |
| 86 | expect(page.get_by_text("Whats the dental plan?")).to_be_visible() |
| 87 | expect(page.get_by_text("The capital of France is Paris.")).to_be_visible() |
| 88 | expect(page.get_by_role("button", name="Clear chat")).to_be_enabled() |
| 89 | |
| 90 | # Show the thought process |
| 91 | page.get_by_label("Show thought process").click() |
| 92 | expect(page.get_by_title("Thought process")).to_be_visible() |
| 93 | expect(page.get_by_text("Prompt to generate search arguments")).to_be_visible() |
| 94 | |
| 95 | # Clear the chat |
| 96 | page.get_by_role("button", name="Clear chat").click() |
| 97 | expect(page.get_by_text("Whats the dental plan?")).not_to_be_visible() |
| 98 | expect(page.get_by_text("The capital of France is Paris.")).not_to_be_visible() |
| 99 | expect(page.get_by_role("button", name="Clear chat")).to_be_disabled() |
| 100 | |
| 101 | |
| 102 | def test_chat_customization(page: Page, live_server_url: str): |
nothing calls this directly
no outgoing calls
no test coverage detected