forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Obs AI Assistant] Regenerate from last user message (elastic#174911)
## Summary Changes the Regenerate functionality to look back to the last written message from the user and use that as the cut of point for where to generate the next messages.
- Loading branch information
1 parent
1f8cce7
commit 602e8ad
Showing
2 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
x-pack/plugins/observability_ai_assistant/public/components/chat/chat_body.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { type Message } from '../../../common/types'; | ||
import { reverseToLastUserMessage } from './chat_body'; | ||
|
||
describe('<ChatBody>', () => { | ||
describe('reverseToLastUserMessage', () => { | ||
const firstUserMessage = { | ||
message: { | ||
role: 'user', | ||
content: 'Give me a list of my APM services', | ||
}, | ||
}; | ||
const firstUserMessageIndex = 1; | ||
|
||
const secondUserMessage = { | ||
message: { | ||
role: 'user', | ||
content: 'Can you tell me about the synth-go-0 service', | ||
}, | ||
}; | ||
const secondUserMessageIndex = 7; | ||
|
||
const messages = [ | ||
{ | ||
message: { | ||
role: 'system', | ||
content: "You're the best around", | ||
}, | ||
}, | ||
firstUserMessage, | ||
{ | ||
message: { | ||
role: 'assistant', | ||
function_call: { | ||
name: 'recall', | ||
arguments: '{"queries":[],"contexts":[]}', | ||
trigger: 'assistant', | ||
}, | ||
content: '', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'user', | ||
name: 'recall', | ||
content: '[]', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'assistant', | ||
function_call: { | ||
name: 'get_apm_services_list', | ||
arguments: '{\n "start": "now-1h",\n "end": "now"\n}', | ||
trigger: 'assistant', | ||
}, | ||
content: '', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'user', | ||
name: 'get_apm_services_list', | ||
content: '[{"service.name":"synth-go-0"}]', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'assistant', | ||
function_call: { | ||
name: '', | ||
arguments: '', | ||
trigger: 'assistant', | ||
}, | ||
content: 'Here is a list of your APM services:\n\n1. synth-go-0\n', | ||
}, | ||
}, | ||
secondUserMessage, | ||
{ | ||
message: { | ||
role: 'assistant', | ||
function_call: { | ||
name: 'recall', | ||
arguments: '{"queries":[],"contexts":[]}', | ||
trigger: 'assistant', | ||
}, | ||
content: '', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'user', | ||
name: 'recall', | ||
content: '[]', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'assistant', | ||
function_call: { | ||
name: 'get_apm_service_summary', | ||
arguments: | ||
'{\n "service.name": "synth-go-0",\n "start": "now-1h",\n "end": "now"\n}', | ||
trigger: 'assistant', | ||
}, | ||
content: '', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'user', | ||
name: 'get_apm_service_summary', | ||
content: '{"service.name":"synth-go-0"}', | ||
}, | ||
}, | ||
{ | ||
message: { | ||
role: 'assistant', | ||
function_call: { | ||
name: '', | ||
arguments: '', | ||
trigger: 'assistant', | ||
}, | ||
content: 'The service named "synth-go-0" is really neat.', | ||
}, | ||
}, | ||
] as unknown as Message[]; | ||
|
||
it('goes back to the last written user message when regenerating from the end of the conversation', () => { | ||
const nextMessages = reverseToLastUserMessage(messages, messages.at(-1)!); | ||
expect(nextMessages).toEqual(messages.slice(0, secondUserMessageIndex + 1)); | ||
}); | ||
|
||
it('goes back to the last written user message when regenerating from the middle of the conversation', () => { | ||
const nextMessages = reverseToLastUserMessage( | ||
messages, | ||
messages.at(secondUserMessageIndex - 1)! | ||
); | ||
expect(nextMessages).toEqual(messages.slice(0, firstUserMessageIndex + 1)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters