mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Obs AI Assistant] Rename knowledgeBaseInstructions
to userInstructions
(#184918)
Minor change to rename `knowledgeBaseInstructions` to `userInstructions`. The fact that userinstructions are currently stored in knowledge base is an implementation details and shouldn't leak through.
This commit is contained in:
parent
8e4886c458
commit
e5ea1d43ce
8 changed files with 29 additions and 31 deletions
|
@ -33,7 +33,7 @@ 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,
|
||||
|
@ -41,7 +41,7 @@ const getFunctionsRoute = createObservabilityAIAssistantServerRoute({
|
|||
screenContexts: [],
|
||||
}),
|
||||
// error is caught in client
|
||||
client.fetchKnowledgeBaseInstructions(),
|
||||
client.fetchUserInstructions(),
|
||||
]);
|
||||
|
||||
const functionDefinitions = functionClient.getFunctions().map((fn) => fn.definition);
|
||||
|
@ -52,7 +52,7 @@ const getFunctionsRoute = createObservabilityAIAssistantServerRoute({
|
|||
functionDefinitions: functionClient.getFunctions().map((fn) => fn.definition),
|
||||
systemMessage: getSystemMessageFromInstructions({
|
||||
registeredInstructions: functionClient.getInstructions(),
|
||||
knowledgeBaseInstructions,
|
||||
userInstructions,
|
||||
requestInstructions: [],
|
||||
availableFunctionNames,
|
||||
}),
|
||||
|
|
|
@ -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;
|
||||
|
@ -171,7 +171,7 @@ describe('Observability AI Assistant client', () => {
|
|||
fields: [],
|
||||
} as any);
|
||||
|
||||
knowledgeBaseServiceMock.getInstructions.mockResolvedValue([]);
|
||||
knowledgeBaseServiceMock.getUserInstructions.mockResolvedValue([]);
|
||||
|
||||
functionClientMock.getInstructions.mockReturnValue(['system']);
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ export function continueConversation({
|
|||
signal,
|
||||
functionCallsLeft,
|
||||
requestInstructions,
|
||||
knowledgeBaseInstructions,
|
||||
userInstructions,
|
||||
logger,
|
||||
disableFunctions,
|
||||
tracer,
|
||||
|
@ -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;
|
||||
|
@ -193,7 +193,7 @@ export function continueConversation({
|
|||
const messagesWithUpdatedSystemMessage = replaceSystemMessage(
|
||||
getSystemMessageFromInstructions({
|
||||
registeredInstructions: functionClient.getInstructions(),
|
||||
knowledgeBaseInstructions,
|
||||
userInstructions,
|
||||
requestInstructions,
|
||||
availableFunctionNames: definitions.map((def) => def.name),
|
||||
}),
|
||||
|
@ -314,7 +314,7 @@ export function continueConversation({
|
|||
functionCallsLeft: nextFunctionCallsLeft,
|
||||
functionClient,
|
||||
signal,
|
||||
knowledgeBaseInstructions,
|
||||
userInstructions,
|
||||
requestInstructions,
|
||||
logger,
|
||||
disableFunctions,
|
||||
|
|
|
@ -537,7 +537,7 @@ export class KnowledgeBaseService {
|
|||
};
|
||||
};
|
||||
|
||||
getInstructions = async (
|
||||
getUserInstructions = async (
|
||||
namespace: string,
|
||||
user?: { name: string }
|
||||
): Promise<UserInstruction[]> => {
|
||||
|
|
|
@ -11,7 +11,7 @@ describe('getSystemMessageFromInstructions', () => {
|
|||
expect(
|
||||
getSystemMessageFromInstructions({
|
||||
registeredInstructions: ['first', 'second'],
|
||||
knowledgeBaseInstructions: [],
|
||||
userInstructions: [],
|
||||
requestInstructions: [],
|
||||
availableFunctionNames: [],
|
||||
})
|
||||
|
@ -27,7 +27,7 @@ describe('getSystemMessageFromInstructions', () => {
|
|||
return availableFunctionNames[0];
|
||||
},
|
||||
],
|
||||
knowledgeBaseInstructions: [],
|
||||
userInstructions: [],
|
||||
requestInstructions: [],
|
||||
availableFunctionNames: ['myFunction'],
|
||||
})
|
||||
|
@ -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: [],
|
||||
})
|
||||
|
@ -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: [],
|
||||
})
|
||||
|
@ -69,7 +69,7 @@ describe('getSystemMessageFromInstructions', () => {
|
|||
return undefined;
|
||||
},
|
||||
],
|
||||
knowledgeBaseInstructions: [],
|
||||
userInstructions: [],
|
||||
requestInstructions: [],
|
||||
availableFunctionNames: [],
|
||||
})
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
|
|
@ -224,7 +224,7 @@ async function executor(
|
|||
content: getSystemMessageFromInstructions({
|
||||
availableFunctionNames: functionClient.getFunctions().map((fn) => fn.definition.name),
|
||||
registeredInstructions: functionClient.getInstructions(),
|
||||
knowledgeBaseInstructions: [],
|
||||
userInstructions: [],
|
||||
requestInstructions: [],
|
||||
}),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue