Skip to content

Commit

Permalink
[Observability] Add feedback buttons for prompts (#160351)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Heelan <[email protected]>
  • Loading branch information
dgieselaar and Sean Heelan authored Jul 12, 2023
1 parent 0cd98f1 commit 4ae94c3
Show file tree
Hide file tree
Showing 29 changed files with 592 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.upgrade_assistant.featureSet.reindexCorrectiveActions (boolean)',
'xpack.upgrade_assistant.ui.enabled (boolean)',
'xpack.observability.aiAssistant.enabled (boolean)',
'xpack.observability.aiAssistant.feedback.enabled (boolean)',
'xpack.observability.unsafe.alertDetails.metrics.enabled (boolean)',
'xpack.observability.unsafe.alertDetails.logs.enabled (boolean)',
'xpack.observability.unsafe.alertDetails.uptime.enabled (boolean)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function ErrorSampleCoPilotPrompt({
)}
promptId={CoPilotPromptId.ApmExplainError}
params={promptParams}
feedbackEnabled={false}
/>
</EuiFlexItem>
<EuiSpacer size="s" />
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const APM_FEATURE = {
privileges: {
all: {
app: [APM_SERVER_FEATURE_ID, 'ux', 'kibana'],
api: [APM_SERVER_FEATURE_ID, 'apm_write', 'rac'],
api: [APM_SERVER_FEATURE_ID, 'apm_write', 'rac', 'ai_assistant'],
catalogue: [APM_SERVER_FEATURE_ID],
savedObject: {
all: [],
Expand All @@ -56,7 +56,7 @@ export const APM_FEATURE = {
},
read: {
app: [APM_SERVER_FEATURE_ID, 'ux', 'kibana'],
api: [APM_SERVER_FEATURE_ID, 'rac'],
api: [APM_SERVER_FEATURE_ID, 'rac', 'ai_assistant'],
catalogue: [APM_SERVER_FEATURE_ID],
savedObject: {
all: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export const ExplainLogRateSpikes: FC<AlertDetailsExplainLogRateSpikesSectionPro
title={explainLogSpikeTitle}
params={logSpikeParams}
promptId={CoPilotPromptId.ExplainLogSpike}
feedbackEnabled={false}
/>
</EuiFlexItem>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const CopilotProcessRow = ({ command }: { command: string }) => {
title={explainProcessMessageTitle}
params={explainProcessParams}
promptId={CoPilotPromptId.InfraExplainProcess}
feedbackEnabled={true}
/>
</EuiFlexItem>
</EuiFlexItem>
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/infra/server/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const METRICS_FEATURE = {
all: {
app: ['infra', 'metrics', 'kibana'],
catalogue: ['infraops', 'metrics'],
api: ['infra', 'rac'],
api: ['infra', 'rac', 'ai_assistant'],
savedObject: {
all: ['infrastructure-ui-source'],
read: ['index-pattern'],
Expand All @@ -54,7 +54,7 @@ export const METRICS_FEATURE = {
read: {
app: ['infra', 'metrics', 'kibana'],
catalogue: ['infraops', 'metrics'],
api: ['infra', 'rac'],
api: ['infra', 'rac', 'ai_assistant'],
savedObject: {
all: [],
read: ['infrastructure-ui-source', 'index-pattern'],
Expand Down Expand Up @@ -92,7 +92,7 @@ export const LOGS_FEATURE = {
all: {
app: ['infra', 'logs', 'kibana'],
catalogue: ['infralogging', 'logs'],
api: ['infra', 'rac'],
api: ['infra', 'rac', 'ai_assistant'],
savedObject: {
all: [infraSourceConfigurationSavedObjectName, logViewSavedObjectName],
read: [],
Expand All @@ -113,7 +113,7 @@ export const LOGS_FEATURE = {
read: {
app: ['infra', 'logs', 'kibana'],
catalogue: ['infralogging', 'logs'],
api: ['infra', 'rac'],
api: ['infra', 'rac', 'ai_assistant'],
alerting: {
rule: {
read: [LOG_DOCUMENT_COUNT_RULE_TYPE_ID],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const LogEntryFlyout = ({
title={explainLogMessageTitle}
params={explainLogMessageParams}
promptId={CoPilotPromptId.LogsExplainMessage}
feedbackEnabled={false}
/>
</EuiFlexItem>
) : null}
Expand All @@ -214,6 +215,7 @@ export const LogEntryFlyout = ({
title={similarLogMessagesTitle}
params={similarLogMessageParams}
promptId={CoPilotPromptId.LogsFindSimilar}
feedbackEnabled={false}
/>
</EuiFlexItem>
) : null}
Expand Down
28 changes: 28 additions & 0 deletions x-pack/plugins/observability/common/co_pilot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export enum OpenAIProvider {
OpenAI = 'openAI',
AzureOpenAI = 'azureOpenAI',
}

export enum CoPilotPromptId {
ProfilingOptimizeFunction = 'profilingOptimizeFunction',
ApmExplainError = 'apmExplainError',
LogsExplainMessage = 'logsExplainMessage',
LogsFindSimilar = 'logsFindSimilar',
InfraExplainProcess = 'infraExplainProcess',
ExplainLogSpike = 'explainLogSpike',
}

export type {
CoPilotPromptMap,
CreateChatCompletionResponseChunk,
PromptParamsOf,
} from './prompts';

export const loadCoPilotPrompts = () => import('./prompts').then((m) => m.coPilotPrompts);
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,12 @@
* 2.0.
*/
import * as t from 'io-ts';
import {
type ChatCompletionRequestMessage,
type CreateChatCompletionResponse,
type CreateChatCompletionResponseChoicesInner,
import type {
ChatCompletionRequestMessage,
CreateChatCompletionResponse,
CreateChatCompletionResponseChoicesInner,
} from 'openai';

export enum OpenAIProvider {
OpenAI = 'openAI',
AzureOpenAI = 'azureOpenAI',
}

export enum CoPilotPromptId {
ProfilingExplainFunction = 'profilingExplainFunction',
ProfilingOptimizeFunction = 'profilingOptimizeFunction',
ApmExplainError = 'apmExplainError',
LogsExplainMessage = 'logsExplainMessage',
LogsFindSimilar = 'logsFindSimilar',
InfraExplainProcess = 'infraExplainProcess',
ExplainLogSpike = 'explainLogSpike',
}
import { CoPilotPromptId } from '.';

const PERF_GPT_SYSTEM_MESSAGE = {
content: `You are perf-gpt, a helpful assistant for performance analysis and optimisation
Expand Down Expand Up @@ -83,49 +69,6 @@ const significantFieldValuesRt = t.array(

export const coPilotPrompts = {
[CoPilotPromptId.ProfilingOptimizeFunction]: prompt({
params: t.type({
library: t.string,
functionName: t.string,
}),
messages: ({ library, functionName }) => {
return [
PERF_GPT_SYSTEM_MESSAGE,
{
content: `Assuming the function ${functionName} from the library ${library} is consuming significant CPU resources.
Suggest ways to optimize or improve the system that involve the ${functionName} function from the
${library} library. Types of improvements that would be useful to me are improvements that result in:
- Higher performance so that the system runs faster or uses less CPU
- Better memory efficient so that the system uses less RAM
- Better storage efficient so that the system stores less data on disk.
- Better network I/O efficiency so that less data is sent over the network
- Better disk I/O efficiency so that less data is read and written from disk
Make up to five suggestions. Your suggestions must meet all of the following criteria:
1. Your suggestions should be detailed, technical and include concrete examples.
2. Your suggestions should be specific to improving performance of a system in which the ${functionName} function from
the ${library} library is consuming significant CPU.
2. If you suggest replacing the function or library with a more efficient replacement you must suggest at least
one concrete replacement.
If you know of fewer than five ways to improve the performance of a system in which the ${functionName} function from the
${library} library is consuming significant CPU, then provide fewer than five suggestions. If you do not know of any
way in which to improve the performance then say "I do not know how to improve the performance of systems where
this function is consuming a significant amount of CPU".
If you have suggestions, the output format should look as follows:
Here are some suggestions as to how you might optimize your system if ${functionName} in ${library} is consuming
significant CPU resources:
1. Insert first suggestion
2. Insert second suggestion
etc.`,
role: 'user',
},
];
},
}),
[CoPilotPromptId.ProfilingExplainFunction]: prompt({
params: t.type({
library: t.string,
functionName: t.string,
Expand All @@ -135,18 +78,52 @@ export const coPilotPrompts = {
PERF_GPT_SYSTEM_MESSAGE,
{
content: `I am a software engineer. I am trying to understand what a function in a particular
software library does.
The library is: ${library}
The function is: ${functionName}
Your task is to describe what the library is and what its use cases are, and to describe what the function
does. The output format should look as follows:
Library description: Provide a concise description of the library
Library use-cases: Provide a concise description of what the library is typically used for.
Function description: Provide a concise, technical, description of what the function does.
`,
software library does.
The library is: ${library}
The function is: ${functionName}
Your have two tasks. Your first task is to desribe what the library is and what its use cases are, and to
describe what the function does. The output format should look as follows:
Library description: Provide a concise description of the library
Library use-cases: Provide a concise description of what the library is typically used for.
Function description: Provide a concise, technical, description of what the function does.
Assume the function ${functionName} from the library ${library} is consuming significant CPU resources.
Your second task is to suggest ways to optimize or improve the system that involve the ${functionName} function from the
${library} library. Types of improvements that would be useful to me are improvements that result in:
- Higher performance so that the system runs faster or uses less CPU
- Better memory efficient so that the system uses less RAM
- Better storage efficient so that the system stores less data on disk.
- Better network I/O efficiency so that less data is sent over the network
- Better disk I/O efficiency so that less data is read and written from disk
Make up to five suggestions. Your suggestions must meet all of the following criteria:
1. Your suggestions should detailed, technical and include concrete examples.
2. Your suggestions should be specific to improving performance of a system in which the ${functionName} function from
the ${library} library is consuming significant CPU.
3. If you suggest replacing the function or library with a more efficient replacement you must suggest at least
one concrete replacement.
If you know of fewer than five ways to improve the performance of a system in which the ${functionName} function from the
${library} library is consuming significant CPU, then provide fewer than five suggestions. If you do not know of any
way in which to improve the performance then say "I do not know how to improve the performance of systems where
this function is consuming a significant amount of CPU".
Do not suggest using a CPU profiler. I have already profiled my code. The profiler I used is Elastic Universal Profiler.
If there is specific information I should look for in the profiler output then tell me what information to look for
in the output of Elastic Universal Profiler.
You must not include URLs, web addresses or websites of any kind in your output.
If you have suggestions, the output format should look as follows:
Here are some suggestions as to how you might optimize your system if ${functionName} in ${library} is consuming
significant CPU resources:
1. Insert first suggestion
2. Insert second suggestion`,
role: 'user',
},
];
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/observability/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ export {
SYNTHETICS_WAIT_TIMINGS,
} from './field_names/synthetics';

export { CoPilotPromptId, coPilotPrompts } from './co_pilot';
export { CoPilotPromptId, loadCoPilotPrompts } from './co_pilot';
Loading

0 comments on commit 4ae94c3

Please sign in to comment.