[8.17] [Obs AI Assistant] It should be possible to clear the user-specific system prompt (#202279) (#202468)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Obs AI Assistant] It should be possible to clear the user-specific
system prompt (#202279)](https://github.com/elastic/kibana/pull/202279)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"soren.louv@elastic.co"},"sourceCommit":{"committedDate":"2024-12-02T13:33:59Z","message":"[Obs
AI Assistant] It should be possible to clear the user-specific system
prompt (#202279)\n\nI noticed that I was not able to clear the
user-specific system prompt.\r\nI had initially entered \"Please speak
in Swedish\" and saved. Afterwards\r\nI wanted to clear this but the
save button is disabled if the text\r\ncontent is
empty.\r\n\r\n![image](https://github.com/user-attachments/assets/c3889831-e96a-491f-a8c1-29ae235af2ae)","sha":"a63441d461d32130c25c6d21d2b42c18eb2f14b5","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","v7.17.0","backport:prev-minor","Team:Obs
AI Assistant","ci:project-deploy-observability"],"title":"[Obs AI
Assistant] It should be possible to clear the user-specific system
prompt","number":202279,"url":"https://github.com/elastic/kibana/pull/202279","mergeCommit":{"message":"[Obs
AI Assistant] It should be possible to clear the user-specific system
prompt (#202279)\n\nI noticed that I was not able to clear the
user-specific system prompt.\r\nI had initially entered \"Please speak
in Swedish\" and saved. Afterwards\r\nI wanted to clear this but the
save button is disabled if the text\r\ncontent is
empty.\r\n\r\n![image](https://github.com/user-attachments/assets/c3889831-e96a-491f-a8c1-29ae235af2ae)","sha":"a63441d461d32130c25c6d21d2b42c18eb2f14b5"}},"sourceBranch":"main","suggestedTargetBranches":["7.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202279","number":202279,"mergeCommit":{"message":"[Obs
AI Assistant] It should be possible to clear the user-specific system
prompt (#202279)\n\nI noticed that I was not able to clear the
user-specific system prompt.\r\nI had initially entered \"Please speak
in Swedish\" and saved. Afterwards\r\nI wanted to clear this but the
save button is disabled if the text\r\ncontent is
empty.\r\n\r\n![image](https://github.com/user-attachments/assets/c3889831-e96a-491f-a8c1-29ae235af2ae)","sha":"a63441d461d32130c25c6d21d2b42c18eb2f14b5"}},{"branch":"7.17","label":"v7.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Søren Louv-Jansen <soren.louv@elastic.co>
This commit is contained in:
Kibana Machine 2024-12-03 02:41:28 +11:00 committed by GitHub
parent d47ddedba0
commit ca4cff02c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 4 deletions

View file

@ -133,7 +133,7 @@ const saveKnowledgeBaseUserInstruction = createObservabilityAIAssistantServerRou
params: t.type({
body: t.type({
id: t.string,
text: nonEmptyStringRt,
text: t.string,
public: toBooleanRt,
}),
}),

View file

@ -405,7 +405,7 @@ export class KnowledgeBaseService {
document: {
'@timestamp': new Date().toISOString(),
...doc,
semantic_text: doc.text,
...(doc.text ? { semantic_text: doc.text } : {}),
user,
namespace,
},

View file

@ -31,7 +31,6 @@ export function KnowledgeBaseEditUserInstructionFlyout({ onClose }: { onClose: (
const { mutateAsync: createEntry, isLoading: isSaving } = useCreateKnowledgeBaseUserInstruction();
const [newEntryText, setNewEntryText] = useState('');
const [newEntryId, setNewEntryId] = useState<string>();
const isSubmitDisabled = newEntryText.trim() === '';
useEffect(() => {
const userInstruction = userInstructions?.find((entry) => !entry.public);
@ -118,7 +117,6 @@ export function KnowledgeBaseEditUserInstructionFlyout({ onClose }: { onClose: (
fill
isLoading={isSaving}
onClick={handleSubmit}
isDisabled={isSubmitDisabled}
>
{i18n.translate(
'xpack.observabilityAiAssistantManagement.knowledgeBaseNewManualEntryFlyout.saveButtonLabel',

View file

@ -331,5 +331,36 @@ export default function ApiTest({ getService }: FtrProviderContext) {
expect(conversation.messages.length).to.be(5);
});
});
describe('Instructions can be saved and cleared again', () => {
async function updateInstruction(text: string) {
await observabilityAIAssistantAPIClient
.editor({
endpoint: 'PUT /internal/observability_ai_assistant/kb/user_instructions',
params: {
body: {
id: 'my-instruction-that-will-be-cleared',
text,
public: false,
},
},
})
.expect(200);
const res = await observabilityAIAssistantAPIClient
.editor({ endpoint: 'GET /internal/observability_ai_assistant/kb/user_instructions' })
.expect(200);
return res.body.userInstructions[0].text;
}
it('can clear the instruction', async () => {
const res1 = await updateInstruction('This is a user instruction that will be cleared');
expect(res1).to.be('This is a user instruction that will be cleared');
const res2 = await updateInstruction('');
expect(res2).to.be('');
});
});
});
}