Skip to content

Commit

Permalink
[Obs AI Assistant] It should be possible to clear the user-specific s…
Browse files Browse the repository at this point in the history
…ystem prompt (elastic#202279)

I noticed that I was not able to clear the user-specific system prompt.
I had initially entered "Please speak in Swedish" and saved. Afterwards
I wanted to clear this but the save button is disabled if the text
content is empty.

![image](https://github.com/user-attachments/assets/c3889831-e96a-491f-a8c1-29ae235af2ae)
  • Loading branch information
sorenlouv authored and CAWilson94 committed Dec 9, 2024
1 parent c0de7ee commit beb83e3
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 beb83e3

Please sign in to comment.