fix(frontend): prevent API key from resetting after modal change (#2329)

* remove bottom chatbox fade

* Modal wider; fix lint error

* settings: attempt to not clear api key for same provider

* prevent api key from resetting after changing the model

* revert other changes and fix post test tear down error

---------

Co-authored-by: amanape <83104063+amanape@users.noreply.github.com>
This commit is contained in:
tobitege
2024-06-08 18:27:43 +02:00
committed by GitHub
parent e8307608c2
commit a8c6fd0d42
3 changed files with 6 additions and 9 deletions

View File

@@ -3,11 +3,11 @@ import userEvent from "@testing-library/user-event";
import { act, render, fireEvent } from "@testing-library/react";
import ChatInput from "./ChatInput";
afterEach(() => {
vi.clearAllMocks();
});
describe("ChatInput", () => {
afterEach(() => {
vi.clearAllMocks();
});
const onSendMessage = vi.fn();
it("should render a textarea", () => {

View File

@@ -26,6 +26,7 @@ vi.mock("#/services/settings", async (importOriginal) => ({
LLM_MODEL: "gpt-4o",
AGENT: "MonologueAgent",
LANGUAGE: "en",
LLM_API_KEY: "sk-...",
}),
getDefaultSettings: vi.fn().mockReturnValue({
LLM_MODEL: "gpt-4o",
@@ -139,7 +140,6 @@ describe("SettingsModal", () => {
expect(saveSettings).toHaveBeenCalledWith({
...initialSettings,
LLM_MODEL: "model3",
LLM_API_KEY: "", // reset after model change
});
});
@@ -196,7 +196,7 @@ describe("SettingsModal", () => {
await userEvent.click(saveButton);
});
expect(toastSpy).toHaveBeenCalledTimes(2);
expect(toastSpy).toHaveBeenCalledTimes(3);
});
it("should change the language", async () => {

View File

@@ -66,12 +66,9 @@ function SettingsModal({ isOpen, onOpenChange }: SettingsProps) {
}, []);
const handleModelChange = (model: string) => {
// Needs to also reset the API key.
const key = localStorage.getItem(`API_KEY_${model}`);
setSettings((prev) => ({
...prev,
LLM_MODEL: model,
LLM_API_KEY: key || "",
}));
};