Skip to content

Commit

Permalink
Add runtime size configuration feature
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Dec 26, 2024
1 parent 1668d58 commit 6b7c15e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
13 changes: 11 additions & 2 deletions frontend/__tests__/services/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe("getSettings", () => {
.mockReturnValueOnce("language_value")
.mockReturnValueOnce("api_key")
.mockReturnValueOnce("true")
.mockReturnValueOnce("invariant");
.mockReturnValueOnce("invariant")
.mockReturnValueOnce("2");

const settings = getSettings();

Expand All @@ -34,6 +35,7 @@ describe("getSettings", () => {
LLM_API_KEY: "api_key",
CONFIRMATION_MODE: true,
SECURITY_ANALYZER: "invariant",
REMOTE_RUNTIME_RESOURCE_FACTOR: 2,
});
});

Expand All @@ -46,6 +48,7 @@ describe("getSettings", () => {
.mockReturnValueOnce(null)
.mockReturnValueOnce(null)
.mockReturnValueOnce(null)
.mockReturnValueOnce(null)
.mockReturnValueOnce(null);

const settings = getSettings();
Expand All @@ -58,6 +61,7 @@ describe("getSettings", () => {
LLM_BASE_URL: DEFAULT_SETTINGS.LLM_BASE_URL,
CONFIRMATION_MODE: DEFAULT_SETTINGS.CONFIRMATION_MODE,
SECURITY_ANALYZER: DEFAULT_SETTINGS.SECURITY_ANALYZER,
REMOTE_RUNTIME_RESOURCE_FACTOR: DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR,
});
});
});
Expand All @@ -72,6 +76,7 @@ describe("saveSettings", () => {
LLM_API_KEY: "some_key",
CONFIRMATION_MODE: true,
SECURITY_ANALYZER: "invariant",
REMOTE_RUNTIME_RESOURCE_FACTOR: 2,
};

saveSettings(settings);
Expand All @@ -86,6 +91,10 @@ describe("saveSettings", () => {
"LLM_API_KEY",
"some_key",
);
expect(localStorage.setItem).toHaveBeenCalledWith(
"REMOTE_RUNTIME_RESOURCE_FACTOR",
"2",
);
});

it.skip("should save partial settings", () => {
Expand All @@ -97,7 +106,7 @@ describe("saveSettings", () => {

expect(localStorage.setItem).toHaveBeenCalledTimes(2);
expect(localStorage.setItem).toHaveBeenCalledWith("LLM_MODEL", "llm_value");
expect(localStorage.setItem).toHaveBeenCalledWith("SETTINGS_VERSION", "2");
expect(localStorage.setItem).toHaveBeenCalledWith("SETTINGS_VERSION", "5");
});

it("should not save invalid settings", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

Check failure on line 1 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'react'` with `"react"`
import { useTranslation } from 'react-i18next';

Check failure on line 2 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'react-i18next'` with `"react-i18next"`

interface RuntimeSizeSelectorProps {
isDisabled: boolean;
defaultValue?: number;
}

export function RuntimeSizeSelector({ isDisabled, defaultValue }: RuntimeSizeSelectorProps) {

Check failure on line 9 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `·isDisabled,·defaultValue·` with `⏎··isDisabled,⏎··defaultValue,⏎`
const { t } = useTranslation();

return (
<div className="flex flex-col gap-2">
<label htmlFor="runtime-size" className="text-sm font-medium text-gray-700">

Check failure on line 14 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `·htmlFor="runtime-size"·className="text-sm·font-medium·text-gray-700"` with `⏎········htmlFor="runtime-size"⏎········className="text-sm·font-medium·text-gray-700"⏎······`
{t('Runtime Size')}

Check failure on line 15 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'Runtime·Size'` with `"Runtime·Size"`
</label>
<select
id="runtime-size"
name="runtime-size"
className="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md"
defaultValue={defaultValue || 1}
disabled={isDisabled}
>
<option value={1}>{t('1x (2 core, 8G)')}</option>

Check failure on line 24 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'1x·(2·core,·8G)'` with `"1x·(2·core,·8G)"`
<option value={2}>{t('2x (4 core, 16G)')}</option>

Check failure on line 25 in frontend/src/components/shared/modals/settings/runtime-size-selector.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'2x·(4·core,·16G)'` with `"2x·(4·core,·16G)"`
</select>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SecurityAnalyzerInput } from "../../inputs/security-analyzers-input";
import { ModalBackdrop } from "../modal-backdrop";
import { ModelSelector } from "./model-selector";
import { useAuth } from "#/context/auth-context";
import { RuntimeSizeSelector } from "./runtime-size-selector";

interface SettingsFormProps {
disabled?: boolean;
Expand Down Expand Up @@ -106,6 +107,7 @@ export function SettingsForm({
posthog.capture("settings_saved", {
LLM_MODEL: newSettings.LLM_MODEL,
LLM_API_KEY: newSettings.LLM_API_KEY ? "SET" : "UNSET",
REMOTE_RUNTIME_RESOURCE_FACTOR: newSettings.REMOTE_RUNTIME_RESOURCE_FACTOR,

Check failure on line 110 in frontend/src/components/shared/modals/settings/settings-form.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Insert `⏎·······`
});
};

Expand Down Expand Up @@ -199,6 +201,11 @@ export function SettingsForm({
defaultValue={settings.LLM_API_KEY}
/>

<RuntimeSizeSelector
isDisabled={!!disabled}
defaultValue={settings.REMOTE_RUNTIME_RESOURCE_FACTOR}
/>

{showAdvancedOptions && (
<AgentInput
isDisabled={!!disabled}
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/services/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const LATEST_SETTINGS_VERSION = 4;
export const LATEST_SETTINGS_VERSION = 5;

export type Settings = {
LLM_MODEL: string;
Expand All @@ -8,6 +8,7 @@ export type Settings = {
LLM_API_KEY: string;
CONFIRMATION_MODE: boolean;
SECURITY_ANALYZER: string;
REMOTE_RUNTIME_RESOURCE_FACTOR: number;
};

export const DEFAULT_SETTINGS: Settings = {
Expand All @@ -18,6 +19,7 @@ export const DEFAULT_SETTINGS: Settings = {
LLM_API_KEY: "",
CONFIRMATION_MODE: false,
SECURITY_ANALYZER: "",
REMOTE_RUNTIME_RESOURCE_FACTOR: 1,
};

const validKeys = Object.keys(DEFAULT_SETTINGS) as (keyof Settings)[];
Expand Down Expand Up @@ -58,6 +60,10 @@ export const maybeMigrateSettings = (logout: () => void) => {
if (currentVersion < 4) {
logout();
}

if (currentVersion < 5) {
localStorage.setItem("REMOTE_RUNTIME_RESOURCE_FACTOR", DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR.toString());

Check failure on line 65 in frontend/src/services/settings.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `"REMOTE_RUNTIME_RESOURCE_FACTOR",·DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR.toString()` with `⏎······"REMOTE_RUNTIME_RESOURCE_FACTOR",⏎······DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR.toString(),⏎····`
}
};

/**
Expand All @@ -76,6 +82,7 @@ export const getSettings = (): Settings => {
const apiKey = localStorage.getItem("LLM_API_KEY");
const confirmationMode = localStorage.getItem("CONFIRMATION_MODE") === "true";
const securityAnalyzer = localStorage.getItem("SECURITY_ANALYZER");
const remoteRuntimeResourceFactor = localStorage.getItem("REMOTE_RUNTIME_RESOURCE_FACTOR");

Check failure on line 85 in frontend/src/services/settings.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `"REMOTE_RUNTIME_RESOURCE_FACTOR"` with `⏎····"REMOTE_RUNTIME_RESOURCE_FACTOR",⏎··`

return {
LLM_MODEL: model || DEFAULT_SETTINGS.LLM_MODEL,
Expand All @@ -85,6 +92,7 @@ export const getSettings = (): Settings => {
LLM_API_KEY: apiKey || DEFAULT_SETTINGS.LLM_API_KEY,
CONFIRMATION_MODE: confirmationMode || DEFAULT_SETTINGS.CONFIRMATION_MODE,
SECURITY_ANALYZER: securityAnalyzer || DEFAULT_SETTINGS.SECURITY_ANALYZER,
REMOTE_RUNTIME_RESOURCE_FACTOR: remoteRuntimeResourceFactor ? parseInt(remoteRuntimeResourceFactor, 10) : DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR,
};
};

Expand Down

0 comments on commit 6b7c15e

Please sign in to comment.