(page: Page, live_server_url: str)
| 100 | |
| 101 | |
| 102 | def test_chat_customization(page: Page, live_server_url: str): |
| 103 | # Set up a mock route to the /chat endpoint |
| 104 | def handle(route: Route): |
| 105 | if route.request.post_data_json: |
| 106 | overrides = route.request.post_data_json["context"]["overrides"] |
| 107 | assert overrides["use_advanced_flow"] is False |
| 108 | assert overrides["retrieval_mode"] == "vectors" |
| 109 | assert overrides["top"] == 1 |
| 110 | assert overrides["prompt_template"] == "You are a cat and only talk about tuna." |
| 111 | |
| 112 | # Read the JSON from our snapshot results and return as the response |
| 113 | f = open("tests/snapshots/test_api_routes/test_simple_chat_flow/simple_chat_flow_response.json") |
| 114 | json = f.read() |
| 115 | f.close() |
| 116 | route.fulfill(body=json, status=200) |
| 117 | |
| 118 | page.route("*/**/chat", handle) |
| 119 | |
| 120 | # Check initial page state |
| 121 | page.goto(live_server_url) |
| 122 | expect(page).to_have_title("RAG on PostgreSQL") |
| 123 | |
| 124 | # Customize all the settings |
| 125 | page.get_by_role("button", name="Developer settings").click() |
| 126 | page.get_by_text( |
| 127 | "Use advanced flow with query rewriting and filter formulation. Not compatible with Ollama models." |
| 128 | ).click() |
| 129 | page.get_by_label("Retrieve this many matching rows:").click() |
| 130 | page.get_by_label("Retrieve this many matching rows:").fill("1") |
| 131 | page.get_by_text("Vectors + Text (Hybrid)").click() |
| 132 | page.get_by_role("option", name="Vectors", exact=True).click() |
| 133 | page.get_by_label("Override prompt template").click() |
| 134 | page.get_by_label("Override prompt template").fill("You are a cat and only talk about tuna.") |
| 135 | |
| 136 | page.get_by_text("Stream chat completion responses").click() |
| 137 | page.locator("button").filter(has_text="Close").click() |
| 138 | |
| 139 | # Ask a question and wait for the message to appear |
| 140 | page.get_by_placeholder("Type a new question (e.g. does my plan cover annual eye exams?)").click() |
| 141 | page.get_by_placeholder("Type a new question (e.g. does my plan cover annual eye exams?)").fill( |
| 142 | "Whats the dental plan?" |
| 143 | ) |
| 144 | page.get_by_role("button", name="Ask question button").click() |
| 145 | |
| 146 | expect(page.get_by_text("Whats the dental plan?")).to_be_visible() |
| 147 | expect(page.get_by_text("The capital of France is Paris.")).to_be_visible() |
| 148 | expect(page.get_by_role("button", name="Clear chat")).to_be_enabled() |
| 149 | |
| 150 | |
| 151 | def test_chat_nonstreaming(page: Page, live_server_url: str): |
nothing calls this directly
no outgoing calls
no test coverage detected