feat: ✨ select model param count from UI
This commit is contained in:
parent
58cd4db253
commit
105afeccca
6 changed files with 241 additions and 155 deletions
1
extension/react-app/package-lock.json
generated
1
extension/react-app/package-lock.json
generated
|
|
@ -11,6 +11,7 @@
|
|||
"@types/vscode-webview": "^1.57.1",
|
||||
"@uiw/react-markdown-preview": "^4.1.13",
|
||||
"downshift": "^7.6.0",
|
||||
"lodash": "^4.17.21",
|
||||
"meilisearch": "^0.33.0",
|
||||
"posthog-js": "^1.58.0",
|
||||
"prismjs": "^1.29.0",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
"@types/vscode-webview": "^1.57.1",
|
||||
"@uiw/react-markdown-preview": "^4.1.13",
|
||||
"downshift": "^7.6.0",
|
||||
"lodash": "^4.17.21",
|
||||
"meilisearch": "^0.33.0",
|
||||
"posthog-js": "^1.58.0",
|
||||
"prismjs": "^1.29.0",
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import React, { useContext } from "react";
|
||||
import React, { useContext, 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 } from "../util/modelData";
|
||||
import { MODEL_PROVIDER_TAG_COLORS, PackageDimension } from "../util/modelData";
|
||||
import InfoHover from "./InfoHover";
|
||||
|
||||
const Div = styled.div<{ color: string; disabled: boolean }>`
|
||||
const Div = styled.div<{ color: string; disabled: boolean; hovered: boolean }>`
|
||||
border: 1px solid ${lightGray};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
padding: 4px 8px;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
transition: all 0.5s;
|
||||
|
|
@ -20,13 +20,45 @@ const Div = styled.div<{ color: string; disabled: boolean }>`
|
|||
? `
|
||||
opacity: 0.5;
|
||||
`
|
||||
: `
|
||||
&:hover {
|
||||
: props.hovered
|
||||
? `
|
||||
border: 1px solid ${props.color};
|
||||
background-color: ${props.color}22;
|
||||
cursor: pointer;
|
||||
}
|
||||
cursor: pointer;`
|
||||
: ""}
|
||||
`;
|
||||
|
||||
const DimensionsDiv = styled.div`
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-left: auto;
|
||||
padding: 4px;
|
||||
/* width: fit-content; */
|
||||
|
||||
border-top: 1px solid ${lightGray};
|
||||
`;
|
||||
|
||||
const DimensionOptionDiv = styled.div<{ selected: boolean }>`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-right: 8px;
|
||||
background-color: ${lightGray};
|
||||
padding: 4px;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
outline: 0.5px solid ${lightGray};
|
||||
|
||||
${(props) =>
|
||||
props.selected &&
|
||||
`
|
||||
background-color: ${buttonColor};
|
||||
color: white;
|
||||
`}
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
outline: 1px solid ${buttonColor};
|
||||
}
|
||||
`;
|
||||
|
||||
interface ModelCardProps {
|
||||
|
|
@ -35,8 +67,12 @@ interface ModelCardProps {
|
|||
tags?: string[];
|
||||
refUrl?: string;
|
||||
icon?: string;
|
||||
onClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
||||
onClick: (
|
||||
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
||||
dimensionChoices?: string[]
|
||||
) => void;
|
||||
disabled?: boolean;
|
||||
dimensions?: PackageDimension[];
|
||||
}
|
||||
|
||||
function ModelCard(props: ModelCardProps) {
|
||||
|
|
@ -44,53 +80,96 @@ function ModelCard(props: ModelCardProps) {
|
|||
(state: RootStore) => state.config.vscMediaUrl
|
||||
);
|
||||
|
||||
const [dimensionChoices, setDimensionChoices] = useState<string[]>(
|
||||
props.dimensions?.map((d) => Object.keys(d.options)[0]) || []
|
||||
);
|
||||
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
return (
|
||||
<Div
|
||||
disabled={props.disabled || false}
|
||||
color={buttonColor}
|
||||
onClick={props.disabled ? undefined : (e) => props.onClick(e)}
|
||||
hovered={hovered}
|
||||
>
|
||||
<div style={{ display: "flex", alignItems: "center" }}>
|
||||
{vscMediaUrl && props.icon && (
|
||||
<img
|
||||
src={`${vscMediaUrl}/logos/${props.icon}`}
|
||||
height="24px"
|
||||
style={{ marginRight: "10px" }}
|
||||
/>
|
||||
)}
|
||||
<h3>{props.title}</h3>
|
||||
</div>
|
||||
{props.tags?.map((tag) => {
|
||||
return (
|
||||
<span
|
||||
style={{
|
||||
backgroundColor: `${MODEL_PROVIDER_TAG_COLORS[tag]}55`,
|
||||
color: "white",
|
||||
padding: "2px 4px",
|
||||
borderRadius: defaultBorderRadius,
|
||||
marginRight: "4px",
|
||||
}}
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
<p>{props.description}</p>
|
||||
<div
|
||||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
className="px-2 py-1"
|
||||
onClick={
|
||||
props.disabled ? undefined : (e) => props.onClick(e, dimensionChoices)
|
||||
}
|
||||
>
|
||||
<div style={{ display: "flex", alignItems: "center" }}>
|
||||
{vscMediaUrl && props.icon && (
|
||||
<img
|
||||
src={`${vscMediaUrl}/logos/${props.icon}`}
|
||||
height="24px"
|
||||
style={{ marginRight: "10px" }}
|
||||
/>
|
||||
)}
|
||||
<h3>{props.title}</h3>
|
||||
</div>
|
||||
{props.tags?.map((tag) => {
|
||||
return (
|
||||
<span
|
||||
style={{
|
||||
backgroundColor: `${MODEL_PROVIDER_TAG_COLORS[tag]}55`,
|
||||
color: "white",
|
||||
padding: "2px 4px",
|
||||
borderRadius: defaultBorderRadius,
|
||||
marginRight: "4px",
|
||||
}}
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
<p>{props.description}</p>
|
||||
|
||||
{props.refUrl && (
|
||||
<a
|
||||
style={{
|
||||
position: "absolute",
|
||||
right: "8px",
|
||||
top: "8px",
|
||||
}}
|
||||
href={props.refUrl}
|
||||
target="_blank"
|
||||
>
|
||||
<HeaderButtonWithText text="Read the docs">
|
||||
<BookOpenIcon width="1.6em" height="1.6em" />
|
||||
</HeaderButtonWithText>
|
||||
</a>
|
||||
{props.refUrl && (
|
||||
<a
|
||||
style={{
|
||||
position: "absolute",
|
||||
right: "8px",
|
||||
top: "8px",
|
||||
}}
|
||||
href={props.refUrl}
|
||||
target="_blank"
|
||||
>
|
||||
<HeaderButtonWithText text="Read the docs">
|
||||
<BookOpenIcon width="1.6em" height="1.6em" />
|
||||
</HeaderButtonWithText>
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{props.dimensions?.length && (
|
||||
<DimensionsDiv>
|
||||
{props.dimensions?.map((dimension, i) => {
|
||||
return (
|
||||
<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) => {
|
||||
return (
|
||||
<DimensionOptionDiv
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
const newChoices = [...dimensionChoices];
|
||||
newChoices[i] = key;
|
||||
setDimensionChoices(newChoices);
|
||||
}}
|
||||
selected={dimensionChoices[i] === key}
|
||||
>
|
||||
{key}
|
||||
</DimensionOptionDiv>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</DimensionsDiv>
|
||||
)}
|
||||
</Div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import { RootStore } from "../redux/store";
|
|||
import StyledMarkdownPreview from "../components/StyledMarkdownPreview";
|
||||
import { getFontSize } from "../util";
|
||||
import { FormProvider, useForm } from "react-hook-form";
|
||||
import _ from "lodash";
|
||||
|
||||
const GridDiv = styled.div`
|
||||
display: grid;
|
||||
|
|
@ -219,7 +220,8 @@ function ModelConfig() {
|
|||
tags={pkg.tags}
|
||||
refUrl={pkg.refUrl}
|
||||
icon={pkg.icon || modelInfo.icon}
|
||||
onClick={(e) => {
|
||||
dimensions={pkg.dimensions}
|
||||
onClick={(e, dimensionChoices) => {
|
||||
if (disableModelCards()) return;
|
||||
const formParams: any = {};
|
||||
for (const d of modelInfo.collectInputFor || []) {
|
||||
|
|
@ -232,6 +234,15 @@ function ModelConfig() {
|
|||
client?.addModelForRole("*", modelInfo.class, {
|
||||
...pkg.params,
|
||||
...modelInfo.params,
|
||||
..._.merge(
|
||||
{},
|
||||
...(pkg.dimensions?.map((dimension, i) => {
|
||||
if (!dimensionChoices?.[i]) return {};
|
||||
return {
|
||||
...dimension.options[dimensionChoices[i]],
|
||||
};
|
||||
}) || [])
|
||||
),
|
||||
...formParams,
|
||||
});
|
||||
navigate("/");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,17 @@
|
|||
import _ from "lodash";
|
||||
|
||||
function updatedObj(old: any, pathToValue: { [key: string]: any }) {
|
||||
const newObject = _.cloneDeep(old);
|
||||
for (const key in pathToValue) {
|
||||
if (typeof pathToValue[key] === "function") {
|
||||
_.updateWith(newObject, key, pathToValue[key]);
|
||||
} else {
|
||||
_.updateWith(newObject, key, (__) => pathToValue[key]);
|
||||
}
|
||||
}
|
||||
return newObject;
|
||||
}
|
||||
|
||||
export enum ModelProviderTag {
|
||||
"Requires API Key" = "Requires API Key",
|
||||
"Local" = "Local",
|
||||
|
|
@ -118,6 +132,14 @@ export interface ModelInfo {
|
|||
collectInputFor?: InputDescriptor[];
|
||||
}
|
||||
|
||||
// A dimension is like parameter count - 7b, 13b, 34b, etc.
|
||||
// You would set options to the field that should be changed for that option in the params field of ModelPackage
|
||||
export interface PackageDimension {
|
||||
name: string;
|
||||
description: string;
|
||||
options: { [key: string]: { [key: string]: any } };
|
||||
}
|
||||
|
||||
export interface ModelPackage {
|
||||
collectInputFor?: InputDescriptor[];
|
||||
description: string;
|
||||
|
|
@ -134,11 +156,13 @@ export interface ModelPackage {
|
|||
replace?: [string, string][];
|
||||
[key: string]: any;
|
||||
};
|
||||
dimensions?: PackageDimension[];
|
||||
}
|
||||
|
||||
const codeLlama7bInstruct: ModelPackage = {
|
||||
title: "CodeLlama-7b-Instruct",
|
||||
description: "A 7b parameter model tuned for code generation",
|
||||
const codeLlamaInstruct: ModelPackage = {
|
||||
title: "CodeLlama Instruct",
|
||||
description:
|
||||
"A model from Meta, fine-tuned for code generation and conversation",
|
||||
refUrl: "",
|
||||
params: {
|
||||
title: "CodeLlama-7b-Instruct",
|
||||
|
|
@ -147,35 +171,31 @@ const codeLlama7bInstruct: ModelPackage = {
|
|||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
};
|
||||
const codeLlama13bInstruct: ModelPackage = {
|
||||
title: "CodeLlama-13b-Instruct",
|
||||
description: "A 13b parameter model tuned for code generation",
|
||||
refUrl: "",
|
||||
params: {
|
||||
title: "CodeLlama13b-Instruct",
|
||||
model: "codellama13b-instruct",
|
||||
context_length: 2048,
|
||||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
};
|
||||
const codeLlama34bInstruct: ModelPackage = {
|
||||
title: "CodeLlama-34b-Instruct",
|
||||
description: "A 34b parameter model tuned for code generation",
|
||||
refUrl: "",
|
||||
params: {
|
||||
title: "CodeLlama-34b-Instruct",
|
||||
model: "codellama:34b-instruct",
|
||||
context_length: 2048,
|
||||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
dimensions: [
|
||||
{
|
||||
name: "Parameter Count",
|
||||
description: "The number of parameters in the model",
|
||||
options: {
|
||||
"7b": {
|
||||
model: "codellama:7b-instruct",
|
||||
title: "CodeLlama-7b-Instruct",
|
||||
},
|
||||
"13b": {
|
||||
model: "codellama:13b-instruct",
|
||||
title: "CodeLlama-13b-Instruct",
|
||||
},
|
||||
"34b": {
|
||||
model: "codellama:34b-instruct",
|
||||
title: "CodeLlama-34b-Instruct",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const llama2Chat7b: ModelPackage = {
|
||||
title: "Llama2-7b-Chat",
|
||||
description: "A 7b parameter model fine-tuned for chat",
|
||||
const llama2Chat: ModelPackage = {
|
||||
title: "Llama2 Chat",
|
||||
description: "The latest Llama model from Meta, fine-tuned for chat",
|
||||
refUrl: "",
|
||||
params: {
|
||||
title: "Llama2-7b-Chat",
|
||||
|
|
@ -184,48 +204,26 @@ const llama2Chat7b: ModelPackage = {
|
|||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
};
|
||||
const llama2Chat13b: ModelPackage = {
|
||||
title: "Llama2-13b-Chat",
|
||||
description: "A 13b parameter model fine-tuned for chat",
|
||||
refUrl: "",
|
||||
params: {
|
||||
title: "Llama2-13b-Chat",
|
||||
model: "llama2:13b-chat",
|
||||
context_length: 2048,
|
||||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
};
|
||||
const llama2Chat34b: ModelPackage = {
|
||||
title: "Llama2-34b-Chat",
|
||||
description: "A 34b parameter model fine-tuned for chat",
|
||||
refUrl: "",
|
||||
params: {
|
||||
title: "Llama2-34b-Chat",
|
||||
model: "llama2:34b-chat",
|
||||
context_length: 2048,
|
||||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
};
|
||||
|
||||
const codeLlamaPackages = [
|
||||
codeLlama7bInstruct,
|
||||
codeLlama13bInstruct,
|
||||
codeLlama34bInstruct,
|
||||
];
|
||||
|
||||
const llama2Packages = [llama2Chat7b, llama2Chat13b, llama2Chat34b];
|
||||
const llama2FamilyPackage = {
|
||||
title: "Llama2 or CodeLlama",
|
||||
description: "Any model using the Llama2 or CodeLlama chat template",
|
||||
params: {
|
||||
model: "llama2",
|
||||
context_length: 2048,
|
||||
template_messages: "llama2_template_messages",
|
||||
},
|
||||
icon: "meta.svg",
|
||||
dimensions: [
|
||||
{
|
||||
name: "Parameter Count",
|
||||
description: "The number of parameters in the model",
|
||||
options: {
|
||||
"7b": {
|
||||
model: "llama2:7b-chat",
|
||||
title: "Llama2-7b-Chat",
|
||||
},
|
||||
"13b": {
|
||||
model: "llama2:13b-chat",
|
||||
title: "Llama2-13b-Chat",
|
||||
},
|
||||
"34b": {
|
||||
model: "llama2:34b-chat",
|
||||
title: "Llama2-34b-Chat",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const gpt4: ModelPackage = {
|
||||
|
|
@ -313,14 +311,14 @@ export const MODEL_INFO: { [key: string]: ModelInfo } = {
|
|||
icon: "ollama.png",
|
||||
tags: [ModelProviderTag["Local"], ModelProviderTag["Open-Source"]],
|
||||
packages: [
|
||||
...codeLlamaPackages.map((p) => ({
|
||||
...p,
|
||||
{
|
||||
...codeLlamaInstruct,
|
||||
refUrl: "https://ollama.ai/library/codellama",
|
||||
})),
|
||||
...llama2Packages.map((p) => ({
|
||||
...p,
|
||||
},
|
||||
{
|
||||
...llama2Chat,
|
||||
refUrl: "https://ollama.ai/library/llama2",
|
||||
})),
|
||||
},
|
||||
],
|
||||
collectInputFor: [...completionParamsInputs],
|
||||
},
|
||||
|
|
@ -349,30 +347,26 @@ export const MODEL_INFO: { [key: string]: ModelInfo } = {
|
|||
...completionParamsInputs,
|
||||
],
|
||||
packages: [
|
||||
...llama2Packages.map((p) => {
|
||||
return {
|
||||
...p,
|
||||
params: {
|
||||
...p.params,
|
||||
model:
|
||||
"togethercomputer/" +
|
||||
p.params.model.replace("llama2", "llama-2").replace(":", "-"),
|
||||
},
|
||||
};
|
||||
updatedObj(llama2Chat, {
|
||||
"dimensions[0].options": (options: any) =>
|
||||
_.mapValues(options, (option) => {
|
||||
return _.assign({}, option, {
|
||||
model: option.model
|
||||
.replace("llama2", "llama-2")
|
||||
.replace(":", "-"),
|
||||
});
|
||||
}),
|
||||
}),
|
||||
...codeLlamaPackages.map((p) => {
|
||||
return {
|
||||
...p,
|
||||
params: {
|
||||
...p.params,
|
||||
model:
|
||||
"togethercomputer/" +
|
||||
p.params.model
|
||||
updatedObj(codeLlamaInstruct, {
|
||||
"dimensions[0].options": (options: any) =>
|
||||
_.mapValues(options, (option) => {
|
||||
return _.assign({}, option, {
|
||||
model: option.model
|
||||
.replace("codellama", "CodeLlama")
|
||||
.replace(":", "-")
|
||||
.replace("instruct", "Instruct"),
|
||||
},
|
||||
};
|
||||
});
|
||||
}),
|
||||
}),
|
||||
].map((p) => {
|
||||
p.params.context_length = 4096;
|
||||
|
|
@ -391,7 +385,7 @@ export const MODEL_INFO: { [key: string]: ModelInfo } = {
|
|||
params: {
|
||||
server_url: "http://localhost:1234",
|
||||
},
|
||||
packages: [llama2FamilyPackage],
|
||||
packages: [codeLlamaInstruct, llama2Chat],
|
||||
collectInputFor: [...completionParamsInputs],
|
||||
},
|
||||
replicate: {
|
||||
|
|
@ -417,7 +411,7 @@ export const MODEL_INFO: { [key: string]: ModelInfo } = {
|
|||
ModelProviderTag["Requires API Key"],
|
||||
ModelProviderTag["Open-Source"],
|
||||
],
|
||||
packages: [...codeLlamaPackages, ...llama2Packages].map((p) => {
|
||||
packages: [codeLlamaInstruct, llama2Chat].map((p) => {
|
||||
return {
|
||||
...p,
|
||||
params: {
|
||||
|
|
@ -447,7 +441,7 @@ export const MODEL_INFO: { [key: string]: ModelInfo } = {
|
|||
After it's up and running, you can start using Continue.`,
|
||||
icon: "llamacpp.png",
|
||||
tags: [ModelProviderTag.Local, ModelProviderTag["Open-Source"]],
|
||||
packages: [llama2FamilyPackage],
|
||||
packages: [codeLlamaInstruct, llama2Chat],
|
||||
collectInputFor: [...completionParamsInputs],
|
||||
},
|
||||
palm: {
|
||||
|
|
@ -489,7 +483,7 @@ After it's up and running, you can start using Continue.`,
|
|||
"HuggingFace Text Generation Inference is an advanced, highly-performant option for serving open-source models to multiple people. To get started, follow the [Quick Tour](https://huggingface.co/docs/text-generation-inference/quicktour) on their website to set up the Docker container. Make sure to enter the server URL below that corresponds to the host and port you set up for the Docker container.",
|
||||
icon: "hf.png",
|
||||
tags: [ModelProviderTag.Local, ModelProviderTag["Open-Source"]],
|
||||
packages: [llama2FamilyPackage],
|
||||
packages: [codeLlamaInstruct, llama2Chat],
|
||||
collectInputFor: [
|
||||
...completionParamsInputs,
|
||||
{ ...serverUrlInput, defaultValue: "http://localhost:8080" },
|
||||
|
|
@ -518,7 +512,7 @@ After it's up and running, you can start using Continue.`,
|
|||
],
|
||||
icon: "openai.svg",
|
||||
tags: [ModelProviderTag.Local, ModelProviderTag["Open-Source"]],
|
||||
packages: [llama2FamilyPackage],
|
||||
packages: [codeLlamaInstruct, llama2Chat],
|
||||
},
|
||||
freetrial: {
|
||||
title: "GPT-4 limited free trial",
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class ConfigPyCodeLensProvider implements vscode.CodeLensProvider {
|
|||
}
|
||||
|
||||
const lineOfSystemMessage = lines.findIndex((line) =>
|
||||
line.includes("system_message=")
|
||||
line.replace(" ", "").includes("config=ContinueConfig(")
|
||||
);
|
||||
|
||||
if (lineOfSystemMessage >= 0) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue