-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security AI Assistant] Chat complete API #184485
Merged
stephmilovic
merged 31 commits into
elastic:main
from
YulNaumenko:security-ai-assistant-public-chat
Jul 2, 2024
Merged
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e4355ae
[Security AI Assistant] Chat complete API
YulNaumenko 36b2a5f
reduced params to keep security only
YulNaumenko 57e7d3a
Merge branch 'main' into security-ai-assistant-public-chat
YulNaumenko a057a09
-
YulNaumenko 34dd667
Merge branch 'security-ai-assistant-public-chat' of github.com:YulNau…
YulNaumenko ab7d207
Merge remote-tracking branch 'upstream/main' into security-ai-assista…
YulNaumenko 8a16b33
Merge remote-tracking branch 'upstream/main' into security-ai-assista…
YulNaumenko 2cb73f5
-
YulNaumenko d0e5a16
added conversation persistence to LangGraph
YulNaumenko 81ad5b1
Merge remote-tracking branch 'upstream/main' into security-ai-assista…
YulNaumenko 4c1f465
removed timestamp
YulNaumenko e481450
fixed streaming
YulNaumenko 178762b
renamed api
YulNaumenko f74c072
changed data
YulNaumenko fabcea8
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 551778f
Merge remote-tracking branch 'upstream/main' into security-ai-assista…
YulNaumenko 004d5c8
fixed tests
YulNaumenko 0fdb096
fixed lint errors
YulNaumenko b096a30
fixed tests
YulNaumenko 42afcc6
fixed tests
YulNaumenko f8bce6c
fixing more tests
YulNaumenko a45db81
fixed data and streaming
YulNaumenko ff4f1b8
changes from comments
YulNaumenko 4e7c418
Merge branch 'main' into security-ai-assistant-public-chat
stephmilovic b289452
fix lint
stephmilovic 15fc400
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 09e3c2b
fix streaming
stephmilovic 1ae5e4f
Merge branch 'security-ai-assistant-public-chat' of github.com:YulNau…
stephmilovic 5aa9c72
rm FF from chat/convo routes
stephmilovic 263ddc5
fix test
stephmilovic cf52d5f
fix chat completion route test
stephmilovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
...k/packages/kbn-elastic-assistant-common/impl/schemas/chat/post_chat_complete_route.gen.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,69 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* NOTICE: Do not edit this file manually. | ||
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. | ||
* | ||
* info: | ||
* title: Chat Complete API endpoint | ||
* version: 2023-10-31 | ||
*/ | ||
|
||
import { z } from 'zod'; | ||
|
||
export type RootContext = z.infer<typeof RootContext>; | ||
export const RootContext = z.literal('security'); | ||
|
||
/** | ||
* Message role. | ||
*/ | ||
export type ChatMessageRole = z.infer<typeof ChatMessageRole>; | ||
export const ChatMessageRole = z.enum(['system', 'user', 'assistant']); | ||
export type ChatMessageRoleEnum = typeof ChatMessageRole.enum; | ||
export const ChatMessageRoleEnum = ChatMessageRole.enum; | ||
|
||
export type MessageData = z.infer<typeof MessageData>; | ||
export const MessageData = z.object({}).catchall(z.unknown()); | ||
|
||
/** | ||
* AI assistant message. | ||
*/ | ||
export type ChatMessage = z.infer<typeof ChatMessage>; | ||
export const ChatMessage = z.object({ | ||
/** | ||
* Message content. | ||
*/ | ||
content: z.string().optional(), | ||
/** | ||
* Message role. | ||
*/ | ||
role: ChatMessageRole, | ||
/** | ||
* ECS object to attach to the context of the message. | ||
*/ | ||
data: MessageData.optional(), | ||
fields_to_anonymize: z.array(z.string()).optional(), | ||
}); | ||
|
||
export type ChatCompleteProps = z.infer<typeof ChatCompleteProps>; | ||
export const ChatCompleteProps = z.object({ | ||
conversationId: z.string().optional(), | ||
promptId: z.string().optional(), | ||
isStream: z.boolean().optional(), | ||
responseLanguage: z.string().optional(), | ||
langSmithProject: z.string().optional(), | ||
langSmithApiKey: z.string().optional(), | ||
connectorId: z.string(), | ||
model: z.string().optional(), | ||
persist: z.boolean(), | ||
messages: z.array(ChatMessage), | ||
}); | ||
|
||
export type ChatCompleteRequestBody = z.infer<typeof ChatCompleteRequestBody>; | ||
export const ChatCompleteRequestBody = ChatCompleteProps; | ||
export type ChatCompleteRequestBodyInput = z.input<typeof ChatCompleteRequestBody>; |
109 changes: 109 additions & 0 deletions
109
...kages/kbn-elastic-assistant-common/impl/schemas/chat/post_chat_complete_route.schema.yaml
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,109 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Chat Complete API endpoint | ||
version: '2023-10-31' | ||
paths: | ||
/api/elastic_assistant/chat/complete: | ||
post: | ||
operationId: ChatComplete | ||
x-codegen-enabled: true | ||
description: Creates a model response for the given chat conversation. | ||
summary: Creates a model response for the given chat conversation. | ||
tags: | ||
- Chat Complete API | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ChatCompleteProps' | ||
responses: | ||
200: | ||
description: Indicates a successful call. | ||
content: | ||
application/octet-stream: | ||
schema: | ||
type: string | ||
format: binary | ||
400: | ||
description: Generic Error | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
statusCode: | ||
type: number | ||
error: | ||
type: string | ||
message: | ||
type: string | ||
|
||
components: | ||
schemas: | ||
RootContext: | ||
type: string | ||
enum: | ||
- security | ||
|
||
ChatMessageRole: | ||
type: string | ||
description: Message role. | ||
enum: | ||
- system | ||
- user | ||
- assistant | ||
|
||
MessageData: | ||
type: object | ||
additionalProperties: true | ||
|
||
ChatMessage: | ||
type: object | ||
description: AI assistant message. | ||
required: | ||
- 'role' | ||
properties: | ||
content: | ||
type: string | ||
description: Message content. | ||
role: | ||
$ref: '#/components/schemas/ChatMessageRole' | ||
description: Message role. | ||
data: | ||
description: ECS object to attach to the context of the message. | ||
$ref: '#/components/schemas/MessageData' | ||
fields_to_anonymize: | ||
type: array | ||
items: | ||
type: string | ||
|
||
ChatCompleteProps: | ||
type: object | ||
properties: | ||
conversationId: | ||
type: string | ||
promptId: | ||
type: string | ||
isStream: | ||
type: boolean | ||
responseLanguage: | ||
type: string | ||
langSmithProject: | ||
type: string | ||
langSmithApiKey: | ||
type: string | ||
connectorId: | ||
type: string | ||
model: | ||
type: string | ||
persist: | ||
type: boolean | ||
messages: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/ChatMessage' | ||
required: | ||
- messages | ||
- persist | ||
- connectorId |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on capturing the chat/complete (non-stream) response interface here as well?
I was going to comment and see if we wanted to return
conversationId
whenpersist:true
, but then noticed we are just using theExecuteConnectorResponse
interface as part ofStaticReturnType
, which is whatlangChainExecute
implicitly returns.I guess more generally, what are your thoughts on chat/complete replacing
/actions/connector/{connectorId}/_execute
route? Would be nice to get away from that initial implementation that was mirroring the actions framework.