fix: Update templates and include global variables (#3755)

* update templates

* update to include global variables

* Refactor code to include global variables

* update PythonREPLTool.py

* [autofix.ci] apply automated fixes

* update pythonREPL and example

* Refactor code to handle decoding chat messages and handle decoding errors

* ✨ (Simple Agent.spec.ts): Add test case to fill textarea with specific text for testing purposes
📝 (Simple Agent.spec.ts): Update test case descriptions for better clarity and accuracy
✅ (Simple Agent.spec.ts): Update test assertions to match the expected behavior of the test case

* [autofix.ci] apply automated fixes

* 🐛 (Dynamic Agent.spec.ts): fix environment variable name from BRAVE_SEARCH_API_KEY to SEARCH_API_KEY for consistency and clarity
💡 (Dynamic Agent.spec.ts): add additional test cases to improve test coverage and ensure specific text is not present in the chat output

* 🔧 (.github/workflows/typescript_test.yml): update environment variable name from BRAVE_SEARCH_API_KEY to SEARCH_API_KEY for consistency
🐛 (Travel Planning Agent.spec.ts): fix test to skip if SEARCH_API_KEY is not available in the environment variables

* ✅ (Simple Agent.spec.ts): update expected count of python words to 3 for accurate test validation

* updating search tools

* [autofix.ci] apply automated fixes

* change examples

* update travel planning to include global variable

* Refactor search API component to include result limiting

* 📝 (Travel Planning Agent.spec.ts): remove unnecessary empty line to improve code readability and consistency

* test: adjusts asserts to make the test pass successfully

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: cristhianzl <cristhian.lousa@gmail.com>
Co-authored-by: italojohnny <italojohnnydosanjos@gmail.com>
This commit is contained in:
anovazzi1 2024-09-11 11:47:42 -03:00 • committed by GitHub
commit 810cf72487
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 953 additions and 823 deletions

View file

@ -126,7 +126,12 @@ export default function ChatMessage({
}
}, [lastMessage]);
const decodedMessage = decodeURIComponent(chatMessage ?? "");
let decodedMessage = chatMessage ?? "";
try {
decodedMessage = decodeURIComponent(chatMessage);
} catch (e) {
console.error(e);
}
const isEmpty = decodedMessage?.trim() === "";
return (

View file

@ -9,8 +9,8 @@ test("Dynamic Agent", async ({ page }) => {
);
test.skip(
!process?.env?.BRAVE_SEARCH_API_KEY,
"BRAVE_SEARCH_API_KEY required to run this test",
!process?.env?.SEARCH_API_KEY,
"SEARCH_API_KEY required to run this test",
);
if (!process.env.CI) {
@ -64,7 +64,7 @@ test("Dynamic Agent", async ({ page }) => {
await page
.getByTestId("popover-anchor-input-api_key")
.last()
.fill(process.env.BRAVE_SEARCH_API_KEY ?? "");
.fill(process.env.SEARCH_API_KEY ?? "");
await page.waitForTimeout(1000);
@ -82,6 +82,11 @@ test("Dynamic Agent", async ({ page }) => {
await page.waitForTimeout(1000);
}
await page
.getByTestId("textarea_str_input_value")
.first()
.fill("how much is an apple stock today");
await page.getByTestId("button_run_chat output").click();
await page.waitForSelector("text=built successfully", { timeout: 60000 * 3 });
@ -93,9 +98,7 @@ test("Dynamic Agent", async ({ page }) => {
await page.waitForTimeout(1000);
expect(
page.getByText("Could you search info about AAPL?", { exact: true }).last(),
).toBeVisible();
expect(page.getByText("apple").last()).toBeVisible();
const textContents = await page
.getByTestId("div-chat-message")
@ -103,6 +106,9 @@ test("Dynamic Agent", async ({ page }) => {
const concatAllText = textContents.join(" ");
expect(concatAllText.toLocaleLowerCase()).toContain("apple");
expect(concatAllText.toLocaleLowerCase()).not.toContain("error");
expect(concatAllText.toLocaleLowerCase()).not.toContain("apologize");
expect(concatAllText.toLocaleLowerCase()).not.toContain("unable");
const allTextLength = concatAllText.length;
expect(allTextLength).toBeGreaterThan(100);
});

View file

@ -65,6 +65,12 @@ test("Simple Agent", async ({ page }) => {
await page.waitForTimeout(1000);
await page
.getByTestId("textarea_str_input_value")
.fill(
"Use the Python REPL tool to create a python function that calculates 4 + 4 and stores it in a variable.",
);
await page.getByTestId("button_run_chat output").click();
await page.waitForSelector("text=built successfully", { timeout: 30000 });
@ -75,7 +81,7 @@ test("Simple Agent", async ({ page }) => {
await page.getByText("Playground", { exact: true }).click();
await page.waitForSelector(
"text=write short python scsript to say hello world",
"text=Use the Python REPL tool to create a python function that calculates 4 + 4 and stores it in a variable.",
{
timeout: 30000,
},
@ -83,19 +89,41 @@ test("Simple Agent", async ({ page }) => {
await page.waitForTimeout(1000);
expect(await page.getByText("User")).toBeVisible();
expect(page.getByText("User")).toBeVisible();
expect(await page.locator(".language-python")).toBeVisible();
expect(page.locator(".language-python")).toBeVisible();
let pythonWords = await page.getByText("Hello, World!").count();
let pythonWords = await page.getByText("4 + 4").count();
expect(pythonWords).toBe(2);
expect(pythonWords).toBe(3);
await page
.getByPlaceholder("Send a message...")
.fill("write short python scsript to say hello world");
await page.getByTestId("icon-LucideSend").last().click();
await page.waitForSelector(
"text=write short python scsript to say hello world",
{
timeout: 30000,
},
);
await page.waitForSelector('[data-testid="icon-Copy"]', {
timeout: 100000,
});
await page.waitForTimeout(1000);
await page.getByTestId("icon-Copy").last().click();
await page.waitForTimeout(500);
await page.getByPlaceholder("Send a message...").click();
await page.waitForTimeout(500);
await page.keyboard.press("Control+V");
await page.waitForTimeout(500);

View file

@ -8,6 +8,11 @@ test("Travel Planning Agent", async ({ page }) => {
"OPENAI_API_KEY required to run this test",
);
test.skip(
!process?.env?.SEARCH_API_KEY,
"SEARCH_API_KEY required to run this test",
);
if (!process.env.CI) {
dotenv.config({ path: path.resolve(__dirname, "../../.env") });
}
@ -56,65 +61,10 @@ test("Travel Planning Agent", async ({ page }) => {
outdatedComponents = await page.getByTestId("icon-AlertTriangle").count();
}
await page.getByTestId("extended-disclosure").click();
await page.getByPlaceholder("Search").click();
await page.getByPlaceholder("Search").fill("yahoo finance");
await page.waitForTimeout(1000);
await page.getByText("SearchAPI").last().click();
await page.waitForTimeout(1000);
await page.keyboard.press("Backspace");
await page.getByTitle("zoom out").click();
await page.getByTitle("zoom out").click();
await page
.locator('//*[@id="react-flow-id"]')
.hover()
.then(async () => {
await page.mouse.down();
await page.mouse.move(-100, 100);
});
await page.mouse.up();
await page
.getByTestId("toolsYahoo Finance News Tool")
.dragTo(page.locator('//*[@id="react-flow-id"]'));
await page.getByTitle("fit view").click();
await page.getByTitle("zoom out").click();
await page.getByTitle("zoom out").click();
//connection 1
const yahooElementOutput = await page
.getByTestId("handle-yfinancetool-shownode-tool-right")
.nth(0);
await yahooElementOutput.hover();
await page.mouse.down();
const agentOne = await page
.getByTestId("handle-toolcallingagent-shownode-tools-left")
.nth(0);
await agentOne.hover();
await page.mouse.up();
//connection 2
await yahooElementOutput.hover();
await page.mouse.down();
const agentTwo = await page
.getByTestId("handle-toolcallingagent-shownode-tools-left")
.nth(1);
await agentTwo.hover();
await page.mouse.up();
//connection 3
await yahooElementOutput.hover();
await page.mouse.down();
const agentThree = await page
.getByTestId("handle-toolcallingagent-shownode-tools-left")
.nth(2);
await agentThree.hover();
await page.mouse.up();
.getByTestId("popover-anchor-input-api_key")
.last()
.fill(process.env.SEARCH_API_KEY ?? "");
await page
.getByTestId("popover-anchor-input-api_key")
@ -132,7 +82,6 @@ test("Travel Planning Agent", async ({ page }) => {
await page.getByText("built successfully").last().click({
timeout: 15000,
});
await page.getByText("Playground", { exact: true }).click();
await page.waitForSelector("text=default session", {