💄 model selection: model first

This commit is contained in:
Nate Sesti 2023-11-15 23:19:22 -08:00
parent c67920afef
commit 21ea4b2d19
14 changed files with 306 additions and 49 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -284,7 +284,7 @@
"if": {
"properties": {
"provider": {
"enum": ["openai", "openai-aiohttp"]
"enum": ["openai"]
}
},
"required": ["provider"]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -1,12 +1,18 @@
import React, { useContext, useState } from "react";
import React, { useContext, useEffect, useState } from "react";
import styled from "styled-components";
import { buttonColor, defaultBorderRadius, lightGray } from ".";
import { useSelector } from "react-redux";
import { RootStore } from "../redux/store";
import { BookOpenIcon } from "@heroicons/react/24/outline";
import HeaderButtonWithText from "./HeaderButtonWithText";
import { MODEL_PROVIDER_TAG_COLORS, PackageDimension } from "../util/modelData";
import {
MODEL_PROVIDER_TAG_COLORS,
PROVIDER_INFO,
PackageDimension,
} from "../util/modelData";
import InfoHover from "./InfoHover";
import { GUIClientContext } from "../App";
import { useNavigate } from "react-router-dom";
const Div = styled.div<{ color: string; disabled: boolean; hovered: boolean }>`
border: 1px solid ${lightGray};
@ -35,6 +41,9 @@ const DimensionsDiv = styled.div`
padding: 4px;
/* width: fit-content; */
flex-wrap: wrap;
row-gap: 12px;
border-top: 1px solid ${lightGray};
`;
@ -67,12 +76,14 @@ interface ModelCardProps {
tags?: string[];
refUrl?: string;
icon?: string;
onClick: (
onClick?: (
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
dimensionChoices?: string[]
dimensionChoices?: string[],
selectedProvider?: string
) => void;
disabled?: boolean;
dimensions?: PackageDimension[];
providerOptions?: string[];
}
function ModelCard(props: ModelCardProps) {
@ -84,6 +95,16 @@ function ModelCard(props: ModelCardProps) {
const [hovered, setHovered] = useState(false);
const [selectedProvider, setSelectedProvider] = useState<string | undefined>(
undefined
);
useEffect(() => {
if (props.providerOptions?.length) {
setSelectedProvider(props.providerOptions[0]);
}
}, [props.providerOptions]);
return (
<Div
disabled={props.disabled || false}
@ -101,7 +122,8 @@ function ModelCard(props: ModelCardProps) {
if ((e.target as any).closest("a")) {
return;
}
props.onClick(e, dimensionChoices);
props.onClick(e, dimensionChoices, selectedProvider);
}
}
>
@ -149,31 +171,78 @@ function ModelCard(props: ModelCardProps) {
)}
</div>
{props.dimensions?.length && (
{(props.dimensions?.length || props.providerOptions?.length) && (
<DimensionsDiv>
{props.dimensions?.map((dimension, i) => {
return (
<>
<div className="flex items-center justify-between">
<div className="flex items-center">
<InfoHover msg={dimension.description} />
<p className="mx-2 text-sm my-0 py-0">{dimension.name}</p>
</div>
<div className="flex items-center">
{Object.keys(dimension.options).map((key) => {
return (
<DimensionOptionDiv
onClick={(e) => {
e.stopPropagation();
const newChoices = [...dimensionChoices];
newChoices[i] = key;
setDimensionChoices(newChoices);
}}
selected={dimensionChoices[i] === key}
>
{key}
</DimensionOptionDiv>
);
})}
</div>
</div>
<br />
</>
);
})}
{props.providerOptions?.length && (
<div className="flex items-center flex-wrap justify-end rtl">
<div className="flex items-center">
<InfoHover msg={dimension.description} />
<p className="mx-2 text-sm my-0 py-0">{dimension.name}</p>
{Object.keys(dimension.options).map((key) => {
<InfoHover
msg={
"Select the provider through which you will access the model"
}
/>
</div>
<div className="flex items-center flex-wrap justify-end rtl">
{props.providerOptions?.map((option, i) => {
const info = PROVIDER_INFO[option];
return (
<DimensionOptionDiv
onClick={(e) => {
e.stopPropagation();
const newChoices = [...dimensionChoices];
newChoices[i] = key;
setDimensionChoices(newChoices);
<HeaderButtonWithText
text={info.title}
className="p-2 text-center mx-1 items-center"
style={{
backgroundColor:
(i === 0 &&
typeof selectedProvider === "undefined") ||
selectedProvider === option
? buttonColor + "aa"
: undefined,
}}
onClick={() => {
setSelectedProvider(option);
}}
selected={dimensionChoices[i] === key}
>
{key}
</DimensionOptionDiv>
{vscMediaUrl && info.icon && (
<img
src={`${vscMediaUrl}/logos/${info.icon}`}
height="24px"
/>
)}
</HeaderButtonWithText>
);
})}
</div>
);
})}
</div>
)}
</DimensionsDiv>
)}
</Div>

View file

@ -0,0 +1,59 @@
import React, { useState } from "react";
import styled from "styled-components";
import {
buttonColor,
defaultBorderRadius,
lightGray,
secondaryDark,
vscBackground,
} from ".";
const TopDiv = styled.div`
display: flex;
align-items: center;
text-align: center;
margin: auto;
width: fit-content;
cursor: pointer;
border: 1px solid ${lightGray};
background-color: ${secondaryDark};
border-radius: ${defaultBorderRadius};
&:hover {
background-color: ${lightGray}55;
}
`;
const SubDiv = styled.div<{ selected: boolean }>`
text-align: center;
padding: 8px 12px;
border-radius: ${defaultBorderRadius};
transition: all 0.2s ease-in-out;
${(props) =>
props.selected &&
`
background-color: ${buttonColor}77;
box-shadow: 0px 0px 8px 0px ${lightGray}88;
`}
`;
function Toggle(props: {
optionOne: string;
optionTwo: string;
selected: boolean;
onClick: () => void;
}) {
return (
<TopDiv onClick={props.onClick}>
<SubDiv selected={props.selected}>{props.optionOne}</SubDiv>
<SubDiv selected={!props.selected}>{props.optionTwo}</SubDiv>
</TopDiv>
);
}
export default Toggle;

View file

@ -9,16 +9,15 @@ import {
vscBackground,
} from "../components";
import { useNavigate } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { useDispatch } from "react-redux";
import { GUIClientContext } from "../App";
import { useParams } from "react-router-dom";
import {
MODEL_INFO,
PROVIDER_INFO,
MODEL_PROVIDER_TAG_COLORS,
ModelInfo,
updatedObj,
} from "../util/modelData";
import { RootStore } from "../redux/store";
import StyledMarkdownPreview from "../components/StyledMarkdownPreview";
import { FormProvider, useForm } from "react-hook-form";
import _ from "lodash";
@ -64,7 +63,7 @@ function ModelConfig() {
useEffect(() => {
if (modelName) {
setModelInfo(MODEL_INFO[modelName]);
setModelInfo(PROVIDER_INFO[modelName]);
}
}, [modelName]);
@ -181,12 +180,16 @@ function ModelConfig() {
if (d.required) return null;
return (
<div>
<label htmlFor={d.key}>{d.key}</label>
<label htmlFor={d.key}>
{d.key.split(".")[d.key.split(".").length - 1]}
</label>
<Input
type={d.inputType}
id={d.key}
className="border-2 border-gray-200 rounded-md p-2 m-2"
placeholder={d.key}
placeholder={
d.key.split(".")[d.key.split(".").length - 1]
}
defaultValue={d.defaultValue}
min={d.min}
max={d.max}

View file

@ -6,8 +6,9 @@ import { lightGray, vscBackground } from "../components";
import { useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { GUIClientContext } from "../App";
import { setShowDialog } from "../redux/slices/uiStateSlice";
import { MODEL_INFO } from "../util/modelData";
import { MODEL_INFO, PROVIDER_INFO } from "../util/modelData";
import Toggle from "../components/Toggle";
import _ from "lodash";
const GridDiv = styled.div`
display: grid;
@ -21,7 +22,9 @@ const GridDiv = styled.div`
function Models() {
const navigate = useNavigate();
const client = useContext(GUIClientContext);
const dispatch = useDispatch();
const [providersSelected, setProvidersSelected] = React.useState(true);
return (
<div className="overflow-y-scroll">
<div
@ -38,24 +41,62 @@ function Models() {
onClick={() => navigate("/")}
className="inline-block ml-4 cursor-pointer"
/>
<h3 className="text-lg font-bold m-2 inline-block">
Select LLM Provider
</h3>
<h3 className="text-lg font-bold m-2 inline-block">Add new model</h3>
</div>
<GridDiv>
{Object.entries(MODEL_INFO).map(([name, modelInfo]) => (
<ModelCard
title={modelInfo.title}
description={modelInfo.description}
tags={modelInfo.tags}
icon={modelInfo.icon}
refUrl={`https://continue.dev/docs/reference/Models/${modelInfo.provider.toLowerCase()}`}
onClick={(e) => {
navigate(`/modelconfig/${name}`);
}}
/>
))}
</GridDiv>
<br />
<Toggle
selected={providersSelected}
optionOne={"Providers"}
optionTwo={"Models"}
onClick={() => {
setProvidersSelected((prev) => !prev);
}}
></Toggle>
{providersSelected ? (
<GridDiv>
{Object.entries(PROVIDER_INFO).map(([name, modelInfo]) => (
<ModelCard
title={modelInfo.title}
description={modelInfo.description}
tags={modelInfo.tags}
icon={modelInfo.icon}
refUrl={`https://continue.dev/docs/reference/Models/${modelInfo.provider.toLowerCase()}`}
onClick={(e) => {
navigate(`/modelconfig/${name}`);
}}
/>
))}
</GridDiv>
) : (
<GridDiv>
{Object.entries(MODEL_INFO).map(([name, pkg]) => (
<ModelCard
title={pkg.title}
description={pkg.description}
tags={pkg.tags}
icon={pkg.icon}
dimensions={pkg.dimensions}
providerOptions={pkg.providerOptions}
onClick={(e, dimensionChoices, selectedProvider) => {
client?.addModelForRole("*", {
...pkg.params,
..._.merge(
{},
...(pkg.dimensions?.map((dimension, i) => {
if (!dimensionChoices?.[i]) return {};
return {
...dimension.options[dimensionChoices[i]],
};
}) || [])
),
provider: PROVIDER_INFO[selectedProvider].provider,
});
navigate("/");
}}
/>
))}
</GridDiv>
)}
</div>
);
}

View file

@ -159,6 +159,7 @@ export interface ModelPackage {
[key: string]: any;
};
dimensions?: PackageDimension[];
providerOptions?: string[];
}
const codeLlamaInstruct: ModelPackage = {
@ -192,6 +193,14 @@ const codeLlamaInstruct: ModelPackage = {
},
},
],
providerOptions: [
"ollama",
"lmstudio",
"together",
"hftgi",
"llamacpp",
"replicate",
],
};
const llama2Chat: ModelPackage = {
@ -224,6 +233,14 @@ const llama2Chat: ModelPackage = {
},
},
],
providerOptions: [
"ollama",
"lmstudio",
"together",
"hftgi",
"llamacpp",
"replicate",
],
};
const wizardCoder: ModelPackage = {
@ -257,6 +274,7 @@ const wizardCoder: ModelPackage = {
},
},
],
providerOptions: ["ollama", "lmstudio", "hftgi", "llamacpp", "replicate"],
};
const phindCodeLlama: ModelPackage = {
@ -267,6 +285,7 @@ const phindCodeLlama: ModelPackage = {
model: "phind-codellama-34b",
context_length: 2048,
},
providerOptions: ["ollama", "lmstudio", "hftgi", "llamacpp", "replicate"],
};
const mistral: ModelPackage = {
@ -279,6 +298,14 @@ const mistral: ModelPackage = {
context_length: 2048,
},
icon: "mistral.png",
providerOptions: [
"ollama",
"lmstudio",
"together",
"hftgi",
"llamacpp",
"replicate",
],
};
const codeup: ModelPackage = {
@ -289,6 +316,7 @@ const codeup: ModelPackage = {
model: "codeup-13b",
context_length: 2048,
},
providerOptions: ["ollama", "lmstudio", "hftgi", "llamacpp", "replicate"],
};
const osModels = [
@ -310,6 +338,8 @@ const gpt4turbo: ModelPackage = {
title: "GPT-4 Turbo",
api_key: "",
},
providerOptions: ["openai", "freetrial"],
icon: "openai.png",
};
const gpt4: ModelPackage = {
@ -321,6 +351,8 @@ const gpt4: ModelPackage = {
api_key: "",
title: "GPT-4",
},
providerOptions: ["openai", "freetrial"],
icon: "openai.png",
};
const gpt35turbo: ModelPackage = {
@ -333,9 +365,52 @@ const gpt35turbo: ModelPackage = {
title: "GPT-3.5-Turbo",
api_key: "",
},
providerOptions: ["openai", "freetrial"],
icon: "openai.png",
};
export const MODEL_INFO: { [key: string]: ModelInfo } = {
const claude2: ModelPackage = {
title: "Claude-2",
description: "A highly capable model with a 100k context length",
params: {
model: "claude-2",
context_length: 100000,
title: "Claude-2",
api_key: "",
},
providerOptions: ["anthropic"],
icon: "anthropic.png",
};
const chatBison: ModelPackage = {
title: "chat-bison-001",
description:
"Google PaLM's chat-bison-001 model, fine-tuned for chatting about code",
params: {
model: "chat-bison-001",
context_length: 8000,
api_key: "",
title: "Chat Bison",
},
providerOptions: ["palm"],
icon: "google-palm.png",
};
export const MODEL_INFO: ModelPackage[] = [
gpt4,
gpt35turbo,
gpt4turbo,
claude2,
mistral,
codeLlamaInstruct,
llama2Chat,
wizardCoder,
phindCodeLlama,
codeup,
chatBison,
];
export const PROVIDER_INFO: { [key: string]: ModelInfo } = {
openai: {
title: "OpenAI",
provider: "openai",
@ -562,7 +637,7 @@ After it's up and running, you can start using Continue.`,
{ ...apiBaseInput, defaultValue: "http://localhost:8080" },
],
},
ggml: {
"openai-aiohttp": {
title: "Other OpenAI-compatible API",
provider: "openai-aiohttp",
description:

View file

@ -23,6 +23,7 @@ class GUIProtocolServer:
get_context_item: Callable[[str, str], Awaitable[ContextItem]]
get_config: Callable[[], ContinueConfig]
reload_config: AsyncFunc
open_config: Callable[[], Awaitable[None]]
def __init__(
self,
@ -33,6 +34,7 @@ class GUIProtocolServer:
get_context_item: Callable[[str, str], Awaitable[ContextItem]],
get_config: Callable[[], ContinueConfig],
reload_config: AsyncFunc,
open_config: Callable[[], Awaitable[None]],
):
self.window_id = window_id
self.messenger = SocketIOMessenger(sio, sid)
@ -40,6 +42,7 @@ class GUIProtocolServer:
self.get_context_item = get_context_item
self.get_config = get_config
self.reload_config = reload_config
self.open_config = open_config
async def handle_json(self, msg: WebsocketsMessage):
data = msg.data
@ -72,6 +75,7 @@ class GUIProtocolServer:
await self.add_model_for_role(
data["role"], ModelDescription(**data["model"])
)
await self.open_config()
elif msg.message_type == "set_model_for_role_from_index":
await self.set_model_for_role_from_index(data["role"], data["index"])
elif msg.message_type == "delete_model_at_index":

View file

@ -255,6 +255,11 @@ class WindowManager:
if window_id not in self.windows:
self.windows[window_id] = Window()
async def open_config():
ide = self.windows[window_id].ide
if ide is not None:
await ide.setFileOpen(getConfigFilePath(json=True))
gui = GUIProtocolServer(
window_id=window_id,
sio=sio,
@ -263,6 +268,7 @@ class WindowManager:
get_context_item=self.windows[window_id].context_manager.get_context_item,
get_config=self.windows[window_id].get_config,
reload_config=self.windows[window_id].reload_config,
open_config=open_config,
)
self.windows[window_id].gui = gui
self.guis[sid] = gui