Send initialization arguments only when stored in localStorage (#618)

* Send initialization arguments only when stored in localStorage

* Fix mock default-model path
This commit is contained in:
Jim Su
2024-04-03 13:56:47 -04:00
committed by GitHub
parent 310cd7017d
commit 0c00e84e77
7 changed files with 40 additions and 5 deletions

View File

@@ -18,11 +18,11 @@
{
"files": ["*.ts", "*.tsx"],
"rules": {
// Allow state modification in Redux reducers
// Allow state modification in reduce and Redux reducers
"no-param-reassign": ["error", {
"props": true,
"ignorePropertyModificationsFor": [
"state"
"acc", "state"
]
}],
// For https://stackoverflow.com/questions/55844608/stuck-with-eslint-error-i-e-separately-loops-should-be-avoided-in-favor-of-arra

View File

@@ -18,6 +18,7 @@ import {
fetchAgents,
INITIAL_MODELS,
sendSettings,
getInitialModel,
} from "../services/settingsService";
import {
setModel,
@@ -54,6 +55,12 @@ function SettingModal({ isOpen, onClose }: Props): JSX.Element {
);
useEffect(() => {
async function setInitialModel() {
const initialModel = await getInitialModel();
store.dispatch(setModel(initialModel));
}
setInitialModel();
fetchModels().then((fetchedModels) => {
setSupportedModels(fetchedModels);
localStorage.setItem("supportedModels", JSON.stringify(fetchedModels));
@@ -100,7 +107,7 @@ function SettingModal({ isOpen, onClose }: Props): JSX.Element {
}))}
label="Model"
placeholder="Select a model"
defaultSelectedKey={model}
selectedKey={model}
// className="max-w-xs"
onSelectionChange={(key) => {
store.dispatch(setModel(key as string));

View File

@@ -2,6 +2,15 @@ import { appendAssistantMessage } from "../state/chatSlice";
import { setInitialized } from "../state/taskSlice";
import store from "../store";
export async function getInitialModel() {
if (localStorage.getItem("model")) {
return localStorage.getItem("model");
}
const res = await fetch("/api/default-model");
return res.json();
}
export async function fetchModels() {
const response = await fetch(`/api/litellm-models`);
return response.json();

View File

@@ -12,7 +12,17 @@ const WS_URL = `ws://${window.location.host}/ws`;
const socket = new WebSocket(WS_URL);
socket.addEventListener("open", () => {
const { settings } = store.getState();
const settingKeys = ["model", "agent", "workspaceDirectory"];
const settings = settingKeys.reduce(
(acc, key) => {
const value = localStorage.getItem(key);
if (value) {
acc[key] = value;
}
return acc;
},
{} as Record<string, string>,
);
sendSettings(socket, settings, false);
});
socket.addEventListener("message", (event) => {

View File

@@ -3,7 +3,7 @@ import { createSlice } from "@reduxjs/toolkit";
export const settingsSlice = createSlice({
name: "settings",
initialState: {
model: localStorage.getItem("model") || "gpt-4-0125-preview",
model: localStorage.getItem("model") || "",
agent: localStorage.getItem("agent") || "MonologueAgent",
workspaceDirectory:
localStorage.getItem("workspaceDirectory") || "./workspace",

View File

@@ -42,5 +42,9 @@ def read_llm_agents():
"PlannerAgent",
]
@app.get("/default-model")
def read_default_model():
return "gpt-4"
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=3000)

View File

@@ -4,6 +4,7 @@ from fastapi.middleware.cors import CORSMiddleware
import agenthub # noqa F401 (we import this to get the agents registered)
import litellm
from opendevin.agent import Agent
from opendevin import config
app = FastAPI()
@@ -36,3 +37,7 @@ async def get_litellm_agents():
Get all agents supported by LiteLLM.
"""
return Agent.listAgents()
@app.get("/default-model")
def read_default_model():
return config.get_or_error("LLM_MODEL")