Skip to content

Commit

Permalink
[8.17] [Obs AI Assistant] It should be possible to clear the user-spe…
Browse files Browse the repository at this point in the history
…cific 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)](#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":"[email protected]"},"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 <[email protected]>
  • Loading branch information
kibanamachine and sorenlouv authored Dec 2, 2024
1 parent d47dded commit ca4cff0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const saveKnowledgeBaseUserInstruction = createObservabilityAIAssistantServerRou
params: t.type({
body: t.type({
id: t.string,
text: nonEmptyStringRt,
text: t.string,
public: toBooleanRt,
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -118,7 +117,6 @@ export function KnowledgeBaseEditUserInstructionFlyout({ onClose }: { onClose: (
fill
isLoading={isSaving}
onClick={handleSubmit}
isDisabled={isSubmitDisabled}
>
{i18n.translate(
'xpack.observabilityAiAssistantManagement.knowledgeBaseNewManualEntryFlyout.saveButtonLabel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
});
});
}

0 comments on commit ca4cff0

Please sign in to comment.