Skip to content

[Bug][Assistant API] - chat/complete endpoint is not persisting the model response to the chosen conversation ID (#11783)#212122

Merged
e40pud merged 3 commits intoelastic:mainfrom
e40pud:security/genai/11783-chat-complete-persisting
Feb 26, 2025
Merged

[Bug][Assistant API] - chat/complete endpoint is not persisting the model response to the chosen conversation ID (#11783)#212122
e40pud merged 3 commits intoelastic:mainfrom
e40pud:security/genai/11783-chat-complete-persisting

Conversation

@e40pud
Copy link
Contributor

@e40pud e40pud commented Feb 21, 2025

Summary

BUG: https://github.com/elastic/security-team/issues/11783

This PR fixes the behaviour of the /api/security_ai_assistant/chat/complete route where the persist flag:

  1. when set to true does not append the assistant reply to existing conversation
  2. when set to false appends user message to existing conversation

Expected behaviour

Details.

  1. conversationId == undefined && persist == false: no new conversations and nothing persisted
  2. conversationId == undefined && persist == true: new conversations is created and both user message and assistant reply appended to the new conversation
  3. conversationId == 'existing-id' && persist == false: nothing appended to the existing conversation
  4. conversationId == 'existing-id' && persist == true: both user message and assistant reply appended to the existing conversation

Testing

  • Use this curl command (with replace connectorId and conversationId) to test the endpoint.
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
  • To retrieve the conversation ID: (/api/security_ai_assistant/current_user/conversations/_find)
  • conversationId can be either existing conversation id or undefined

@e40pud e40pud added release_note:fix v9.0.0 Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Security Generative AI Security Generative AI backport:version Backport to applied version labels v8.18.0 v9.1.0 labels Feb 21, 2025
@e40pud e40pud self-assigned this Feb 21, 2025
@e40pud e40pud requested a review from a team as a code owner February 21, 2025 16:42
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@YulNaumenko YulNaumenko self-requested a review February 24, 2025 16:04
Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested locally, works as expected.
Thank you for the fix @e40pud

# Conflicts:
#	x-pack/solutions/security/plugins/elastic_assistant/server/routes/chat/chat_complete_route.ts
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @e40pud

@e40pud e40pud merged commit a2b2e81 into elastic:main Feb 26, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.17, 8.18, 8.x, 9.0

https://github.com/elastic/kibana/actions/runs/13542392339

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 26, 2025
…odel response to the chosen conversation ID (elastic#11783) (elastic#212122)

## Summary

BUG: elastic/security-team#11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the `persist`
flag:
1. when set to `true` does not append the assistant reply to existing
conversation
2. when set to `false` appends user message to existing conversation

### Expected behaviour

[Details](elastic/security-team#11783 (comment)).

1. `conversationId == undefined && persist == false`: no new
conversations and nothing persisted
2. `conversationId == undefined && persist == true`: new conversations
is created and both user message and assistant reply appended to the new
conversation
3. `conversationId == 'existing-id' && persist == false`: nothing
appended to the existing conversation
4. `conversationId == 'existing-id' && persist == true`: both user
message and assistant reply appended to the existing conversation

### Testing

* Use this `curl` command (with replace `connectorId` and
`conversationId`) to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

* To retrieve the conversation ID:
(/api/security_ai_assistant/current_user/conversations/_find)
* `conversationId` can be either existing conversation id or `undefined`

(cherry picked from commit a2b2e81)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 26, 2025
…odel response to the chosen conversation ID (elastic#11783) (elastic#212122)

## Summary

BUG: elastic/security-team#11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the `persist`
flag:
1. when set to `true` does not append the assistant reply to existing
conversation
2. when set to `false` appends user message to existing conversation

### Expected behaviour

[Details](elastic/security-team#11783 (comment)).

1. `conversationId == undefined && persist == false`: no new
conversations and nothing persisted
2. `conversationId == undefined && persist == true`: new conversations
is created and both user message and assistant reply appended to the new
conversation
3. `conversationId == 'existing-id' && persist == false`: nothing
appended to the existing conversation
4. `conversationId == 'existing-id' && persist == true`: both user
message and assistant reply appended to the existing conversation

### Testing

* Use this `curl` command (with replace `connectorId` and
`conversationId`) to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

* To retrieve the conversation ID:
(/api/security_ai_assistant/current_user/conversations/_find)
* `conversationId` can be either existing conversation id or `undefined`

(cherry picked from commit a2b2e81)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.17 Backport failed because of merge conflicts
8.18
8.x Backport failed because of merge conflicts
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 212122

Questions ?

Please refer to the Backport tool documentation

e40pud added a commit to e40pud/kibana that referenced this pull request Feb 26, 2025
…odel response to the chosen conversation ID (elastic#11783) (elastic#212122)

## Summary

BUG: elastic/security-team#11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the `persist`
flag:
1. when set to `true` does not append the assistant reply to existing
conversation
2. when set to `false` appends user message to existing conversation

### Expected behaviour

[Details](elastic/security-team#11783 (comment)).

1. `conversationId == undefined && persist == false`: no new
conversations and nothing persisted
2. `conversationId == undefined && persist == true`: new conversations
is created and both user message and assistant reply appended to the new
conversation
3. `conversationId == 'existing-id' && persist == false`: nothing
appended to the existing conversation
4. `conversationId == 'existing-id' && persist == true`: both user
message and assistant reply appended to the existing conversation

### Testing

* Use this `curl` command (with replace `connectorId` and
`conversationId`) to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

* To retrieve the conversation ID:
(/api/security_ai_assistant/current_user/conversations/_find)
* `conversationId` can be either existing conversation id or `undefined`

(cherry picked from commit a2b2e81)

# Conflicts:
#	x-pack/solutions/security/plugins/elastic_assistant/server/routes/chat/chat_complete_route.ts
@e40pud
Copy link
Contributor Author

e40pud commented Feb 26, 2025

💚 All backports created successfully

Status Branch Result
8.x
8.17

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

e40pud added a commit to e40pud/kibana that referenced this pull request Feb 26, 2025
…odel response to the chosen conversation ID (elastic#11783) (elastic#212122)

## Summary

BUG: elastic/security-team#11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the `persist`
flag:
1. when set to `true` does not append the assistant reply to existing
conversation
2. when set to `false` appends user message to existing conversation

### Expected behaviour

[Details](elastic/security-team#11783 (comment)).

1. `conversationId == undefined && persist == false`: no new
conversations and nothing persisted
2. `conversationId == undefined && persist == true`: new conversations
is created and both user message and assistant reply appended to the new
conversation
3. `conversationId == 'existing-id' && persist == false`: nothing
appended to the existing conversation
4. `conversationId == 'existing-id' && persist == true`: both user
message and assistant reply appended to the existing conversation

### Testing

* Use this `curl` command (with replace `connectorId` and
`conversationId`) to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

* To retrieve the conversation ID:
(/api/security_ai_assistant/current_user/conversations/_find)
* `conversationId` can be either existing conversation id or `undefined`

(cherry picked from commit a2b2e81)

# Conflicts:
#	x-pack/plugins/elastic_assistant/server/routes/chat/chat_complete_route.ts
kibanamachine added a commit that referenced this pull request Feb 26, 2025
… the model response to the chosen conversation ID (#11783) (#212122) (#212501)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Bug][Assistant API] - chat/complete endpoint is not persisting the
model response to the chosen conversation ID (#11783)
(#212122)](#212122)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ievgen
Sorokopud","email":"ievgen.sorokopud@elastic.co"},"sourceCommit":{"committedDate":"2025-02-26T11:03:09Z","message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v8.17.0","v8.18.0","v9.1.0","v8.19.0"],"title":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID
(#11783)","number":212122,"url":"https://github.com/elastic/kibana/pull/212122","mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.17","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212122","number":212122,"mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ievgen Sorokopud <ievgen.sorokopud@elastic.co>
kibanamachine added a commit that referenced this pull request Feb 26, 2025
…g the model response to the chosen conversation ID (#11783) (#212122) (#212500)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Bug][Assistant API] - chat/complete endpoint is not persisting the
model response to the chosen conversation ID (#11783)
(#212122)](#212122)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ievgen
Sorokopud","email":"ievgen.sorokopud@elastic.co"},"sourceCommit":{"committedDate":"2025-02-26T11:03:09Z","message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v8.17.0","v8.18.0","v9.1.0","v8.19.0"],"title":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID
(#11783)","number":212122,"url":"https://github.com/elastic/kibana/pull/212122","mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.17","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212122","number":212122,"mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ievgen Sorokopud <ievgen.sorokopud@elastic.co>
e40pud added a commit that referenced this pull request Feb 26, 2025
…g the model response to the chosen conversation ID (#11783) (#212122) (#212505)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Bug][Assistant API] - chat/complete endpoint is not persisting the
model response to the chosen conversation ID (#11783)
(#212122)](#212122)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ievgen
Sorokopud","email":"ievgen.sorokopud@elastic.co"},"sourceCommit":{"committedDate":"2025-02-26T11:03:09Z","message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v8.17.0","v8.18.0","v9.1.0","v8.19.0"],"title":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID
(#11783)","number":212122,"url":"https://github.com/elastic/kibana/pull/212122","mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212501","number":212501,"state":"OPEN"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212500","number":212500,"state":"OPEN"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212122","number":212122,"mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
e40pud added a commit that referenced this pull request Feb 26, 2025
… the model response to the chosen conversation ID (#11783) (#212122) (#212504)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Bug][Assistant API] - chat/complete endpoint is not persisting the
model response to the chosen conversation ID (#11783)
(#212122)](#212122)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ievgen
Sorokopud","email":"ievgen.sorokopud@elastic.co"},"sourceCommit":{"committedDate":"2025-02-26T11:03:09Z","message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v8.17.0","v8.18.0","v9.1.0","v8.19.0"],"title":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID
(#11783)","number":212122,"url":"https://github.com/elastic/kibana/pull/212122","mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212501","number":212501,"state":"OPEN"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212500","number":212500,"state":"OPEN"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212122","number":212122,"mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (#11783) (#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
JoseLuisGJ pushed a commit to JoseLuisGJ/kibana that referenced this pull request Feb 27, 2025
…odel response to the chosen conversation ID (elastic#11783) (elastic#212122)

## Summary

BUG: elastic/security-team#11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the `persist`
flag:
1. when set to `true` does not append the assistant reply to existing
conversation
2. when set to `false` appends user message to existing conversation

### Expected behaviour


[Details](elastic/security-team#11783 (comment)).

1. `conversationId == undefined && persist == false`: no new
conversations and nothing persisted
2. `conversationId == undefined && persist == true`: new conversations
is created and both user message and assistant reply appended to the new
conversation
3. `conversationId == 'existing-id' && persist == false`: nothing
appended to the existing conversation
4. `conversationId == 'existing-id' && persist == true`: both user
message and assistant reply appended to the existing conversation

### Testing

* Use this `curl` command (with replace `connectorId` and
`conversationId`) to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

* To retrieve the conversation ID:
(/api/security_ai_assistant/current_user/conversations/_find)
* `conversationId` can be either existing conversation id or `undefined`
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Mar 4, 2025
… the model response to the chosen conversation ID (elastic#11783) (elastic#212122) (elastic#212504)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Bug][Assistant API] - chat/complete endpoint is not persisting the
model response to the chosen conversation ID (elastic#11783)
(elastic#212122)](elastic#212122)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ievgen
Sorokopud","email":"ievgen.sorokopud@elastic.co"},"sourceCommit":{"committedDate":"2025-02-26T11:03:09Z","message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (elastic#11783) (elastic#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v8.17.0","v8.18.0","v9.1.0","v8.19.0"],"title":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID
(elastic#11783)","number":212122,"url":"https://github.com/elastic/kibana/pull/212122","mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (elastic#11783) (elastic#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212501","number":212501,"state":"OPEN"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212500","number":212500,"state":"OPEN"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212122","number":212122,"mergeCommit":{"message":"[Bug][Assistant
API] - chat/complete endpoint is not persisting the model response to
the chosen conversation ID (elastic#11783) (elastic#212122)\n\n## Summary\n\nBUG:
https://github.com/elastic/security-team/issues/11783\n\nThis PR fixes
the behaviour of the\n`/api/security_ai_assistant/chat/complete` route
where the `persist`\nflag:\n1. when set to `true` does not append the
assistant reply to existing\nconversation\n2. when set to `false`
appends user message to existing conversation\n\n### Expected
behaviour\n\n\n[Details](https://github.com/elastic/security-team/issues/11783#issuecomment-2674565194).\n\n1.
`conversationId == undefined && persist == false`: no new\nconversations
and nothing persisted\n2. `conversationId == undefined && persist ==
true`: new conversations\nis created and both user message and assistant
reply appended to the new\nconversation\n3. `conversationId ==
'existing-id' && persist == false`: nothing\nappended to the existing
conversation\n4. `conversationId == 'existing-id' && persist == true`:
both user\nmessage and assistant reply appended to the existing
conversation\n\n### Testing\n\n* Use this `curl` command (with replace
`connectorId` and\n`conversationId`) to test the endpoint.\n\n```\ncurl
--location
'http://localhost:5601/api/security_ai_assistant/chat/complete'
\\\n--header 'kbn-xsrf: true' \\\n--header 'Content-Type:
application/json' \\\n--data '{\n \"connectorId\":
\"{{my-gpt4o-ai}}\",\n \"conversationId\": \"{{existing-conversation-id
| undefined}}\",\n \"isStream\": false,\n \"messages\": [\n {\n
\"content\": \"Follow up\",\n \"role\": \"user\"\n }\n ],\n \"persist\":
true\n}'\n```\n\n* To retrieve the conversation
ID:\n(/api/security_ai_assistant/current_user/conversations/_find)\n*
`conversationId` can be either existing conversation id or
`undefined`","sha":"a2b2e81b5b74ffc56302953d186a36984b3b1c23"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Mar 22, 2025
…odel response to the chosen conversation ID (elastic#11783) (elastic#212122)

## Summary

BUG: elastic/security-team#11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the `persist`
flag:
1. when set to `true` does not append the assistant reply to existing
conversation
2. when set to `false` appends user message to existing conversation

### Expected behaviour


[Details](elastic/security-team#11783 (comment)).

1. `conversationId == undefined && persist == false`: no new
conversations and nothing persisted
2. `conversationId == undefined && persist == true`: new conversations
is created and both user message and assistant reply appended to the new
conversation
3. `conversationId == 'existing-id' && persist == false`: nothing
appended to the existing conversation
4. `conversationId == 'existing-id' && persist == true`: both user
message and assistant reply appended to the existing conversation

### Testing

* Use this `curl` command (with replace `connectorId` and
`conversationId`) to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "{{existing-conversation-id | undefined}}",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

* To retrieve the conversation ID:
(/api/security_ai_assistant/current_user/conversations/_find)
* `conversationId` can be either existing conversation id or `undefined`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:fix Team:Security Generative AI Security Generative AI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.17.0 v8.17.3 v8.18.0 v8.19.0 v9.0.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants