[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:
Søren Louv-Jansen 2024-06-07 08:50:03 +02:00 committed by GitHub
parent 8e4886c458
commit e5ea1d43ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 29 additions and 31 deletions

View file

@ -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,
}),

View file

@ -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']);

View file

@ -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;
};
}

View file

@ -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,

View file

@ -537,7 +537,7 @@ export class KnowledgeBaseService {
};
};
getInstructions = async (
getUserInstructions = async (
namespace: string,
user?: { name: string }
): Promise<UserInstruction[]> => {

View file

@ -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: [],
})

View file

@ -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);

View file

@ -224,7 +224,7 @@ async function executor(
content: getSystemMessageFromInstructions({
availableFunctionNames: functionClient.getFunctions().map((fn) => fn.definition.name),
registeredInstructions: functionClient.getInstructions(),
knowledgeBaseInstructions: [],
userInstructions: [],
requestInstructions: [],
}),
},