From 105afeccca903072bc48772bdaf8f100f996c4a7 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 6 Oct 2023 12:18:48 -0700 Subject: [PATCH] feat: :sparkles: select model param count from UI --- extension/react-app/package-lock.json | 1 + extension/react-app/package.json | 1 + .../react-app/src/components/ModelCard.tsx | 179 +++++++++++----- extension/react-app/src/pages/modelconfig.tsx | 13 +- extension/react-app/src/util/modelData.ts | 200 +++++++++--------- extension/src/lang-server/codeLens.ts | 2 +- 6 files changed, 241 insertions(+), 155 deletions(-) diff --git a/extension/react-app/package-lock.json b/extension/react-app/package-lock.json index fb68081cc..a52396efd 100644 --- a/extension/react-app/package-lock.json +++ b/extension/react-app/package-lock.json @@ -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", diff --git a/extension/react-app/package.json b/extension/react-app/package.json index b9f70645f..be23b34b7 100644 --- a/extension/react-app/package.json +++ b/extension/react-app/package.json @@ -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", diff --git a/extension/react-app/src/components/ModelCard.tsx b/extension/react-app/src/components/ModelCard.tsx index d1cb31656..dfaa0bfab 100644 --- a/extension/react-app/src/components/ModelCard.tsx +++ b/extension/react-app/src/components/ModelCard.tsx @@ -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) => void; + onClick: ( + e: React.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( + props.dimensions?.map((d) => Object.keys(d.options)[0]) || [] + ); + + const [hovered, setHovered] = useState(false); + return (
props.onClick(e)} + hovered={hovered} > -
- {vscMediaUrl && props.icon && ( - - )} -

{props.title}

-
- {props.tags?.map((tag) => { - return ( - - {tag} - - ); - })} -

{props.description}

+
setHovered(true)} + onMouseLeave={() => setHovered(false)} + className="px-2 py-1" + onClick={ + props.disabled ? undefined : (e) => props.onClick(e, dimensionChoices) + } + > +
+ {vscMediaUrl && props.icon && ( + + )} +

{props.title}

+
+ {props.tags?.map((tag) => { + return ( + + {tag} + + ); + })} +

{props.description}

- {props.refUrl && ( - - - - - + {props.refUrl && ( + + + + + + )} +
+ + {props.dimensions?.length && ( + + {props.dimensions?.map((dimension, i) => { + return ( +
+ +

{dimension.name}

+ {Object.keys(dimension.options).map((key) => { + return ( + { + e.stopPropagation(); + const newChoices = [...dimensionChoices]; + newChoices[i] = key; + setDimensionChoices(newChoices); + }} + selected={dimensionChoices[i] === key} + > + {key} + + ); + })} +
+ ); + })} +
)}
); diff --git a/extension/react-app/src/pages/modelconfig.tsx b/extension/react-app/src/pages/modelconfig.tsx index b6be4fa27..00d9d9bfc 100644 --- a/extension/react-app/src/pages/modelconfig.tsx +++ b/extension/react-app/src/pages/modelconfig.tsx @@ -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("/"); diff --git a/extension/react-app/src/util/modelData.ts b/extension/react-app/src/util/modelData.ts index ade56611c..7b40b6b0d 100644 --- a/extension/react-app/src/util/modelData.ts +++ b/extension/react-app/src/util/modelData.ts @@ -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", diff --git a/extension/src/lang-server/codeLens.ts b/extension/src/lang-server/codeLens.ts index 6cd9f38cb..6f36a6bd0 100644 --- a/extension/src/lang-server/codeLens.ts +++ b/extension/src/lang-server/codeLens.ts @@ -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) {