Skip to content

Commit

Permalink
[Observability AI Assistant] Disable functions in insights (#165189)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar authored Aug 30, 2023
1 parent 030fa9e commit d2b145c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ function ChatContent({
const reloadReply = useCallback(() => {
setLoading(true);

const nextSubscription = chatService.chat({ messages, connectorId }).subscribe({
next: (msg) => {
setPendingMessage(() => msg);
},
complete: () => {
setLoading(false);
},
});
const nextSubscription = chatService
.chat({ messages, connectorId, function: 'none' })
.subscribe({
next: (msg) => {
setPendingMessage(() => msg);
},
complete: () => {
setLoading(false);
},
});

setSubscription(nextSubscription);
}, [messages, connectorId, chatService]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ export async function createChatService({
hasRenderFunction: (name: string) => {
return !!getFunctions().find((fn) => fn.options.name === name)?.render;
},
chat({ connectorId, messages }: { connectorId: string; messages: Message[] }) {
chat({
connectorId,
messages,
function: callFunctions = 'auto',
}: {
connectorId: string;
messages: Message[];
function?: 'none' | 'auto';
}) {
const subject = new BehaviorSubject<PendingMessage>({
message: {
role: MessageRole.Assistant,
Expand All @@ -164,7 +172,10 @@ export async function createChatService({
body: {
messages,
connectorId,
functions: functions.map((fn) => pick(fn.options, 'name', 'description', 'parameters')),
functions:
callFunctions === 'none'
? []
: functions.map((fn) => pick(fn.options, 'name', 'description', 'parameters')),
},
},
signal: controller.signal,
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/observability_ai_assistant/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export interface PendingMessage {
}

export interface ObservabilityAIAssistantChatService {
chat: (options: { messages: Message[]; connectorId: string }) => Observable<PendingMessage>;
chat: (options: {
messages: Message[];
connectorId: string;
function?: 'none' | 'auto';
}) => Observable<PendingMessage>;
getContexts: () => ContextDefinition[];
getFunctions: (options?: { contexts?: string[]; filter?: string }) => FunctionDefinition[];
hasRenderFunction: (name: string) => boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ const chatRoute = createObservabilityAIAssistantServerRoute({
return client.chat({
messages,
connectorId,
functions,
functionCall: isStartOfConversation && isRecallFunctionAvailable ? 'recall' : undefined,
...(functions.length
? {
functions,
functionCall: isStartOfConversation && isRecallFunctionAvailable ? 'recall' : undefined,
}
: {}),
});
},
});
Expand Down

0 comments on commit d2b145c

Please sign in to comment.