-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inference] Implement NL-to-ESQL task (#190433)
Implements the NL-to-ESQL task and migrates the Observability AI Assistant to use the new task. Most of the files are simply generated documentation. I've also included two scripts: one to generate the documentation, and another to evaluate the task against a real LLM. TBD: run evaluation framework in Observability AI Assistant to ensure there are no performance regressions. --------- Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: pgayvallet <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
d7e5559
commit 5c298a1
Showing
326 changed files
with
6,257 additions
and
4,632 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/inference/common/chat_complete/is_chat_completion_chunk_event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ChatCompletionChunkEvent, ChatCompletionEvent, ChatCompletionEventType } from '.'; | ||
|
||
export function isChatCompletionChunkEvent( | ||
event: ChatCompletionEvent | ||
): event is ChatCompletionChunkEvent { | ||
return event.type === ChatCompletionEventType.ChatCompletionChunk; | ||
} |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/inference/common/chat_complete/is_chat_completion_event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ChatCompletionEvent, ChatCompletionEventType } from '.'; | ||
import { InferenceTaskEvent } from '../inference_task'; | ||
|
||
export function isChatCompletionEvent(event: InferenceTaskEvent): event is ChatCompletionEvent { | ||
return ( | ||
event.type === ChatCompletionEventType.ChatCompletionChunk || | ||
event.type === ChatCompletionEventType.ChatCompletionMessage || | ||
event.type === ChatCompletionEventType.ChatCompletionTokenCount | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/inference/common/chat_complete/is_chat_completion_message_event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ChatCompletionEvent, ChatCompletionEventType, ChatCompletionMessageEvent } from '.'; | ||
import type { ToolOptions } from './tools'; | ||
|
||
export function isChatCompletionMessageEvent<T extends ToolOptions<string>>( | ||
event: ChatCompletionEvent<T> | ||
): event is ChatCompletionMessageEvent<T> { | ||
return event.type === ChatCompletionEventType.ChatCompletionMessage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { Message, MessageRole } from './chat_complete'; | ||
|
||
function isUserMessage(message: Message): boolean { | ||
return message.role !== MessageRole.Assistant; | ||
} | ||
|
||
export function ensureMultiTurn(messages: Message[]): Message[] { | ||
const next: Message[] = []; | ||
|
||
messages.forEach((message) => { | ||
const prevMessage = next[next.length - 1]; | ||
|
||
if (prevMessage && isUserMessage(prevMessage) === isUserMessage(message)) { | ||
next.push({ | ||
content: '-', | ||
role: isUserMessage(message) ? MessageRole.Assistant : MessageRole.User, | ||
}); | ||
} | ||
|
||
next.push(message); | ||
}); | ||
|
||
return next; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { | ||
correctCommonEsqlMistakes, | ||
splitIntoCommands, | ||
} from './tasks/nl_to_esql/correct_common_esql_mistakes'; | ||
|
||
export { isChatCompletionChunkEvent } from './chat_complete/is_chat_completion_chunk_event'; | ||
export { isChatCompletionMessageEvent } from './chat_complete/is_chat_completion_message_event'; | ||
export { isChatCompletionEvent } from './chat_complete/is_chat_completion_event'; | ||
|
||
export { isOutputUpdateEvent } from './output/is_output_update_event'; | ||
export { isOutputCompleteEvent } from './output/is_output_complete_event'; | ||
export { isOutputEvent } from './output/is_output_event'; | ||
|
||
export type { ToolSchema } from './chat_complete/tool_schema'; | ||
|
||
export { | ||
type Message, | ||
MessageRole, | ||
type ToolMessage, | ||
type AssistantMessage, | ||
type UserMessage, | ||
} from './chat_complete'; | ||
|
||
export { generateFakeToolCallId } from './chat_complete/generate_fake_tool_call_id'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/inference/common/output/is_output_complete_event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { OutputEvent, OutputEventType, OutputUpdateEvent } from '.'; | ||
|
||
export function isOutputCompleteEvent<TOutputEvent extends OutputEvent>( | ||
event: TOutputEvent | ||
): event is Exclude<TOutputEvent, OutputUpdateEvent> { | ||
return event.type === OutputEventType.OutputComplete; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { OutputEvent, OutputEventType } from '.'; | ||
import type { InferenceTaskEvent } from '../inference_task'; | ||
|
||
export function isOutputEvent(event: InferenceTaskEvent): event is OutputEvent { | ||
return ( | ||
event.type === OutputEventType.OutputComplete || event.type === OutputEventType.OutputUpdate | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/inference/common/output/is_output_update_event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { OutputEvent, OutputEventType, OutputUpdateEvent } from '.'; | ||
|
||
export function isOutputUpdateEvent<TId extends string>( | ||
event: OutputEvent | ||
): event is OutputUpdateEvent<TId> { | ||
return event.type === OutputEventType.OutputComplete; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.