🚧 add + delete models from UI
This commit is contained in:
parent
0053cab91a
commit
5d79795e80
9 changed files with 112 additions and 59 deletions
|
|
@ -16,7 +16,7 @@
|
|||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"noEmitOnError": false,
|
||||
"types": ["jest"]
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": ["./**/*.ts"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import defaultConfig from "../config/default";
|
||||
|
||||
export function getContinueGlobalPath(): string {
|
||||
// This is ~/.continue on mac/linux
|
||||
|
|
@ -28,8 +29,11 @@ export function getSessionsListPath(): string {
|
|||
}
|
||||
|
||||
export function getConfigJsonPath(): string {
|
||||
// TODO: Create if it doesn't exist
|
||||
return path.join(getContinueGlobalPath(), "config.json");
|
||||
const p = path.join(getContinueGlobalPath(), "config.json");
|
||||
if (!fs.existsSync(p)) {
|
||||
fs.writeFileSync(p, JSON.stringify(defaultConfig, null, 2));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
export function devDataPath(): string {
|
||||
|
|
|
|||
|
|
@ -41,10 +41,7 @@ class IdeProtocolClient {
|
|||
const filepath = event.uri.fsPath;
|
||||
const contents = event.getText();
|
||||
const config = JSON.parse(contents);
|
||||
debugPanelWebview?.postMessage({
|
||||
type: "configUpdate",
|
||||
config,
|
||||
});
|
||||
this.configUpdate(config);
|
||||
});
|
||||
|
||||
// Register a content provider for the readonly virtual documents
|
||||
|
|
@ -69,6 +66,13 @@ class IdeProtocolClient {
|
|||
|
||||
visibleMessages: Set<string> = new Set();
|
||||
|
||||
configUpdate(config: any) {
|
||||
debugPanelWebview?.postMessage({
|
||||
type: "configUpdate",
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
async gotoDefinition(
|
||||
filepath: string,
|
||||
position: vscode.Position
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { FileEdit } from "core/types";
|
||||
import { getConfigJsonPath, getDevDataFilePath } from "core/util/paths";
|
||||
import { writeFileSync } from "fs";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import * as io from "socket.io-client";
|
||||
import * as vscode from "vscode";
|
||||
import { ideProtocolClient, windowId } from "./activation/activate";
|
||||
|
|
@ -331,11 +331,39 @@ export function getSidebarContent(
|
|||
break;
|
||||
}
|
||||
case "logDevData": {
|
||||
const filepath: string = getDevDataFilePath(data.message.tableName);
|
||||
const jsonLine = JSON.stringify(data.message.data);
|
||||
const filepath: string = getDevDataFilePath(data.tableName);
|
||||
const jsonLine = JSON.stringify(data.data);
|
||||
writeFileSync(filepath, `${jsonLine}\n`, { flag: "a" });
|
||||
break;
|
||||
}
|
||||
case "addModel": {
|
||||
const model = data.model;
|
||||
const config = readFileSync(getConfigJsonPath(), "utf8");
|
||||
const configJson = JSON.parse(config);
|
||||
configJson.models.push(model);
|
||||
writeFileSync(
|
||||
getConfigJsonPath(),
|
||||
JSON.stringify(
|
||||
configJson,
|
||||
(key, value) => {
|
||||
return value === null ? undefined : value;
|
||||
},
|
||||
2
|
||||
)
|
||||
);
|
||||
ideProtocolClient.configUpdate(configJson);
|
||||
break;
|
||||
}
|
||||
case "deleteModel": {
|
||||
const config = readFileSync(getConfigJsonPath(), "utf8");
|
||||
const configJson = JSON.parse(config);
|
||||
configJson.models = configJson.models.filter(
|
||||
(m: any) => m.title !== data.title
|
||||
);
|
||||
writeFileSync(getConfigJsonPath(), JSON.stringify(configJson, null, 2));
|
||||
ideProtocolClient.configUpdate(configJson);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -376,9 +404,6 @@ export function getSidebarContent(
|
|||
: ""
|
||||
}
|
||||
${page ? `<script>window.location.pathname = "${page}"</script>` : ""}
|
||||
|
||||
|
||||
${false ? `<iframe src="http://localhost:65433/sw"></iframe>` : null}
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ import { useDispatch } from "react-redux";
|
|||
import { useNavigate } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { Button, Input } from "..";
|
||||
import { setDefaultModel } from "../../redux/slices/stateSlice";
|
||||
import { setShowDialog } from "../../redux/slices/uiStateSlice";
|
||||
import { addModel } from "../../util/ide";
|
||||
|
||||
const GridDiv = styled.div`
|
||||
display: grid;
|
||||
|
|
@ -53,14 +55,14 @@ function FTCDialog() {
|
|||
<Button
|
||||
disabled={!apiKey}
|
||||
onClick={() => {
|
||||
// TODO: Edit the config to add this model.
|
||||
// client?.addModelForRole("*", {
|
||||
// model: "gpt-4",
|
||||
// api_key: apiKey,
|
||||
// title: "GPT-4",
|
||||
// provider: "openai",
|
||||
// });
|
||||
addModel({
|
||||
model: "gpt-4",
|
||||
api_key: apiKey,
|
||||
title: "GPT-4",
|
||||
provider: "openai",
|
||||
});
|
||||
dispatch(setShowDialog(false));
|
||||
dispatch(setDefaultModel("GPT-4"));
|
||||
}}
|
||||
>
|
||||
Use my API key
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import { defaultModelSelector } from "../../redux/selectors/modelSelectors";
|
|||
import { setDefaultModel } from "../../redux/slices/stateSlice";
|
||||
import { RootStore } from "../../redux/store";
|
||||
import { getMetaKeyLabel } from "../../util";
|
||||
import { deleteModel } from "../../util/ide";
|
||||
import HeaderButtonWithText from "../HeaderButtonWithText";
|
||||
|
||||
const GridDiv = styled.div`
|
||||
|
|
@ -162,8 +163,7 @@ function ListBoxOption({ option, idx }: { option: Option; idx: number }) {
|
|||
<HeaderButtonWithText
|
||||
text="Delete"
|
||||
onClick={(e) => {
|
||||
// TODO
|
||||
// client?.deleteModelAtIndex(idx - 1); // -1 because 0 is default, not in saved array
|
||||
deleteModel(option.title);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}}
|
||||
|
|
@ -173,7 +173,6 @@ function ListBoxOption({ option, idx }: { option: Option; idx: number }) {
|
|||
<TrashIcon width="1.2em" height="1.2em" />
|
||||
</HeaderButtonWithText>
|
||||
)}
|
||||
{idx === 0 && <TrashIcon width="1.6em" height="1.6em" opacity={0.0} />}
|
||||
</div>
|
||||
</StyledListboxOption>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||
import _ from "lodash";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { FormProvider, useForm } from "react-hook-form";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
|
@ -12,6 +13,8 @@ import {
|
|||
} from "../components";
|
||||
import StyledMarkdownPreview from "../components/markdown/StyledMarkdownPreview";
|
||||
import ModelCard from "../components/modelSelection/ModelCard";
|
||||
import { setDefaultModel } from "../redux/slices/stateSlice";
|
||||
import { addModel } from "../util/ide";
|
||||
import {
|
||||
MODEL_PROVIDER_TAG_COLORS,
|
||||
ModelInfo,
|
||||
|
|
@ -225,22 +228,23 @@ function ModelConfig() {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO
|
||||
// client?.addModelForRole("default", {
|
||||
// ...pkg.params,
|
||||
// ...modelInfo.params,
|
||||
// ..._.merge(
|
||||
// {},
|
||||
// ...(pkg.dimensions?.map((dimension, i) => {
|
||||
// if (!dimensionChoices?.[i]) return {};
|
||||
// return {
|
||||
// ...dimension.options[dimensionChoices[i]],
|
||||
// };
|
||||
// }) || [])
|
||||
// ),
|
||||
// ...formParams,
|
||||
// provider: modelInfo.provider,
|
||||
// });
|
||||
const model = {
|
||||
...pkg.params,
|
||||
...modelInfo.params,
|
||||
..._.merge(
|
||||
{},
|
||||
...(pkg.dimensions?.map((dimension, i) => {
|
||||
if (!dimensionChoices?.[i]) return {};
|
||||
return {
|
||||
...dimension.options[dimensionChoices[i]],
|
||||
};
|
||||
}) || [])
|
||||
),
|
||||
...formParams,
|
||||
provider: modelInfo.provider,
|
||||
};
|
||||
addModel(model);
|
||||
dispatch(setDefaultModel(model.title));
|
||||
navigate("/");
|
||||
}}
|
||||
/>
|
||||
|
|
@ -259,12 +263,13 @@ function ModelConfig() {
|
|||
: parseFloat(formMethods.watch(d.key));
|
||||
}
|
||||
|
||||
// TODO
|
||||
// client?.addModelForRole("default", {
|
||||
// ...modelInfo.packages[0]?.params,
|
||||
// ...modelInfo.params,
|
||||
// ...formParams,
|
||||
// });
|
||||
const model = {
|
||||
...modelInfo.packages[0]?.params,
|
||||
...modelInfo.params,
|
||||
...formParams,
|
||||
};
|
||||
addModel(model);
|
||||
dispatch(setDefaultModel(model.title));
|
||||
navigate("/");
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||
import _ from "lodash";
|
||||
import React from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { lightGray, vscBackground } from "../components";
|
||||
import ModelCard from "../components/modelSelection/ModelCard";
|
||||
|
||||
import { useDispatch } from "react-redux";
|
||||
import Toggle from "../components/modelSelection/Toggle";
|
||||
import { setDefaultModel } from "../redux/slices/stateSlice";
|
||||
import { addModel } from "../util/ide";
|
||||
import { MODEL_INFO, PROVIDER_INFO } from "../util/modelData";
|
||||
|
||||
const GridDiv = styled.div`
|
||||
|
|
@ -19,6 +23,7 @@ const GridDiv = styled.div`
|
|||
|
||||
function Models() {
|
||||
const navigate = useNavigate();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [providersSelected, setProvidersSelected] = React.useState(true);
|
||||
|
||||
|
|
@ -75,20 +80,21 @@ function Models() {
|
|||
dimensions={pkg.dimensions}
|
||||
providerOptions={pkg.providerOptions}
|
||||
onClick={(e, dimensionChoices, selectedProvider) => {
|
||||
// TODO
|
||||
// client?.addModelForRole("*", {
|
||||
// ...pkg.params,
|
||||
// ..._.merge(
|
||||
// {},
|
||||
// ...(pkg.dimensions?.map((dimension, i) => {
|
||||
// if (!dimensionChoices?.[i]) return {};
|
||||
// return {
|
||||
// ...dimension.options[dimensionChoices[i]],
|
||||
// };
|
||||
// }) || [])
|
||||
// ),
|
||||
// provider: PROVIDER_INFO[selectedProvider].provider,
|
||||
// });
|
||||
const model = {
|
||||
...pkg.params,
|
||||
..._.merge(
|
||||
{},
|
||||
...(pkg.dimensions?.map((dimension, i) => {
|
||||
if (!dimensionChoices?.[i]) return {};
|
||||
return {
|
||||
...dimension.options[dimensionChoices[i]],
|
||||
};
|
||||
}) || [])
|
||||
),
|
||||
provider: PROVIDER_INFO[selectedProvider].provider,
|
||||
};
|
||||
addModel(model);
|
||||
dispatch(setDefaultModel(model.title));
|
||||
navigate("/");
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -69,3 +69,11 @@ export function errorPopup(message: string) {
|
|||
export function logDevData(tableName: string, data: any) {
|
||||
postToIde("logDevData", { tableName, data });
|
||||
}
|
||||
|
||||
export function addModel(model: any) {
|
||||
postToIde("addModel", { model });
|
||||
}
|
||||
|
||||
export function deleteModel(title: any) {
|
||||
postToIde("deleteModel", { title });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue