Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Obs AI Assistant] Remove unused signal and LangTracer params #205069

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function registerContextFunction({
'This function provides context as to what the user is looking at on their screen, and recalled documents from the knowledge base that matches their query',
visibility: FunctionVisibility.Internal,
},
async ({ messages, screenContexts, chat }, signal) => {
async ({ messages, screenContexts, chat }) => {
const { analytics } = await resources.plugins.core.start();

async function getContext() {
Expand Down Expand Up @@ -71,7 +71,6 @@ export function registerContextFunction({
userPrompt,
context: screenDescription,
messages,
signal,
analytics,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export async function getRelevantFieldNames({
chunk(fieldNamesToAnalyze, FIELD_NAMES_PER_CHUNK).map(async (fieldsInChunk) => {
const chunkResponse$ = (
await chat('get_relevant_dataset_names', {
signal,
messages: [
{
'@timestamp': new Date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/
import { notImplemented } from '@hapi/boom';
import { toBooleanRt } from '@kbn/io-ts-utils';
import { context as otelContext } from '@opentelemetry/api';
import * as t from 'io-ts';
import { from, map } from 'rxjs';
import { Readable } from 'stream';
import { AssistantScope } from '@kbn/ai-assistant-common';
import { aiAssistantSimulatedFunctionCalling } from '../..';
import { createFunctionResponseMessage } from '../../../common/utils/create_function_response_message';
import { withoutTokenCountEvents } from '../../../common/utils/without_token_count_events';
import { LangTracer } from '../../service/client/instrumentation/lang_tracer';
import { flushBuffer } from '../../service/util/flush_buffer';
import { observableIntoOpenAIStream } from '../../service/util/observable_into_openai_stream';
import { observableIntoStream } from '../../service/util/observable_into_stream';
Expand Down Expand Up @@ -152,22 +150,20 @@ const chatRoute = createObservabilityAIAssistantServerRoute({
body: { name, messages, connectorId, functions, functionCall },
} = params;

const { client, simulateFunctionCalling, signal, isCloudEnabled } = await initializeChatRequest(
const { client, simulateFunctionCalling, isCloudEnabled } = await initializeChatRequest(
resources
);

const response$ = client.chat(name, {
messages,
connectorId,
signal,
...(functions.length
? {
functions,
functionCall,
}
: {}),
simulateFunctionCalling,
tracer: new LangTracer(otelContext.active()),
});

return observableIntoStream(response$.pipe(flushBuffer(isCloudEnabled)));
Expand All @@ -190,7 +186,7 @@ const chatRecallRoute = createObservabilityAIAssistantServerRoute({
}),
}),
handler: async (resources): Promise<Readable> => {
const { client, simulateFunctionCalling, signal, isCloudEnabled } = await initializeChatRequest(
const { client, simulateFunctionCalling, isCloudEnabled } = await initializeChatRequest(
resources
);

Expand All @@ -205,16 +201,13 @@ const chatRecallRoute = createObservabilityAIAssistantServerRoute({
...params,
connectorId,
simulateFunctionCalling,
signal,
tracer: new LangTracer(otelContext.active()),
})
.pipe(withoutTokenCountEvents()),
context,
logger: resources.logger,
messages: [],
userPrompt: prompt,
recall: client.recall,
signal,
})
).pipe(
map(({ scores, suggestions, relevantDocuments }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,8 @@ export class ObservabilityAIAssistantClient {
...chatParams,
simulateFunctionCalling,
connectorId,
signal,
});
},
tracer: completeTracer,
})
),
shareReplay()
Expand Down Expand Up @@ -290,7 +288,6 @@ export class ObservabilityAIAssistantClient {
// inject a chat function with predefined parameters
return this.chat(name, {
...chatParams,
signal,
simulateFunctionCalling,
connectorId,
});
Expand Down Expand Up @@ -468,17 +465,13 @@ export class ObservabilityAIAssistantClient {
connectorId,
functions,
functionCall,
signal,
simulateFunctionCalling,
tracer,
}: {
messages: Message[];
connectorId: string;
functions?: Array<{ name: string; description: string; parameters?: CompatibleJSONSchema }>;
functionCall?: string;
signal: AbortSignal;
simulateFunctionCalling?: boolean;
tracer: LangTracer;
}
): Observable<ChatCompletionChunkEvent | TokenCountEvent | ChatCompletionMessageEvent> => {
let tools: Record<string, { description: string; schema: any }> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ function executeFunctionAndCatchError({
// hide token count events from functions to prevent them from
// having to deal with it as well

return tracer.startActiveSpan(`execute_function ${name}`, ({ tracer: nextTracer }) =>
return tracer.startActiveSpan(`execute_function ${name}`, () =>
hideTokenCountEvents((hide) => {
const executeFunctionResponse$ = from(
functionClient.executeFunction({
name,
chat: (operationName, params) => {
return chat(operationName, {
...params,
tracer: nextTracer,
connectorId,
}).pipe(hide());
},
Expand Down Expand Up @@ -241,7 +240,6 @@ export function continueConversation({
return chat(operationName, {
messages: messagesWithUpdatedSystemMessage,
functions: definitions,
tracer,
connectorId,
}).pipe(emitWithConcatenatedMessage(), catchFunctionNotFoundError(functionLimitExceeded));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
StreamingChatResponseEventType,
} from '../../../../common';
import { ChatEvent } from '../../../../common/conversation_complete';
import { LangTracer } from '../instrumentation/lang_tracer';
import { TITLE_CONVERSATION_FUNCTION_NAME, getGeneratedTitle } from './get_generated_title';

describe('getGeneratedTitle', () => {
Expand Down Expand Up @@ -51,9 +50,6 @@ describe('getGeneratedTitle', () => {
error: jest.fn(),
},
messages,
tracer: {
startActiveSpan: jest.fn(),
} as unknown as LangTracer,
...options,
});

Expand Down Expand Up @@ -185,9 +181,6 @@ describe('getGeneratedTitle', () => {
chat: chatSpy,
logger,
messages,
tracer: {
startActiveSpan: jest.fn(),
} as unknown as LangTracer,
});

const title = await lastValueFrom(title$);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Message, MessageRole } from '../../../../common';
import { concatenateChatCompletionChunks } from '../../../../common/utils/concatenate_chat_completion_chunks';
import { hideTokenCountEvents } from './hide_token_count_events';
import { ChatEvent, TokenCountEvent } from '../../../../common/conversation_complete';
import { LangTracer } from '../instrumentation/lang_tracer';

export const TITLE_CONVERSATION_FUNCTION_NAME = 'title_conversation';

Expand All @@ -28,12 +27,10 @@ export function getGeneratedTitle({
messages,
chat,
logger,
tracer,
}: {
messages: Message[];
chat: ChatFunctionWithoutConnectorAndTokenCount;
logger: Pick<Logger, 'debug' | 'error'>;
tracer: LangTracer;
}): Observable<string | TokenCountEvent> {
return hideTokenCountEvents((hide) =>
chat('generate_title', {
Expand Down Expand Up @@ -74,7 +71,6 @@ export function getGeneratedTitle({
},
],
functionCall: TITLE_CONVERSATION_FUNCTION_NAME,
tracer,
}).pipe(
hide(),
concatenateChatCompletionChunks(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export async function recallAndScore({
context,
messages,
logger,
signal,
}: {
recall: ObservabilityAIAssistantClient['recall'];
chat: FunctionCallChatFunction;
Expand All @@ -33,7 +32,6 @@ export async function recallAndScore({
context: string;
messages: Message[];
logger: Logger;
signal: AbortSignal;
}): Promise<{
relevantDocuments?: RecalledSuggestion[];
scores?: Array<{ id: string; score: number }>;
Expand Down Expand Up @@ -63,7 +61,6 @@ export async function recallAndScore({
messages,
userPrompt,
context,
signal,
chat,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ export async function scoreSuggestions({
userPrompt,
context,
chat,
signal,
logger,
}: {
suggestions: RecalledSuggestion[];
messages: Message[];
userPrompt: string;
context: string;
chat: FunctionCallChatFunction;
signal: AbortSignal;
logger: Logger;
}): Promise<{
relevantDocuments: RecalledSuggestion[];
Expand Down Expand Up @@ -111,7 +109,6 @@ export async function scoreSuggestions({
messages: [...messages.slice(0, -2), newUserMessage],
functions: [scoreFunction],
functionCall: 'score',
signal,
}).pipe(concatenateChatCompletionChunks())
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export function registerAlertsFunction({
messages: nextMessages,
functionCall,
functions: nextFunctions,
signal,
});
},
});
Expand Down Expand Up @@ -162,10 +161,9 @@ export function registerAlertsFunction({
required: ['start', 'end'],
} as const,
},
async (
{ arguments: { start: startAsDatemath, end: endAsDatemath, filter, includeRecovered } },
signal
) => {
async ({
arguments: { start: startAsDatemath, end: endAsDatemath, filter, includeRecovered },
}) => {
const alertsClient = await pluginsStart.ruleRegistry.getRacClientWithRequest(
resources.request as KibanaRequest
);
Expand Down