mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[inference] improve simulated function calling instructions (#193414)
## Summary (and do it also for o11y)
This commit is contained in:
parent
6f86d45147
commit
a9402939f3
9 changed files with 73 additions and 23 deletions
|
@ -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(
|
||||
|
|
|
@ -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: {} })}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -4,7 +4,7 @@ The BUCKET function allows you to create groups of values, known as buckets, fro
|
|||
|
||||
## Syntax
|
||||
|
||||
`BUCKET(field, buckets, from, to)`
|
||||
`BUCKET(field, buckets [, from, to])`
|
||||
|
||||
### Parameters
|
||||
|
||||
|
@ -18,16 +18,25 @@ The target number of buckets, or the desired bucket size if `from` and `to` para
|
|||
|
||||
#### from
|
||||
|
||||
The start of the range. This can be a number, a date, or a date expressed as a string.
|
||||
(optional) The start of the range. This can be a number, a date, or a date expressed as a string.
|
||||
|
||||
#### to
|
||||
|
||||
The end of the range. This can be a number, a date, or a date expressed as a string.
|
||||
(optional) The end of the range. This can be a number, a date, or a date expressed as a string.
|
||||
|
||||
## Important notes:
|
||||
|
||||
BUCKET can operate in two modes:
|
||||
- one where the bucket size is computed based on a bucket count recommendation and a range,
|
||||
- and another where the bucket size is provided directly.
|
||||
|
||||
When the bucket size is provided directly for time interval,
|
||||
it is expressed as a *timespan literal*, e.g.
|
||||
- GOOD: `BUCKET(@timestamp, 1 month)`
|
||||
- BAD: `BUCKET(@timestamp, "month")`
|
||||
|
||||
## Examples
|
||||
|
||||
BUCKET can operate in two modes: one where the bucket size is computed based on a bucket count recommendation and a range, and another where the bucket size is provided directly.
|
||||
|
||||
For instance, asking for at most 20 buckets over a year results in monthly buckets:
|
||||
|
||||
```esql
|
||||
|
|
|
@ -16,6 +16,14 @@ This is the interval to which the date will be rounded down. It is expressed usi
|
|||
|
||||
This is the date expression that will be rounded down.
|
||||
|
||||
## Important notes
|
||||
|
||||
The *interval* parameter of DATE_TRUNC is a timespan literal, NOT a string.
|
||||
- GOOD: `DATE_TRUNC(1 year, date)`
|
||||
- BAD: `DATE_TRUNC("year", date)`
|
||||
|
||||
When grouping data by time interval, it is recommended to use BUCKET instead of DATE_TRUNC.
|
||||
|
||||
## Examples
|
||||
|
||||
The following example rounds down the hire_date to the nearest year:
|
||||
|
|
|
@ -43,7 +43,7 @@ FROM index
|
|||
|
||||
## Literals
|
||||
|
||||
ES|QL currently supports numeric and string literals.
|
||||
ES|QL currently supports numeric, string and timespan literals.
|
||||
|
||||
### String Literals
|
||||
|
||||
|
@ -93,11 +93,11 @@ These qualifiers are supported:
|
|||
- `quarter`/`quarters`/`q`
|
||||
- `year`/`years`/`yr`/`y`
|
||||
|
||||
Timespan literals are not whitespace sensitive. These expressions are all valid:
|
||||
|
||||
- 1day
|
||||
- 1 day
|
||||
- 1 day
|
||||
Timespan literals are not whitespace sensitive, and should not be wrapped with quotes:
|
||||
- GOOD: 1day
|
||||
- GOOD: 1 day
|
||||
- BAD: "day"
|
||||
- BAD: "2 days"
|
||||
|
||||
## Example Queries with Timespan Literals
|
||||
|
||||
|
@ -137,6 +137,15 @@ FROM sales
|
|||
| SORT week
|
||||
```
|
||||
|
||||
4. The same example with BUCKET instead of DATE_TRUNC:
|
||||
|
||||
```esql
|
||||
FROM sales
|
||||
| WHERE @timestamp > NOW() - 1 quarter
|
||||
| STATS weekly_sales = SUM(sales_amount) BY week = BUCKET(@timestamp, 1 week)
|
||||
| SORT week
|
||||
```
|
||||
|
||||
5. Retrieve error logs from the last 15 minutes and group by error type:
|
||||
|
||||
```esql
|
||||
|
|
|
@ -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 } : {}),
|
||||
}))
|
||||
)}
|
||||
|
||||
|
||||
`;
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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('/')}`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue