Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functional test for dashboard assistant trace page #1012

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"completion": " ```json\n{\n \"thought\": \"Thought: Let me use tool to figure out\",\n \"action\": \"CatIndexTool\",\n \"action_input\": \"\"}\n```\n",
"stop_reason": "stop_sequence",
"stop": "\n\nHuman:"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

describe('Interact with Agent framework', () => {
it('toggle Chatbot and enable to interact', () => {
// enable to toggle and show Chatbot
cy.get(`img[aria-label="toggle chat flyout icon"]`).click();

// click suggestions to generate response
cy.contains('What are the indices in my cluster?').click();
// input question
cy.wait(1000);
cy.get(`input[placeholder="Ask question"]`)
.click()
.type('What are the indices in my cluster?{enter}');

// should have a LLM Response
cy.contains(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { BASE_PATH } from '../../../utils/constants';

if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
describe('Interaction trace spec', () => {
before(() => {
// Set welcome screen tracking to false
localStorage.setItem('home:welcome:show', 'false');
// Set new theme modal to false
localStorage.setItem('home:newThemeModal:show', 'false');
wanglam marked this conversation as resolved.
Show resolved Hide resolved

cy.visit(`${BASE_PATH}/app/home`);
// cy.waitForLoader();

// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
wanglam marked this conversation as resolved.
Show resolved Hide resolved
cy.get(`input[placeholder="Ask question"]`, { timeout: 120000 }).as(
'chatInput'
);
cy.get('@chatInput').should('be.length', 1);

cy.wait(1000);

cy.get('@chatInput')
.click()
.type('What are the indices in my cluster?{enter}');

// should have a LLM Response
cy.contains(
'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.'
);
});

describe('Trace page', () => {
it('open trace page and verify page content', () => {
// click How was this generated? to view trace
cy.contains('How was this generated?').click();

cy.get(`.llm-chat-flyout .llm-chat-flyout-body`).as('tracePage');
cy.get('@tracePage')
.find(`button[aria-label="back"]`)
.should('have.length', 1);

cy.get('@tracePage')
.find(`button[aria-label="close"]`)
.should('have.length', 0);

// title
cy.get('@tracePage').contains('h1', 'How was this generated');

// question
cy.get('@tracePage').contains('What are the indices in my cluster?');

// result
cy.get('@tracePage').contains(
'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.'
);
});

it('tools invocation displayed in trace steps', () => {
// trace
cy.get(`.llm-chat-flyout .llm-chat-flyout-body`).as('tracePage');
cy.get('@tracePage').find('.euiAccordion').should('have.length', 1);

cy.get('@tracePage')
.find('.euiAccordion')
// tool name
.contains('Step 1 - CatIndexTool')
.click({ force: true });

// tool output
cy.contains('Output: health status index');
});

it('trace page display correctly in fullscreen mode', () => {
cy.get(`.llm-chat-flyout-header`)
.find(`button[aria-label="fullScreen"]`)
.click({ force: true });

// show close button
cy.get(`.llm-chat-flyout .llm-chat-flyout-body`).as('tracePage');
cy.get('@tracePage')
.find(`button[aria-label="close"]`)
.should('have.length', 1);

cy.get('@tracePage')
.find(`button[aria-label="back"]`)
.should('have.length', 0);

// both chat and trace are both displayed
cy.contains('How was this generated?').click();
});
});
});
}
8 changes: 7 additions & 1 deletion cypress/support/assistant-dummy-llm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
*/
const http = require('http');
const agentFrameworkJson = require('../fixtures/plugins/dashboards-assistant/agent-framework-response.json');
const agentFrameworkThoughtJson = require('../fixtures/plugins/dashboards-assistant/agent-framework-thought-response.json');
const suggestionJson = require('../fixtures/plugins/dashboards-assistant/suggestion-response.json');

const MATCH_AGENT_FRAMEWORK_PROMPT =
'Assistant is designed to be able to assist with a wide range of tasks';
const MATCH_SUGGESTION_PROMPT = 'You are an AI that only speaks JSON';
const TOOL_RESPONSE = 'TOOL RESPONSE:';

const server = http.createServer((req, res) => {
// Set the content type to JSON
Expand All @@ -27,7 +29,11 @@ const server = http.createServer((req, res) => {
// Why add a delay here? reference: https://github.com/opensearch-project/ml-commons/issues/1894
setTimeout(() => {
if (requestBody.includes(MATCH_AGENT_FRAMEWORK_PROMPT)) {
return res.end(JSON.stringify(agentFrameworkJson));
if (requestBody.includes(TOOL_RESPONSE)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TOOL RESPONSE request from the ml-commons side? Since we are adding a specific response for agentFrameworkThoughtJson, could we just add a condition just like below. Preferring add else if(requestBody.includes(MATCH_THOUGHT_PROMPT))) {.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, TOOL RESPONSE comes from ml-common side and it's part of prompt when we have tool involved.

The first LLM call prompt is MATCH_AGENT_FRAMEWORK_PROMPT...., when some tool been involved, prompt becomes MATCH_AGENT_FRAMEWORK_PROMPT.... TOOL_RESPONSE:...., i am not quite follow your comments here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your point, Let's keep current implementation

return res.end(JSON.stringify(agentFrameworkJson));
} else {
return res.end(JSON.stringify(agentFrameworkThoughtJson));
}
} else if (requestBody.includes(MATCH_SUGGESTION_PROMPT)) {
return res.end(JSON.stringify(suggestionJson));
}
Expand Down
Loading