Skip to content

Commit

Permalink
remove legacy prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Nov 21, 2024
1 parent 59e080a commit 50ab424
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { KibanaRequest } from '@kbn/core-http-server';
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import type { MlPluginSetup } from '@kbn/ml-plugin/server';
import { DeleteByQueryRequest } from '@elastic/elasticsearch/lib/api/types';
import { getResourceName } from '.';
import { knowledgeBaseIngestPipeline } from '../ai_assistant_data_clients/knowledge_base/ingest_pipeline';
import { GetElser } from '../types';

Expand Down Expand Up @@ -96,3 +98,31 @@ export const deletePipeline = async ({ esClient, id }: DeletePipelineParams): Pr

return response.acknowledged;
};

export const removeLegacyQuickPrompt = async (esClient: ElasticsearchClient) => {
const deleteQuery: DeleteByQueryRequest = {
index: `${getResourceName('prompts')}-*`,
query: {
bool: {
must: [
{
term: {
name: 'ES|QL Query Generation',
},
},
{
term: {
prompt_type: 'quick',
},
},
{
term: {
is_default: true,
},
},
],
},
},
};
return esClient.deleteByQuery(deleteQuery);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { hasAIAssistantLicense } from '../routes/helpers';

const TOTAL_FIELDS_LIMIT = 2500;

function getResourceName(resource: string) {
export function getResourceName(resource: string) {
return `.kibana-elastic-ai-assistant-${resource}`;
}

Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/elastic_assistant/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { RequestContextFactory } from './routes/request_context_factory';
import { PLUGIN_ID } from '../common/constants';
import { registerRoutes } from './routes/register_routes';
import { appContextService } from './services/app_context';
import { createGetElserId } from './ai_assistant_service/helpers';
import { createGetElserId, removeLegacyQuickPrompt } from './ai_assistant_service/helpers';

export class ElasticAssistantPlugin
implements
Expand Down Expand Up @@ -109,6 +109,10 @@ export class ElasticAssistantPlugin
this.getElserId = createGetElserId(this.mlTrainedModelsProvider);
}
});
removeLegacyQuickPrompt(core.elasticsearch.client.asInternalUser).then((res) => {
if (res?.total)
this.logger.info(`Removed ${res.total} legacy quick prompts from AI Assistant`);
});

return {
actions: plugins.actions,
Expand Down

0 comments on commit 50ab424

Please sign in to comment.