Skip to content

Commit

Permalink
Merge branch 'main' into oas/generate-serverless-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jun 7, 2024
2 parents 0d55e13 + 21d9035 commit 698dc93
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ The \`SHOW <item>\` source command returns information about the deployment and
* Use \`SHOW INFO\` to return the deployment's version, build date and hash.
* Use \`SHOW FUNCTIONS\` to return a list of all supported functions and a synopsis of each function.
`,
ignoreTag: true,
description:
'Text is in markdown. Do not translate function names, special characters, or field names like sum(bytes)',
}
Expand Down Expand Up @@ -214,9 +215,9 @@ Refer to the [dissect processor documentation](https://www.elastic.co/guide/en/e
\`\`\`
ROW a = "1953-01-23T12:15:00Z - some text - 127.0.0.1"
| DISSECT a "%\\{Y\\}-%\\{M\\}-%\\{D\\}T%\\{h\\}:%\\{m\\}:%\\{s\\}Z - %\\{msg\\} - %\\{ip\\}"
\`\`\`
`,
| DISSECT a "%'\{Y\}-%\{M\}-%\{D\}T%\{h\}:%\{m\}:%\{s\}Z - %\{msg\} - %\{ip\}'"
\`\`\` `,
ignoreTag: true,
description:
'Text is in markdown. Do not translate function names, special characters, or field names like sum(bytes)',
}
Expand Down Expand Up @@ -308,6 +309,7 @@ By default (if no \`WITH\` is defined), \`ENRICH\` will add all the enrich field
In case of name collisions, the newly created fields will override the existing fields.
`,
ignoreTag: true,
description:
'Text is in markdown. Do not translate function names, special characters, or field names like sum(bytes)',
}
Expand Down Expand Up @@ -376,7 +378,7 @@ Refer to the [grok processor documentation](https://www.elastic.co/guide/en/elas
\`\`\`
ROW a = "12 15.5 15.6 true"
| GROK a "%\\{NUMBER:b:int\\} %\\{NUMBER:c:float\\} %\\{NUMBER:d:double\\} %\\{WORD:e:boolean\\}"
| GROK a "%'{NUMBER:b:int}' %'{NUMBER:c:float}' %'{NUMBER:d:double}' %'{WORD:e:boolean}'"
\`\`\`
`,
description:
Expand Down Expand Up @@ -523,6 +525,7 @@ FROM employees
| RENAME first_name AS fn, last_name AS ln
\`\`\`
`,
ignoreTag: true,
description:
'Text is in markdown. Do not translate function names, special characters, or field names like sum(bytes)',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ export const LogEntryFlyout = ({
);
};

// eslint-disable-next-line import/no-default-export
export default LogEntryFlyout;

const loadingProgressMessage = i18n.translate('xpack.logsShared.logFlyout.loadingMessage', {
defaultMessage: 'Searching log entry in shards',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ export const WithSummary = ({ serializedParsedQuery, children }: WithSummaryProp

return children({ buckets, start, end });
};

// eslint-disable-next-line import/no-default-export
export default WithSummary;
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export {
useLogHighlightsStateContext,
} from './containers/logs/log_highlights';
export type { LogSummaryBuckets, WithSummaryProps } from './containers/logs/log_summary';
export { useLogSummary, WithSummary } from './containers/logs/log_summary';
export { useLogEntryFlyout } from './components/logging/log_entry_flyout';

// Shared components
export type { LogAIAssistantDocument } from './components/log_ai_assistant/log_ai_assistant';
Expand All @@ -46,10 +44,13 @@ export {
iconColumnId,
useColumnWidths,
} from './components/logging/log_text_stream/log_entry_column';
export { LogEntryFlyout } from './components/logging/log_entry_flyout';
export type { LogAIAssistantProps } from './components/log_ai_assistant/log_ai_assistant';
export type { LogStreamProps } from './components/log_stream/log_stream';

export const WithSummary = dynamic(() => import('./containers/logs/log_summary/with_summary'));
export const LogEntryFlyout = dynamic(
() => import('./components/logging/log_entry_flyout/log_entry_flyout')
);
export const LogAIAssistant = dynamic(
() => import('./components/log_ai_assistant/log_ai_assistant')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const getFunctionsRoute = createObservabilityAIAssistantServerRoute({

const client = await service.getClient({ request });

const [functionClient, knowledgeBaseInstructions] = await Promise.all([
const [functionClient, userInstructions] = await Promise.all([
service.getFunctionClient({
signal: controller.signal,
resources,
client,
screenContexts: [],
}),
// error is caught in client
client.fetchKnowledgeBaseInstructions(),
client.fetchUserInstructions(),
]);

const functionDefinitions = functionClient.getFunctions().map((fn) => fn.definition);
Expand All @@ -52,7 +52,7 @@ const getFunctionsRoute = createObservabilityAIAssistantServerRoute({
functionDefinitions: functionClient.getFunctions().map((fn) => fn.definition),
systemMessage: getSystemMessageFromInstructions({
registeredInstructions: functionClient.getInstructions(),
knowledgeBaseInstructions,
userInstructions,
requestInstructions: [],
availableFunctionNames,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('Observability AI Assistant client', () => {

const knowledgeBaseServiceMock: DeeplyMockedKeys<KnowledgeBaseService> = {
recall: jest.fn(),
getInstructions: jest.fn(),
getUserInstructions: jest.fn(),
} as any;

let loggerMock: DeeplyMockedKeys<Logger> = {} as any;
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('Observability AI Assistant client', () => {
fields: [],
} as any);

knowledgeBaseServiceMock.getInstructions.mockResolvedValue([]);
knowledgeBaseServiceMock.getUserInstructions.mockResolvedValue([]);

functionClientMock.getInstructions.mockReturnValue(['system']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ export class ObservabilityAIAssistantClient {
);
}

const kbInstructions$ = from(this.fetchKnowledgeBaseInstructions()).pipe(shareReplay());
const userInstructions$ = from(this.fetchUserInstructions()).pipe(shareReplay());

// from the initial messages, override any system message with
// the one that is based on the instructions (registered, request, kb)
const messagesWithUpdatedSystemMessage$ = kbInstructions$.pipe(
map((knowledgeBaseInstructions) => {
const messagesWithUpdatedSystemMessage$ = userInstructions$.pipe(
map((userInstructions) => {
// this is what we eventually store in the conversation
const messagesWithUpdatedSystemMessage = replaceSystemMessage(
getSystemMessageFromInstructions({
registeredInstructions: functionClient.getInstructions(),
knowledgeBaseInstructions,
userInstructions,
requestInstructions,
availableFunctionNames: functionClient
.getFunctions()
Expand Down Expand Up @@ -268,9 +268,9 @@ export class ObservabilityAIAssistantClient {
// messages and the knowledge base instructions
const nextEvents$ = combineLatest([
messagesWithUpdatedSystemMessage$,
kbInstructions$,
userInstructions$,
]).pipe(
switchMap(([messagesWithUpdatedSystemMessage, knowledgeBaseInstructions]) => {
switchMap(([messagesWithUpdatedSystemMessage, userInstructions]) => {
// if needed, inject a context function request here
const contextRequest = functionClient.hasFunction(CONTEXT_FUNCTION_NAME)
? getContextFunctionRequestIfNeeded(messagesWithUpdatedSystemMessage)
Expand Down Expand Up @@ -298,7 +298,7 @@ export class ObservabilityAIAssistantClient {
// start out with the max number of function calls
functionCallsLeft: MAX_FUNCTION_CALLS,
functionClient,
knowledgeBaseInstructions,
userInstructions,
requestInstructions,
signal,
logger: this.dependencies.logger,
Expand Down Expand Up @@ -756,12 +756,12 @@ export class ObservabilityAIAssistantClient {
return this.dependencies.knowledgeBaseService.deleteEntry({ id });
};

fetchKnowledgeBaseInstructions = async () => {
const knowledgeBaseInstructions = await this.dependencies.knowledgeBaseService.getInstructions(
fetchUserInstructions = async () => {
const userInstructions = await this.dependencies.knowledgeBaseService.getUserInstructions(
this.dependencies.namespace,
this.dependencies.user
);

return knowledgeBaseInstructions;
return userInstructions;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function continueConversation({
signal,
functionCallsLeft,
requestInstructions,
knowledgeBaseInstructions,
userInstructions,
logger,
disableFunctions,
tracer,
Expand All @@ -175,7 +175,7 @@ export function continueConversation({
signal: AbortSignal;
functionCallsLeft: number;
requestInstructions: Array<string | UserInstruction>;
knowledgeBaseInstructions: UserInstruction[];
userInstructions: UserInstruction[];
logger: Logger;
disableFunctions: boolean;
tracer: LangTracer;
Expand All @@ -193,7 +193,7 @@ export function continueConversation({
const messagesWithUpdatedSystemMessage = replaceSystemMessage(
getSystemMessageFromInstructions({
registeredInstructions: functionClient.getInstructions(),
knowledgeBaseInstructions,
userInstructions,
requestInstructions,
availableFunctionNames: definitions.map((def) => def.name),
}),
Expand Down Expand Up @@ -314,7 +314,7 @@ export function continueConversation({
functionCallsLeft: nextFunctionCallsLeft,
functionClient,
signal,
knowledgeBaseInstructions,
userInstructions,
requestInstructions,
logger,
disableFunctions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export class KnowledgeBaseService {
};
};

getInstructions = async (
getUserInstructions = async (
namespace: string,
user?: { name: string }
): Promise<UserInstruction[]> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('getSystemMessageFromInstructions', () => {
expect(
getSystemMessageFromInstructions({
registeredInstructions: ['first', 'second'],
knowledgeBaseInstructions: [],
userInstructions: [],
requestInstructions: [],
availableFunctionNames: [],
})
Expand All @@ -27,7 +27,7 @@ describe('getSystemMessageFromInstructions', () => {
return availableFunctionNames[0];
},
],
knowledgeBaseInstructions: [],
userInstructions: [],
requestInstructions: [],
availableFunctionNames: ['myFunction'],
})
Expand All @@ -38,7 +38,7 @@ describe('getSystemMessageFromInstructions', () => {
expect(
getSystemMessageFromInstructions({
registeredInstructions: ['first'],
knowledgeBaseInstructions: [{ doc_id: 'second', text: 'second_kb' }],
userInstructions: [{ doc_id: 'second', text: 'second_kb' }],
requestInstructions: [{ doc_id: 'second', text: 'second_request' }],
availableFunctionNames: [],
})
Expand All @@ -51,7 +51,7 @@ describe('getSystemMessageFromInstructions', () => {
expect(
getSystemMessageFromInstructions({
registeredInstructions: ['first'],
knowledgeBaseInstructions: [{ doc_id: 'second', text: 'second_kb' }],
userInstructions: [{ doc_id: 'second', text: 'second_kb' }],
requestInstructions: [],
availableFunctionNames: [],
})
Expand All @@ -69,7 +69,7 @@ describe('getSystemMessageFromInstructions', () => {
return undefined;
},
],
knowledgeBaseInstructions: [],
userInstructions: [],
requestInstructions: [],
availableFunctionNames: [],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { RegisteredInstruction } from '../types';

export function getSystemMessageFromInstructions({
registeredInstructions,
knowledgeBaseInstructions,
userInstructions,
requestInstructions,
availableFunctionNames,
}: {
registeredInstructions: RegisteredInstruction[];
knowledgeBaseInstructions: UserInstruction[];
userInstructions: UserInstruction[];
requestInstructions: Array<UserInstruction | string>;
availableFunctionNames: string[];
}): string {
Expand All @@ -39,9 +39,7 @@ export function getSystemMessageFromInstructions({

// all request instructions, and those from the KB that are not defined as a request instruction
const allUserInstructions = requestInstructionsWithId.concat(
knowledgeBaseInstructions.filter(
(instruction) => !requestOverrideIds.includes(instruction.doc_id)
)
userInstructions.filter((instruction) => !requestOverrideIds.includes(instruction.doc_id))
);

const instructionsWithinBudget = withTokenBudget(allUserInstructions, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async function executor(
content: getSystemMessageFromInstructions({
availableFunctionNames: functionClient.getFunctions().map((fn) => fn.definition.name),
registeredInstructions: functionClient.getInstructions(),
knowledgeBaseInstructions: [],
userInstructions: [],
requestInstructions: [],
}),
},
Expand Down

0 comments on commit 698dc93

Please sign in to comment.