fix(chat): do not delete the answer when regenerating without a selected model
regenerateResponse removed the previous answer before checking for a model and then returned silently, leaving the conversation without a reply. It now checks first and explains that a model is required, like sendMessage. The duplicated streaming code in sendMessage and regenerateResponse is now a single streamAnswer helper.
This commit is contained in:
1 parent
b441339bb4
commit
1a3ce9ccec
3 files changed
+76
-106
No files matched your search
@@ -165,7 +165,7 @@ describe('ChatScreen', () => {
|
||||
expect(apiMessages[0].role).toBe('system');
|
||||
});
|
||||
|
||||
it('edits without regenerating when no model is selected', () => {
|
||||
it('edits and explains that a model is needed when none is selected', () => {
|
||||
const id = setup();
|
||||
act(() => {
|
||||
useAppStore.setState({ activeModelId: '' });
|
||||
@@ -177,8 +177,9 @@ describe('ChatScreen', () => {
|
||||
jest.advanceTimersByTime(100);
|
||||
});
|
||||
|
||||
expect(state().messages).toHaveLength(1);
|
||||
expect(state().messages).toHaveLength(2);
|
||||
expect(state().messages[0]).toMatchObject({ id, content: 'new question' });
|
||||
expect(state().messages[1].content).toContain('No model selected');
|
||||
expect(streamMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -177,22 +177,34 @@ describe('regenerateResponse', () => {
|
||||
expect(state().isStreaming).toBe(true);
|
||||
});
|
||||
|
||||
it('does nothing without a user message, while streaming, or without a model', async () => {
|
||||
it('keeps the current answer and asks for a model when none is selected', async () => {
|
||||
state().addMessage({ role: 'user', content: 'q' });
|
||||
state().addMessage({ role: 'assistant', content: 'a' });
|
||||
useAppStore.setState({ activeModelId: '' });
|
||||
const { result } = renderHook(() => useLMStudio());
|
||||
|
||||
await act(async () => {
|
||||
await result.current.regenerateResponse();
|
||||
});
|
||||
expect(mockApi.chatCompletionStream).not.toHaveBeenCalled();
|
||||
expect(state().messages.map((m) => m.content)).toEqual([
|
||||
'q',
|
||||
'a',
|
||||
expect.stringContaining('No model selected'),
|
||||
]);
|
||||
});
|
||||
|
||||
it('does nothing without a user message or while streaming', async () => {
|
||||
const { result, rerender } = renderHook(() => useLMStudio());
|
||||
await act(async () => {
|
||||
await result.current.regenerateResponse();
|
||||
});
|
||||
expect(mockApi.chatCompletionStream).not.toHaveBeenCalled();
|
||||
expect(state().messages).toEqual([]);
|
||||
|
||||
act(() => {
|
||||
state().addMessage({ role: 'user', content: 'q' });
|
||||
useAppStore.setState({ activeModelId: '' });
|
||||
});
|
||||
await act(async () => {
|
||||
await result.current.regenerateResponse();
|
||||
});
|
||||
expect(mockApi.chatCompletionStream).not.toHaveBeenCalled();
|
||||
|
||||
act(() => {
|
||||
useAppStore.setState({ activeModelId: 'model-a', isStreaming: true });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user