Skip to content

Commit 104100c

Browse files
committed
add more keywords, and retry another question
Signed-off-by: cheehook <[email protected]>
1 parent 404ccfd commit 104100c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

tests/playwright/studio-e2e/002_test_sandbox_chatqna.spec.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const uploadPDF1 = path.resolve(__dirname, '../../test-files/tennis_tutorial.pdf
77
const uploadPDF2 = path.resolve(__dirname, '../../test-files/Q3 24_EarningsRelease.pdf');
88

99
const question = "what is intel third-quarter 2024 revenue?";
10-
const keyword = "billion"; // more keywords needed
10+
const keywords = ["billion", "$13.3", "$13.3-14.3", "above the midpoint", "guidance"]; // more keywords needed
11+
12+
function containsAnyKeyword(response: string, keywords: string[]): boolean {
13+
return keywords.some((keyword) => response.includes(keyword.replace(/\s+/g, '')));
14+
}
1115

1216
async function setupResponseListener(page, apiResponse) {
1317
page.on('response', async (response) => {
@@ -67,7 +71,7 @@ test('002_test_sandbox_chatqna', async ({ page, baseURL }) => {
6771
await page2.getByPlaceholder('Ask a question').fill(question);
6872
await page2.getByRole('button').nth(3).click();
6973
await page2.waitForTimeout(10000);
70-
let responseContainsKeyword = apiResponse && apiResponse.value.includes(keyword.replace(/\s+/g, ''));
74+
let responseContainsKeyword = apiResponse && containsAnyKeyword(apiResponse.value, keywords);
7175
if (responseContainsKeyword) {
7276
throw new Error('LLM already has knowledge of this guide!')
7377
}
@@ -146,12 +150,28 @@ test('002_test_sandbox_chatqna', async ({ page, baseURL }) => {
146150
await page2.waitForTimeout(10000);
147151

148152
// Chat Attempt 2
153+
console.log ('Chat Attempt 2-------------------');
149154
await page2.getByPlaceholder('Ask a question').fill(question);
150155
await page2.getByRole('button').nth(3).click();
151156
await page2.waitForTimeout(10000);
152-
responseContainsKeyword = apiResponse && apiResponse.value.includes(keyword.replace(/\s+/g, ''));
157+
responseContainsKeyword = apiResponse && containsAnyKeyword(apiResponse.value, keywords);
158+
console.log ('response:', apiResponse.value);
153159
if (!responseContainsKeyword) {
154-
throw new Error('RAG failed')
160+
console.log('First attempt failed. Asking a follow-up question...');
161+
apiResponse.value = ""; // Clear the response listener buffer
162+
163+
// Ask another question
164+
const followUpQuestion = "How is Intel performing in Q3 2024?";
165+
await page2.getByPlaceholder('Ask a question').fill(followUpQuestion);
166+
await page2.getByRole('button').nth(3).click();
167+
await page2.waitForTimeout(10000);
168+
169+
responseContainsKeyword = apiResponse && containsAnyKeyword(apiResponse.value, keywords);
170+
console.log ('response:', apiResponse.value);
171+
172+
if (!responseContainsKeyword) {
173+
throw new Error('RAG failed after follow-up question');
174+
}
155175
}
156176

157177
// Delete 1 document + Check data sources successfully deduct 1 or not

0 commit comments

Comments
 (0)