diff --git a/x-pack/plugins/inference/scripts/util/kibana_client.ts b/x-pack/plugins/inference/scripts/util/kibana_client.ts index f8e96cfcf4ae3..ca26ef76b2c72 100644 --- a/x-pack/plugins/inference/scripts/util/kibana_client.ts +++ b/x-pack/plugins/inference/scripts/util/kibana_client.ts @@ -179,6 +179,7 @@ export class KibanaClient { system, toolChoice, tools, + functionCalling, }) => { const body: ChatCompleteRequestBody = { connectorId: chatCompleteConnectorId, @@ -186,6 +187,7 @@ export class KibanaClient { messages, toolChoice, tools, + functionCalling, }; return stream( diff --git a/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/get_system_instructions.ts b/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/get_system_instructions.ts index 872e842e03f86..848b8d1f44f07 100644 --- a/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/get_system_instructions.ts +++ b/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/get_system_instructions.ts @@ -29,9 +29,18 @@ export function getSystemMessageInstructions({ It is EXTREMELY important that you generate valid JSON between the \`\`\`json and \`\`\` delimiters. - You may call them like this. + IMPORTANT: make sure you start and end a tool call with the ${TOOL_USE_START} and ${TOOL_USE_END} markers, it MUST + be included in the tool call. - Given the following tool: + You may call tools like this: + + ${TOOL_USE_START} + \`\`\`json + ${JSON.stringify({ name: '[name of the tool]', input: { myProperty: 'myValue' } })} + \`\`\`\ + ${TOOL_USE_END} + + For example, given the following tool: ${JSON.stringify({ name: 'my_tool', @@ -54,13 +63,15 @@ export function getSystemMessageInstructions({ \`\`\`\ ${TOOL_USE_END} - Given the following tool: + Another example: given the following tool: + ${JSON.stringify({ name: 'my_tool_without_parameters', description: 'A tool to call without parameters', })} Use it the following way: + ${TOOL_USE_START} \`\`\`json ${JSON.stringify({ name: 'my_tool_without_parameters', input: {} })} diff --git a/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/parse_inline_function_calls.ts b/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/parse_inline_function_calls.ts index 2fa9dd899e986..3436d7a7edac5 100644 --- a/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/parse_inline_function_calls.ts +++ b/x-pack/plugins/inference/server/chat_complete/simulated_function_calling/parse_inline_function_calls.ts @@ -45,7 +45,7 @@ export function parseInlineFunctionCalls({ logger }: { logger: Logger }) { logger.debug('Parsing function call:\n' + buffer); const match = buffer.match( - /<\|tool_use_start\|>\s*```json\n?(.*?)(\n```\s*).*<\|tool_use_end\|>/s + /<\|tool_use_start\|>\s*```json\n?(.*?)(\n?```\s*).*<\|tool_use_end\|>/s ); const functionCallBody = match?.[1]; diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/get_system_message_instructions.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/get_system_message_instructions.ts index a409a80716320..c80ac022ca6c0 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/get_system_message_instructions.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/get_system_message_instructions.ts @@ -29,10 +29,19 @@ export function getSystemMessageInstructions({ If a tool does not have properties, leave them out. It is EXTREMELY important that you generate valid JSON between the \`\`\`json and \`\`\` delimiters. - - You may call them like this. - Given the following tool: + IMPORTANT: make sure you start and end a tool call with the ${TOOL_USE_START} and ${TOOL_USE_END} markers, it MUST + be included in the tool call. + + You may call tools like this: + + ${TOOL_USE_START} + \`\`\`json + ${JSON.stringify({ name: '[name of the tool]', input: { myProperty: 'myValue' } })} + \`\`\`\ + ${TOOL_USE_END} + + For example, given the following tool: ${JSON.stringify({ name: 'my_tool', @@ -55,13 +64,15 @@ export function getSystemMessageInstructions({ \`\`\`\ ${TOOL_USE_END} - Given the following tool: + Another example: given the following tool: + ${JSON.stringify({ name: 'my_tool_without_parameters', description: 'A tool to call without parameters', })} - Use it the following way: + Use it the following way: + ${TOOL_USE_START} \`\`\`json ${JSON.stringify({ name: 'my_tool_without_parameters', input: {} })} @@ -77,7 +88,7 @@ export function getSystemMessageInstructions({ ...(fn.parameters ? { parameters: fn.parameters } : {}), })) )} - + `; } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/parse_inline_function_calls.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/parse_inline_function_calls.ts index 82a613ef0b4f8..4ae3c5bf746e3 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/parse_inline_function_calls.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/simulate_function_calling/parse_inline_function_calls.ts @@ -44,7 +44,7 @@ export function parseInlineFunctionCalls({ logger }: { logger: Logger }) { logger.debug('Parsing function call:\n' + buffer); const match = buffer.match( - /<\|tool_use_start\|>\s*```json\n?(.*?)(\n```\s*).*<\|tool_use_end\|>/s + /<\|tool_use_start\|>\s*```json\n?(.*?)(\n?```\s*).*<\|tool_use_end\|>/s ); const functionCallBody = match?.[1]; diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_app/scripts/evaluation/kibana_client.ts b/x-pack/plugins/observability_solution/observability_ai_assistant_app/scripts/evaluation/kibana_client.ts index 8246a9ceae71f..ddfa4c98765f7 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_app/scripts/evaluation/kibana_client.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_app/scripts/evaluation/kibana_client.ts @@ -110,7 +110,7 @@ export class KibanaClient { const url = format({ ...parsed, pathname: `/${[ - baseUrl, + ...(baseUrl ? [baseUrl] : []), ...(props.ignoreSpaceId || !this.spaceId ? [] : ['s', this.spaceId]), props.pathname.startsWith('/') ? props.pathname.substring(1) : props.pathname, ].join('/')}`,