mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Security solution] Fix executor for SimpleChatModel
(#186661)
This commit is contained in:
parent
781db4507d
commit
561c562724
3 changed files with 11 additions and 15 deletions
|
@ -98,20 +98,13 @@ export class ActionsClientSimpleChatModel extends SimpleChatModel {
|
|||
if (!messages.length) {
|
||||
throw new Error('No messages provided.');
|
||||
}
|
||||
const formattedMessages = [];
|
||||
if (messages.length >= 2) {
|
||||
messages.forEach((message, i) => {
|
||||
if (typeof message.content !== 'string') {
|
||||
throw new Error('Multimodal messages are not supported.');
|
||||
}
|
||||
formattedMessages.push(getMessageContentAndRole(message.content, message._getType()));
|
||||
});
|
||||
} else {
|
||||
if (typeof messages[0].content !== 'string') {
|
||||
const formattedMessages: Array<{ content: string; role: string }> = [];
|
||||
messages.forEach((message, i) => {
|
||||
if (typeof message.content !== 'string') {
|
||||
throw new Error('Multimodal messages are not supported.');
|
||||
}
|
||||
formattedMessages.push(getMessageContentAndRole(messages[0].content));
|
||||
}
|
||||
formattedMessages.push(getMessageContentAndRole(message.content, message._getType()));
|
||||
});
|
||||
this.#logger.debug(
|
||||
`ActionsClientSimpleChatModel#_call\ntraceId: ${
|
||||
this.#traceId
|
||||
|
@ -129,7 +122,6 @@ export class ActionsClientSimpleChatModel extends SimpleChatModel {
|
|||
},
|
||||
},
|
||||
};
|
||||
|
||||
// create an actions client from the authenticated request context:
|
||||
const actionsClient = await this.#actions.getActionsClientWithRequest(this.#request);
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ const prepareBedrockOutput = (responseBody: CompletionChunk, logger?: Logger): s
|
|||
return responseBody.delta.text;
|
||||
}
|
||||
}
|
||||
logger?.warn(`Failed to parse bedrock chunk ${JSON.stringify(responseBody)}`);
|
||||
// ignore any chunks that do not include text output
|
||||
return '';
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
ActionsClientChatOpenAI,
|
||||
ActionsClientSimpleChatModel,
|
||||
} from '@kbn/langchain/server';
|
||||
import { MessagesPlaceholder } from '@langchain/core/prompts';
|
||||
import { AgentExecutor } from '../executors/types';
|
||||
import { APMTracer } from '../tracers/apm_tracer';
|
||||
import { AssistantToolParams } from '../../../types';
|
||||
|
@ -126,7 +127,10 @@ export const callAgentExecutor: AgentExecutor<true | false> = async ({
|
|||
returnIntermediateSteps: false,
|
||||
agentArgs: {
|
||||
// this is important to help LangChain correctly format tool input
|
||||
humanMessageTemplate: `Question: {input}\n\n{agent_scratchpad}`,
|
||||
humanMessageTemplate: `Remember, when you have enough information, always prefix your final JSON output with "Final Answer:"\n\nQuestion: {input}\n\n{agent_scratchpad}.`,
|
||||
memoryPrompts: [new MessagesPlaceholder('chat_history')],
|
||||
suffix:
|
||||
'Begin! Reminder to ALWAYS use the above format, and to use tools if appropriate.',
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue