/chat save command saves empty conversations with only system context (#6121)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
parent
8bebaedad4
commit
4973e7e1e0
|
@ -185,30 +185,32 @@ describe('chatCommand', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inform if conversation history is empty', async () => {
|
it('should inform if conversation history is empty or only contains system context', async () => {
|
||||||
mockGetHistory.mockReturnValue([]);
|
mockGetHistory.mockReturnValue([]);
|
||||||
const result = await saveCommand?.action?.(mockContext, tag);
|
let result = await saveCommand?.action?.(mockContext, tag);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
messageType: 'info',
|
messageType: 'info',
|
||||||
content: 'No conversation found to save.',
|
content: 'No conversation found to save.',
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should save the conversation if checkpoint does not exist', async () => {
|
mockGetHistory.mockReturnValue([
|
||||||
const history: HistoryItemWithoutId[] = [
|
{ role: 'user', parts: [{ text: 'context for our chat' }] },
|
||||||
{
|
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
||||||
type: 'user',
|
]);
|
||||||
text: 'hello',
|
result = await saveCommand?.action?.(mockContext, tag);
|
||||||
},
|
expect(result).toEqual({
|
||||||
];
|
type: 'message',
|
||||||
mockGetHistory.mockReturnValue(history);
|
messageType: 'info',
|
||||||
mockCheckpointExists.mockResolvedValue(false);
|
content: 'No conversation found to save.',
|
||||||
|
});
|
||||||
|
|
||||||
const result = await saveCommand?.action?.(mockContext, tag);
|
mockGetHistory.mockReturnValue([
|
||||||
|
{ role: 'user', parts: [{ text: 'context for our chat' }] },
|
||||||
expect(mockCheckpointExists).toHaveBeenCalledWith(tag);
|
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
||||||
expect(mockSaveCheckpoint).toHaveBeenCalledWith(history, tag);
|
{ role: 'user', parts: [{ text: 'Hello, how are you?' }] },
|
||||||
|
]);
|
||||||
|
result = await saveCommand?.action?.(mockContext, tag);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
messageType: 'info',
|
messageType: 'info',
|
||||||
|
@ -237,11 +239,11 @@ describe('chatCommand', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should save the conversation if overwrite is confirmed', async () => {
|
it('should save the conversation if overwrite is confirmed', async () => {
|
||||||
const history: HistoryItemWithoutId[] = [
|
const history: Content[] = [
|
||||||
{
|
{ role: 'user', parts: [{ text: 'context for our chat' }] },
|
||||||
type: 'user',
|
{ role: 'model', parts: [{ text: 'Got it. Thanks for the context!' }] },
|
||||||
text: 'hello',
|
{ role: 'user', parts: [{ text: 'hello' }] },
|
||||||
},
|
{ role: 'model', parts: [{ text: 'Hi there!' }] },
|
||||||
];
|
];
|
||||||
mockGetHistory.mockReturnValue(history);
|
mockGetHistory.mockReturnValue(history);
|
||||||
mockContext.overwriteConfirmed = true;
|
mockContext.overwriteConfirmed = true;
|
||||||
|
|
|
@ -142,7 +142,7 @@ const saveCommand: SlashCommand = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const history = chat.getHistory();
|
const history = chat.getHistory();
|
||||||
if (history.length > 0) {
|
if (history.length > 2) {
|
||||||
await logger.saveCheckpoint(history, tag);
|
await logger.saveCheckpoint(history, tag);
|
||||||
return {
|
return {
|
||||||
type: 'message',
|
type: 'message',
|
||||||
|
|
Loading…
Reference in New Issue