-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update example to have running trace based test
- Loading branch information
1 parent
f364a18
commit 68ba846
Showing
30 changed files
with
749 additions
and
73 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @ts-check | ||
const { test, expect } = require('@playwright/test'); | ||
|
||
const geminiTraceBasedTest = require('./definitions/gemini'); | ||
const chatgptTraceBasedTest = require('./definitions/chatgpt'); | ||
|
||
const { runTracebasedTest } = require('./tracetest'); | ||
|
||
test('generated summarized test for Gemini', async ({ request }) => { | ||
const result = await request.post(`http://localhost:8800/summarizeText`, { | ||
data: { | ||
provider: "Google (Gemini)", | ||
text: "Born in London, Turing was raised in southern England. He graduated from King's College, Cambridge, and in 1938, earned a doctorate degree from Princeton University. During World War II, Turing worked for the Government Code and Cypher School at Bletchley Park, Britain's codebreaking centre that produced Ultra intelligence. He led Hut 8, the section responsible for German naval cryptanalysis. Turing devised techniques for speeding the breaking of German ciphers, including improvements to the pre-war Polish bomba method, an electromechanical machine that could find settings for the Enigma machine. He played a crucial role in cracking intercepted messages that enabled the Allies to defeat the Axis powers in many crucial engagements, including the Battle of the Atlantic.\n\nAfter the war, Turing worked at the National Physical Laboratory, where he designed the Automatic Computing Engine, one of the first designs for a stored-program computer. In 1948, Turing joined Max Newman's Computing Machine Laboratory at the Victoria University of Manchester, where he helped develop the Manchester computers[12] and became interested in mathematical biology. Turing wrote on the chemical basis of morphogenesis and predicted oscillating chemical reactions such as the Belousov–Zhabotinsky reaction, first observed in the 1960s. Despite these accomplishments, he was never fully recognised during his lifetime because much of his work was covered by the Official Secrets Act." | ||
} | ||
}); | ||
|
||
const jsonResult = await result.json(); | ||
expect(jsonResult).not.toBe(null); | ||
expect(jsonResult.summary).not.toBe(null); | ||
|
||
const traceID = jsonResult.trace_id; | ||
expect(traceID).not.toBe(null); | ||
|
||
// run trace-based test | ||
await runTracebasedTest(geminiTraceBasedTest, traceID); | ||
}); | ||
|
||
test('generated summarized test for OpenAI', async ({ request }) => { | ||
const result = await request.post(`http://localhost:8800/summarizeText`, { | ||
data: { | ||
provider: "OpenAI (ChatGPT)", | ||
text: "Born in London, Turing was raised in southern England. He graduated from King's College, Cambridge, and in 1938, earned a doctorate degree from Princeton University. During World War II, Turing worked for the Government Code and Cypher School at Bletchley Park, Britain's codebreaking centre that produced Ultra intelligence. He led Hut 8, the section responsible for German naval cryptanalysis. Turing devised techniques for speeding the breaking of German ciphers, including improvements to the pre-war Polish bomba method, an electromechanical machine that could find settings for the Enigma machine. He played a crucial role in cracking intercepted messages that enabled the Allies to defeat the Axis powers in many crucial engagements, including the Battle of the Atlantic.\n\nAfter the war, Turing worked at the National Physical Laboratory, where he designed the Automatic Computing Engine, one of the first designs for a stored-program computer. In 1948, Turing joined Max Newman's Computing Machine Laboratory at the Victoria University of Manchester, where he helped develop the Manchester computers[12] and became interested in mathematical biology. Turing wrote on the chemical basis of morphogenesis and predicted oscillating chemical reactions such as the Belousov–Zhabotinsky reaction, first observed in the 1960s. Despite these accomplishments, he was never fully recognised during his lifetime because much of his work was covered by the Official Secrets Act." | ||
} | ||
}); | ||
|
||
const jsonResult = await result.json(); | ||
expect(jsonResult).not.toBe(null); | ||
expect(jsonResult.summary).not.toBe(null); | ||
|
||
const traceID = jsonResult.trace_id; | ||
expect(traceID).not.toBe(null); | ||
|
||
// run trace-based test | ||
await runTracebasedTest(chatgptTraceBasedTest, traceID); | ||
}); |
32 changes: 32 additions & 0 deletions
32
examples/quick-start-llm-python/tests/e2e/definitions/chatgpt.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const definition = { | ||
"type": "Test", | ||
"spec": { | ||
"id": "B9opfNRNR", | ||
"name": "Get GPT4 trace", | ||
"trigger": { | ||
"type": "traceid", | ||
"traceid": { | ||
"id": "${var:TRACE_ID}" | ||
} | ||
}, | ||
"specs": [ | ||
{ | ||
"selector": "span[tracetest.span.type=\"general\" name=\"ChatPromptTemplate.workflow\"]", | ||
"name": "It performed a Chat workflow", | ||
"assertions": [ | ||
"attr:tracetest.span.name = \"ChatPromptTemplate.workflow\"" | ||
] | ||
}, | ||
{ | ||
"selector": "span[tracetest.span.type=\"general\" name=\"openai.chat\"]", | ||
"name": "It called OpenAI API", | ||
"assertions": [ | ||
"attr:name = \"openai.chat\"" | ||
] | ||
} | ||
], | ||
"pollingProfile": "predefined-default" | ||
} | ||
}; | ||
|
||
module.exports = definition; |
32 changes: 32 additions & 0 deletions
32
examples/quick-start-llm-python/tests/e2e/definitions/gemini.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const definition = { | ||
"type": "Test", | ||
"spec": { | ||
"id": "VS0U-HgHg", | ||
"name": "Get Gemini trace", | ||
"trigger": { | ||
"type": "traceid", | ||
"traceid": { | ||
"id": "${var:TRACE_ID}" | ||
} | ||
}, | ||
"specs": [ | ||
{ | ||
"selector": "span[tracetest.span.type=\"general\" name=\"MapReduceDocumentsChain.workflow\"]", | ||
"name": "It triggered a Summarization workflow", | ||
"assertions": [ | ||
"attr:traceloop.workflow.name = \"MapReduceDocumentsChain\"" | ||
] | ||
}, | ||
{ | ||
"selector": "span[tracetest.span.type=\"general\" name=\"ChatGoogleGenerativeAI.chat\"]", | ||
"name": "It called Gemini API at least once", | ||
"assertions": [ | ||
"attr:tracetest.selected_spans.count >= 1" | ||
] | ||
} | ||
], | ||
"pollingProfile": "predefined-default" | ||
} | ||
}; | ||
|
||
module.exports = definition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Tracetest = require('@tracetest/client').default; | ||
|
||
const { TRACETEST_API_TOKEN = '' } = process.env; | ||
|
||
async function runTracebasedTest(testDefinition, traceID) { | ||
const tracetestClient = await Tracetest({ apiToken: TRACETEST_API_TOKEN }); | ||
|
||
const test = await tracetestClient.newTest(testDefinition); | ||
await tracetestClient.runTest(test, { variables: [ { key: 'TRACE_ID', value: traceID }] }); | ||
console.log(await tracetestClient.getSummary()); | ||
} | ||
|
||
module.exports = { runTracebasedTest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// @ts-check | ||
const { test, expect } = require('@playwright/test'); | ||
|
||
const geminiTraceBasedTest = require('./definitions/gemini'); | ||
const chatgptTraceBasedTest = require('./definitions/chatgpt'); | ||
|
||
const { runTracebasedTest } = require('./tracetest'); | ||
|
||
const timeToWait = 10_000; // 10 seconds | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
test('generated summarized test for Gemini', async ({ page }) => { | ||
// Go to Streamlit app | ||
await page.goto('http://localhost:8501/'); | ||
|
||
// Select Google (Gemini) model | ||
await page.getByTestId('stSelectbox').locator('div').filter({ hasText: 'Google (Gemini)' }).nth(2).click(); | ||
|
||
// Click on add example text | ||
await page.getByRole('button', { name: 'Add example text' }).click(); | ||
|
||
// Click on button to call summarization rule | ||
await page.getByRole('button', { name: 'Summarize' }).click(); | ||
|
||
// Wait for time | ||
await sleep(timeToWait); | ||
|
||
// Capture TraceID | ||
const traceIDLabel = await page.getByRole('link', { name: 'Trace ID' }); | ||
expect(traceIDLabel).toHaveText('Trace ID'); | ||
|
||
console.log(traceIDLabel); | ||
|
||
// const traceID = (traceIDLabel || '').replace('Trace ID:', '').trim(); | ||
|
||
// // run trace-based test | ||
// await runTracebasedTest(geminiTraceBasedTest, traceID); | ||
}); | ||
|
||
// test('generated summarized test for OpenAPI', async ({ page }) => { | ||
// // Go to Streamlit app | ||
// await page.goto('http://localhost:8501/'); | ||
|
||
// // Select OpenAI (ChatGPT) model | ||
// await page.getByTestId('stSelectbox').locator('div').filter({ hasText: 'OpenAI (ChatGPT)' }).nth(2).click(); | ||
|
||
// // Click on add example text | ||
// await page.getByRole('button', { name: 'Add example text' }).click(); | ||
|
||
// // Click on button to call summarization rule | ||
// await page.getByRole('button', { name: 'Summarize' }).click(); | ||
|
||
// // Wait for time | ||
// await sleep(timeToWait); | ||
|
||
// // Capture TraceID | ||
// const traceIDElement = await page.getByText('Trace ID:'); | ||
// expect(traceIDElement).toHaveText('Trace ID:'); | ||
|
||
// const traceIDLabel = await page.getByText('Trace ID:').innerText(); | ||
// expect(traceIDLabel).not.toBeNull(); | ||
|
||
// const traceID = (traceIDLabel || '').replace('Trace ID:', '').trim(); | ||
|
||
// // run trace-based test | ||
// await runTracebasedTest(chatgptTraceBasedTest, traceID); | ||
// }); |
Oops, something went wrong.