Skip to content

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

Merged
e40pud merged 3 commits intoelastic:8.xfrom
e40pud:backport/8.x/pr-212122
Feb 26, 2025
Merged

[8.x] [Bug][Assistant API] - chat/complete endpoint is not persisting the model response to the chosen conversation ID (#11783) (#212122)#212504
e40pud merged 3 commits intoelastic:8.xfrom
e40pud:backport/8.x/pr-212122

Conversation

@e40pud
Copy link
Contributor

@e40pud e40pud commented 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 e40pud merged commit 68a19ad into elastic:8.x Feb 26, 2025
8 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants