From db6fcc0423d6dae846a7165e4436a7c03bfbd7c0 Mon Sep 17 00:00:00 2001 From: Sandra G Date: Wed, 18 Dec 2024 13:23:32 -0500 Subject: [PATCH] [Obs AI Assistant] unskip and update summarize.spec.ts for serverless (#204790) Closes https://github.com/elastic/kibana/issues/192497 - Unskips summarize.spec.ts. It was originally skipped because tiny_elser was not available on CI. - Adds `this.tags(['skipMKI']` due to https://github.com/elastic/kibana/issues/192751 Related: https://github.com/elastic/kibana/pull/199134 --- .../complete/functions/summarize.spec.ts | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/ai_assistant/tests/complete/functions/summarize.spec.ts b/x-pack/test_serverless/api_integration/test_suites/observability/ai_assistant/tests/complete/functions/summarize.spec.ts index f949268aa730a..823dd15f46b64 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/ai_assistant/tests/complete/functions/summarize.spec.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/ai_assistant/tests/complete/functions/summarize.spec.ts @@ -11,6 +11,13 @@ import { LlmProxy, createLlmProxy, } from '@kbn/test-suites-xpack/observability_ai_assistant_api_integration/common/create_llm_proxy'; +import { + clearKnowledgeBase, + createKnowledgeBaseModel, + deleteInferenceEndpoint, + deleteKnowledgeBaseModel, + TINY_ELSER, +} from '@kbn/test-suites-xpack/observability_ai_assistant_api_integration/tests/knowledge_base/helpers'; import { FtrProviderContext } from '../../../common/ftr_provider_context'; import { invokeChatCompleteWithFunctionRequest } from './helpers'; import { @@ -22,12 +29,15 @@ import type { InternalRequestHeader, RoleCredentials } from '../../../../../../. export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const log = getService('log'); + const ml = getService('ml'); + const es = getService('es'); const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantAPIClient'); const svlUserManager = getService('svlUserManager'); const svlCommonApi = getService('svlCommonApi'); - // Skipped until Elser is available in tests - describe.skip('when calling summarize function', () => { + describe('when calling summarize function', function () { + // TODO: https://github.com/elastic/kibana/issues/192751 + this.tags(['skipMKI']); let roleAuthc: RoleCredentials; let internalReqHeader: InternalRequestHeader; let proxy: LlmProxy; @@ -36,6 +46,19 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('editor'); internalReqHeader = svlCommonApi.getInternalRequestHeader(); + + await createKnowledgeBaseModel(ml); + await observabilityAIAssistantAPIClient + .slsAdmin({ + endpoint: 'POST /internal/observability_ai_assistant/kb/setup', + params: { + query: { + model_id: TINY_ELSER.id, + }, + }, + }) + .expect(200); + proxy = await createLlmProxy(log); connectorId = await createProxyActionConnector({ supertest, @@ -57,10 +80,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { name: 'summarize', trigger: MessageRole.User, arguments: JSON.stringify({ - id: 'my-id', + title: 'My Title', text: 'Hello world', is_correction: false, - confidence: 1, + confidence: 'high', public: false, }), }, @@ -72,6 +95,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { after(async () => { proxy.close(); await deleteActionConnector({ supertest, connectorId, log, roleAuthc, internalReqHeader }); + await deleteKnowledgeBaseModel(ml); + await clearKnowledgeBase(es); + await deleteInferenceEndpoint({ es }); }); it('persists entry in knowledge base', async () => { @@ -80,12 +106,20 @@ export default function ApiTest({ getService }: FtrProviderContext) { params: { query: { query: '', - sortBy: 'doc_id', + sortBy: 'title', sortDirection: 'asc', }, }, }); + const { role, public: isPublic, text, type, user, title } = res.body.entries[0]; + + expect(role).to.eql('assistant_summarization'); + expect(isPublic).to.eql(false); + expect(text).to.eql('Hello world'); + expect(type).to.eql('contextual'); + expect(user?.name).to.eql('elastic_editor'); // "editor" in stateful + expect(title).to.eql('My Title'); expect(res.body.entries).to.have.length(1); }); });