Support Saving and Resuming Chats in non-interactive mode
What would you like to be added?
It would be quite useful to have command line support for saving and restoring chats.
The following tests show a potential way to use this:
test('should save and resume chat history using tags', async () => {
rig.setup('chat-history-tags');
const tag = `test-session-${Date.now()}`;
// First run: save the history
const result1 = await rig.run(
'What is the capital of France?',
'--save-chat',
tag,
);
expect(result1).toContain('Paris');
// Second run: resume the history
const result2 = await rig.run(
'What is its population?',
'--resume-chat',
tag,
);
expect(result2).toContain('million');
});
test('should save and resume chat history using file paths', async () => {
rig.setup('chat-history-paths');
const filePath = path.resolve(rig.testDir!, `chat-history-${Date.now()}.json`);
// First run: save the history
const result1 = await rig.run(
'What is the capital of Japan?',
'--save-chat',
filePath,
);
expect(result1).toContain('Tokyo');
// Second run: resume the history
const result2 = await rig.run(
'What is its population?',
'--resume-chat',
filePath,
);
expect(result2).toContain('million');
await fs.unlink(filePath);
});
Why is this needed?
Saving and resuming context are generally useful features today, and enabling this on the command line extends the current functionality.
I would also like to save the chat logs to be able to process them for evaluations.
Additional context
No response
I plan to share a PR shortly.
@vmiura We have added "-r" option to gemini cli you could do something like
test('should save and resume chat history', async () => {
rig.setup('chat-history-tags');
// First run: save the history
const result1 = await rig.run(
'What is the capital of France?',
);
expect(result1).toContain('Paris');
// Second run: resume the history
const result2 = await rig.run(
'What is its population?',
'-r',
);
expect(result2).toContain('million');
});
This should suffice the requirement. The only difference being explicit tagging is currently not possible.
In scenarios where we need to resume a specific conversation the below command can be run gemini "What is it's population" -r <session_id>
But this session id is not available to user as o/p of the gemini non interactive mode run. Capturing the requirement to print the session ID in json output mode here