🚧 load unserialized config
This commit is contained in:
parent
7edfd3d651
commit
9dff6f8859
27 changed files with 360 additions and 216 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import { CustomCommand } from "../config";
|
||||
import { CustomCommand, SlashCommandDescription } from "../config";
|
||||
import { IDE } from "../ide/types";
|
||||
import { LLM } from "../llm";
|
||||
import { ChatMessage, ContextItem } from "../llm/types";
|
||||
|
||||
import SlashCommands from "./slash";
|
||||
export interface ContinueSDK {
|
||||
ide: IDE;
|
||||
llm: LLM;
|
||||
|
|
@ -44,3 +44,7 @@ export function slashFromCustomCommand(
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function slashCommandFromDescription(desc: SlashCommandDescription) {
|
||||
return SlashCommands.find((cmd) => cmd.name === desc.name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { SlashCommand } from ".";
|
||||
import { removeQuotesAndEscapes } from "../util";
|
||||
import { SlashCommand } from "..";
|
||||
import { removeQuotesAndEscapes } from "../../util";
|
||||
|
||||
`
|
||||
cmd = await sdk.models.default.complete(
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { ContinueSDK, SlashCommand } from ".";
|
||||
import { ChatMessage } from "../llm/types";
|
||||
import { removeQuotesAndEscapes } from "../util";
|
||||
import { SlashCommand } from "..";
|
||||
import { ChatMessage } from "../../llm/types";
|
||||
import { removeQuotesAndEscapes } from "../../util";
|
||||
|
||||
const PROMPT = (
|
||||
input: string,
|
||||
11
core/commands/slash/index.ts
Normal file
11
core/commands/slash/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import GenerateTerminalCommand from "./cmd";
|
||||
import DraftIssueCommand from "./draftIssue";
|
||||
import ShareSlashCommand from "./share";
|
||||
import StackOverflowSlashCommand from "./stackOverflow";
|
||||
|
||||
export default [
|
||||
DraftIssueCommand,
|
||||
ShareSlashCommand,
|
||||
StackOverflowSlashCommand,
|
||||
GenerateTerminalCommand,
|
||||
];
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { SlashCommand } from ".";
|
||||
import { SlashCommand } from "..";
|
||||
|
||||
const ShareSlashCommand: SlashCommand = {
|
||||
name: "share",
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { SlashCommand } from ".";
|
||||
import { pruneStringFromBottom } from "../llm/countTokens";
|
||||
import { ChatMessageRole } from "../llm/types";
|
||||
import { SlashCommand } from "..";
|
||||
import { pruneStringFromBottom } from "../../llm/countTokens";
|
||||
import { ChatMessageRole } from "../../llm/types";
|
||||
|
||||
const SERVER_URL = "https://proxy-server-l6vsfbzhba-uw.a.run.app";
|
||||
const PROMPT = (
|
||||
43
core/config/index.d.ts
vendored
43
core/config/index.d.ts
vendored
|
|
@ -4,6 +4,10 @@ These are the types for the JSON config file, config.json.
|
|||
|
||||
**/
|
||||
|
||||
import { SlashCommand } from "../commands/index";
|
||||
import { ContextProvider } from "../context";
|
||||
import { LLM } from "../llm";
|
||||
|
||||
type StepName =
|
||||
| "AnswerQuestionChroma"
|
||||
| "GenerateShellCommandStep"
|
||||
|
|
@ -69,7 +73,7 @@ interface ContextProviderWithParams {
|
|||
params: { [key: string]: any };
|
||||
}
|
||||
|
||||
interface SlashCommand {
|
||||
interface SlashCommandDescription {
|
||||
name: string;
|
||||
description: string;
|
||||
step: StepName | string;
|
||||
|
|
@ -131,23 +135,38 @@ interface SerializedContinueConfig {
|
|||
modelRoles: ModelRoles;
|
||||
systemMessage?: string;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
slashCommands?: SlashCommand[];
|
||||
slashCommands?: SlashCommandDescription[];
|
||||
customCommands?: CustomCommand[];
|
||||
contextProviders?: ContextProviderWithParams[];
|
||||
retrievalSettings?: RetrievalSettings;
|
||||
disableIndexing?: boolean;
|
||||
}
|
||||
|
||||
interface ContinueConfig {
|
||||
allowAnonymousTelemetry?: boolean;
|
||||
models: LLM[];
|
||||
systemMessage?: string;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
slashCommands?: SlashCommand[];
|
||||
contextProviders?: ContextProvider[];
|
||||
retrievalSettings?: RetrievalSettings;
|
||||
disableIndexing?: boolean;
|
||||
}
|
||||
|
||||
export {
|
||||
StepName,
|
||||
ContextProviderName,
|
||||
TemplateType,
|
||||
ModelProvider,
|
||||
RequestOptions,
|
||||
StepWithParams,
|
||||
ContextProviderWithParams,
|
||||
SlashCommand,
|
||||
CustomCommand,
|
||||
RetrievalSettings,
|
||||
BaseCompletionOptions,
|
||||
ContextProviderName,
|
||||
ContextProviderWithParams,
|
||||
ContinueConfig,
|
||||
CustomCommand,
|
||||
ModelDescription,
|
||||
ModelProvider,
|
||||
ModelRoles,
|
||||
RequestOptions,
|
||||
RetrievalSettings,
|
||||
SerializedContinueConfig,
|
||||
SlashCommandDescription,
|
||||
StepName,
|
||||
StepWithParams,
|
||||
TemplateType,
|
||||
};
|
||||
|
|
|
|||
51
core/config/load.ts
Normal file
51
core/config/load.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { ContinueConfig, SerializedContinueConfig } from ".";
|
||||
import {
|
||||
SlashCommand,
|
||||
slashCommandFromDescription,
|
||||
slashFromCustomCommand,
|
||||
} from "../commands";
|
||||
import { ContextProvider } from "../context";
|
||||
import { contextProviderClassFromName } from "../context/providers";
|
||||
import { LLM } from "../llm";
|
||||
import { llmFromDescription } from "../llm/llms";
|
||||
|
||||
function loadSerializedConfig(
|
||||
initial: SerializedContinueConfig
|
||||
): ContinueConfig {
|
||||
const models: LLM[] = [];
|
||||
for (const desc of initial.models) {
|
||||
models.push(llmFromDescription(desc, initial.completionOptions));
|
||||
}
|
||||
|
||||
const slashCommands: SlashCommand[] = [];
|
||||
for (const command of initial.slashCommands || []) {
|
||||
const newCommand = slashCommandFromDescription(command);
|
||||
if (newCommand) {
|
||||
slashCommands.push(newCommand);
|
||||
}
|
||||
}
|
||||
for (const command of initial.customCommands || []) {
|
||||
slashCommands.push(slashFromCustomCommand(command));
|
||||
}
|
||||
|
||||
const contextProviders: ContextProvider[] = [];
|
||||
for (const provider of initial.contextProviders || []) {
|
||||
const cls = contextProviderClassFromName(provider.name) as any;
|
||||
contextProviders.push(new cls(provider.params));
|
||||
}
|
||||
|
||||
const config: ContinueConfig = {
|
||||
allowAnonymousTelemetry: initial.allowAnonymousTelemetry,
|
||||
models,
|
||||
systemMessage: initial.systemMessage,
|
||||
completionOptions: initial.completionOptions,
|
||||
slashCommands,
|
||||
contextProviders,
|
||||
retrievalSettings: initial.retrievalSettings,
|
||||
disableIndexing: initial.disableIndexing,
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export { loadSerializedConfig };
|
||||
|
|
@ -1,19 +1,29 @@
|
|||
import { ContextProvider } from "..";
|
||||
import { ContextProviderName } from "../../config";
|
||||
import DiffContextProvider from "./DiffContextProvider";
|
||||
import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider";
|
||||
import TerminalContextProvider from "./TerminalContextProvider";
|
||||
// import OpenTabsContextProvider from "./OpenTabsContextProvider";
|
||||
import GoogleContextProvider from "./GoogleContextProvider";
|
||||
// import SearchContextProvider from "./SearchContextProvider";
|
||||
import URLContextProvider from "./URLContextProvider";
|
||||
import FileTreeContextProvider from "./FileTreeContextProvider";
|
||||
import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider";
|
||||
import GoogleContextProvider from "./GoogleContextProvider";
|
||||
import TerminalContextProvider from "./TerminalContextProvider";
|
||||
import URLContextProvider from "./URLContextProvider";
|
||||
|
||||
export default {
|
||||
diff: DiffContextProvider,
|
||||
github: GitHubIssuesContextProvider,
|
||||
terminal: TerminalContextProvider,
|
||||
// open: OpenTabsContextProvider, TODO
|
||||
google: GoogleContextProvider,
|
||||
// search: SearchContextProvider, TODO
|
||||
url: URLContextProvider,
|
||||
tree: FileTreeContextProvider,
|
||||
};
|
||||
const Providers: (typeof ContextProvider)[] = [
|
||||
DiffContextProvider,
|
||||
FileTreeContextProvider,
|
||||
GitHubIssuesContextProvider,
|
||||
GoogleContextProvider,
|
||||
TerminalContextProvider,
|
||||
URLContextProvider,
|
||||
];
|
||||
|
||||
export function contextProviderClassFromName(
|
||||
name: ContextProviderName
|
||||
): typeof ContextProvider {
|
||||
const cls = Providers.find((cls) => cls.description.title === name);
|
||||
|
||||
if (!cls) {
|
||||
throw new Error(`Unknown provider ${name}`);
|
||||
}
|
||||
|
||||
return cls;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import {
|
|||
simplestEditPrompt,
|
||||
zephyrEditPrompt,
|
||||
} from "./templates/edit";
|
||||
import { CompletionOptions, ChatMessage } from "./types";
|
||||
import { ChatMessage, CompletionOptions } from "./types";
|
||||
|
||||
function autodetectTemplateType(model: string): TemplateType | undefined {
|
||||
const lower = model.toLowerCase();
|
||||
|
|
@ -153,7 +153,7 @@ interface LLMFullCompletionOptions {
|
|||
|
||||
export abstract class LLM implements LLMOptions {
|
||||
static providerName: ModelProvider;
|
||||
static defaultOptions: Partial<LLMOptions>;
|
||||
static defaultOptions: Partial<LLMOptions> | undefined;
|
||||
|
||||
get providerName(): ModelProvider {
|
||||
return (this.constructor as typeof LLM).providerName;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { ChatMessage, CompletionOptions } from "../types";
|
|||
class GooglePalm extends LLM {
|
||||
static providerName: ModelProvider = "google-palm";
|
||||
|
||||
static defaultOptions: LLMOptions = {
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
model: "chat-bison-001",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
|
||||
import { LLMOptions } from "..";
|
||||
import { ModelProvider } from "../../config";
|
||||
import { ChatMessage } from "../types";
|
||||
import OpenAI from "./OpenAI";
|
||||
|
||||
class LMStudio extends OpenAI {
|
||||
static providerName: ModelProvider = "lmstudio";
|
||||
static defaultOptions = {
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
apiBase: "http://localhost:1234/v1",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
import { LLM, LLMOptions } from "..";
|
||||
import { BaseCompletionOptions, ModelDescription } from "../../config";
|
||||
import Anthropic from "./Anthropic";
|
||||
import FreeTrial from "./FreeTrial";
|
||||
import GooglePalm from "./GooglePalm";
|
||||
import HuggingFaceInferenceAPI from "./HuggingFaceInferenceAPI";
|
||||
import HuggingFaceTGI from "./HuggingFaceTGI";
|
||||
import LMStudio from "./LMStudio";
|
||||
import LlamaCpp from "./LlamaCpp";
|
||||
import Llamafile from "./Llamafile";
|
||||
import Ollama from "./Ollama";
|
||||
import OpenAI from "./OpenAI";
|
||||
import Replicate from "./Replicate";
|
||||
import TextGenWebUI from "./TextGenWebUI";
|
||||
import Together from "./Together";
|
||||
import HuggingFaceTGI from "./HuggingFaceTGI";
|
||||
import HuggingFaceInferenceAPI from "./HuggingFaceInferenceAPI";
|
||||
import LlamaCpp from "./LlamaCpp";
|
||||
import OpenAI from "./OpenAI";
|
||||
import LMStudio from "./LMStudio";
|
||||
|
||||
export {
|
||||
const LLMs = [
|
||||
Anthropic,
|
||||
FreeTrial,
|
||||
GooglePalm,
|
||||
|
|
@ -26,4 +28,34 @@ export {
|
|||
LlamaCpp,
|
||||
OpenAI,
|
||||
LMStudio,
|
||||
};
|
||||
];
|
||||
|
||||
export function llmFromDescription(
|
||||
desc: ModelDescription,
|
||||
completionOptions?: BaseCompletionOptions
|
||||
): LLM {
|
||||
const cls = LLMs.find((llm) => llm.providerName === desc.provider);
|
||||
|
||||
if (!cls) {
|
||||
throw new Error(`Unknown provider ${desc.provider}`);
|
||||
}
|
||||
|
||||
const finalCompletionOptions = {
|
||||
...completionOptions,
|
||||
...desc.completionOptions,
|
||||
};
|
||||
|
||||
const options: LLMOptions = {
|
||||
...desc,
|
||||
completionOptions: {
|
||||
...finalCompletionOptions,
|
||||
model: desc.model || cls.defaultOptions?.model || "codellama-7b", // TODO: Fix up all the ?'s
|
||||
maxTokens:
|
||||
finalCompletionOptions.maxTokens ||
|
||||
cls.defaultOptions?.completionOptions?.maxTokens ||
|
||||
1024,
|
||||
},
|
||||
};
|
||||
|
||||
return new cls(options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import {
|
|||
} from "..";
|
||||
import useContextProviders from "../../hooks/useContextProviders";
|
||||
import useHistory from "../../hooks/useHistory";
|
||||
import { contextLengthSelector } from "../../redux/selectors/configSelectors";
|
||||
import { contextLengthSelector } from "../../redux/selectors/modelSelectors";
|
||||
import { setTakenActionTrue } from "../../redux/slices/miscSlice";
|
||||
import {
|
||||
addContextItems,
|
||||
|
|
@ -337,7 +337,7 @@ const Li = styled.li<{
|
|||
background-color: ${({ highlighted }) =>
|
||||
highlighted ? buttonColor + "66" : "transparent"};
|
||||
${({ selected }) => selected && "font-weight: bold;"}
|
||||
padding: 0.5rem 0.5rem;
|
||||
padding: 0.5rem 0.25rem;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
|
@ -416,16 +416,15 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
any | undefined
|
||||
>(undefined);
|
||||
|
||||
const availableSlashCommands = [];
|
||||
// useSelector(
|
||||
// (state: RootStore) =>
|
||||
// state.serverState.slashCommands?.map((cmd) => {
|
||||
// return {
|
||||
// name: `/${cmd.name}`,
|
||||
// description: cmd.description,
|
||||
// };
|
||||
// }) || []
|
||||
// );
|
||||
const availableSlashCommands = useSelector(
|
||||
(state: RootStore) =>
|
||||
state.state.config.slashCommands?.map((cmd) => {
|
||||
return {
|
||||
name: `/${cmd.name}`,
|
||||
description: cmd.description,
|
||||
};
|
||||
}) || []
|
||||
);
|
||||
const selectedContextItems = useSelector((state: RootStore) => {
|
||||
if (typeof props.index !== "undefined") {
|
||||
return state.state.history[props.index].contextItems;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
vscBackground,
|
||||
vscForeground,
|
||||
} from "..";
|
||||
import { defaultModelSelector } from "../../redux/selectors/configSelectors";
|
||||
import { defaultModelSelector } from "../../redux/selectors/modelSelectors";
|
||||
import { RootStore } from "../../redux/store";
|
||||
import { getMetaKeyLabel } from "../../util";
|
||||
import HeaderButtonWithText from "../HeaderButtonWithText";
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
import posthog from "posthog-js";
|
||||
import { PostHogProvider } from "posthog-js/react";
|
||||
import { PropsWithChildren, useEffect } from "react";
|
||||
import { RootStore } from "../redux/store";
|
||||
import React, { PropsWithChildren, useEffect } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import React from "react";
|
||||
import { RootStore } from "../redux/store";
|
||||
|
||||
const CustomPostHogProvider = ({ children }: PropsWithChildren) => {
|
||||
const allowAnonymousTelemetry = useSelector(
|
||||
(store: RootStore) => store?.serverState?.config?.allow_anonymous_telemetry
|
||||
(store: RootStore) => store?.serverState?.config.allowAnonymousTelemetry
|
||||
);
|
||||
|
||||
const [client, setClient] = React.useState<any>(undefined);
|
||||
|
|
|
|||
96
gui/src/hooks/useChatHandler.ts
Normal file
96
gui/src/hooks/useChatHandler.ts
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
|
||||
import { SlashCommand } from "core/commands";
|
||||
import { ExtensionIde } from "core/ide";
|
||||
import { ChatMessage } from "core/llm/types";
|
||||
import { useSelector } from "react-redux";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import {
|
||||
addContextItems,
|
||||
setInactive,
|
||||
streamUpdate,
|
||||
} from "../redux/slices/stateSlice";
|
||||
import { RootStore } from "../redux/store";
|
||||
|
||||
function useChatHandler(dispatch: Dispatch) {
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
const slashCommands = useSelector(
|
||||
(store: RootStore) => store.state.config.slashCommands || []
|
||||
);
|
||||
|
||||
const active = useSelector((store: RootStore) => store.state.active);
|
||||
|
||||
function getSlashCommandForInput(
|
||||
input: string
|
||||
): [SlashCommand, string] | undefined {
|
||||
let slashCommand: SlashCommand | undefined;
|
||||
let slashCommandName: string | undefined;
|
||||
if (input.startsWith("/")) {
|
||||
slashCommandName = input.split(" ")[0].substring(1);
|
||||
slashCommand = slashCommands.find(
|
||||
(command) => command.name === slashCommandName
|
||||
);
|
||||
}
|
||||
if (!slashCommand || !slashCommandName) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Convert to actual slash command object with runnable function
|
||||
return [slashCommand, input];
|
||||
}
|
||||
|
||||
async function _streamNormalInput(messages: ChatMessage[]) {
|
||||
for await (const update of defaultModel.streamChat(messages)) {
|
||||
if (!active) {
|
||||
break;
|
||||
}
|
||||
dispatch(streamUpdate(update.content));
|
||||
}
|
||||
}
|
||||
|
||||
async function _streamSlashCommand(
|
||||
messages: ChatMessage[],
|
||||
slashCommand: SlashCommand,
|
||||
input: string
|
||||
) {
|
||||
const sdk = {
|
||||
input,
|
||||
history: messages,
|
||||
ide: new ExtensionIde(),
|
||||
llm: defaultModel,
|
||||
addContextItem: (item) => {
|
||||
dispatch(addContextItems([item]));
|
||||
},
|
||||
options: {}, // TODO: pass options to slash command
|
||||
};
|
||||
|
||||
for await (const update of slashCommand.run(sdk)) {
|
||||
if (!active) {
|
||||
break;
|
||||
}
|
||||
dispatch(streamUpdate(update));
|
||||
}
|
||||
}
|
||||
|
||||
async function streamResponse(messages: ChatMessage[]) {
|
||||
if (messages.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine if the input is a slash command
|
||||
const input = messages[-1].content;
|
||||
let [slashCommand, commandInput] = getSlashCommandForInput(input);
|
||||
|
||||
if (slashCommand) {
|
||||
await _streamSlashCommand(messages, slashCommand, commandInput);
|
||||
} else {
|
||||
await _streamNormalInput(messages);
|
||||
}
|
||||
dispatch(setInactive());
|
||||
}
|
||||
|
||||
return { streamResponse };
|
||||
}
|
||||
|
||||
export default useChatHandler;
|
||||
|
|
@ -1,22 +1,10 @@
|
|||
import { ContextProviderName } from "core/config";
|
||||
import { ContextProvider, ContextProviderDescription } from "core/context";
|
||||
import { contextProviderClassFromName } from "core/context/providers";
|
||||
import { ContextItem } from "core/llm/types";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootStore } from "../redux/store";
|
||||
import { ContextProviderName } from "core/config";
|
||||
import { ContextProvider, ContextProviderDescription } from "core/context";
|
||||
import Providers from "core/context/providers";
|
||||
import { ContextItem } from "core/llm/types";
|
||||
|
||||
function providerNameToProvider(
|
||||
name: ContextProviderName
|
||||
): typeof ContextProvider {
|
||||
const cls = Providers[name];
|
||||
|
||||
if (!cls) {
|
||||
throw new Error(`Unknown provider ${name}`);
|
||||
}
|
||||
|
||||
return cls;
|
||||
}
|
||||
|
||||
function useContextProviders() {
|
||||
const [providers, setProviders] = useState<{
|
||||
|
|
@ -34,7 +22,9 @@ function useContextProviders() {
|
|||
let providersList = [];
|
||||
let descriptionsList = [];
|
||||
for (const [name, options] of Object.entries(providerConfig)) {
|
||||
const provider = providerNameToProvider(name as ContextProviderName);
|
||||
const provider = contextProviderClassFromName(
|
||||
name as ContextProviderName
|
||||
);
|
||||
providersList.push((provider as any)(options));
|
||||
descriptionsList.push(provider.description);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootStore } from "../redux/store";
|
||||
import {
|
||||
FreeTrial,
|
||||
Anthropic,
|
||||
GooglePalm,
|
||||
LMStudio,
|
||||
Llamafile,
|
||||
Ollama,
|
||||
Replicate,
|
||||
TextGenWebUI,
|
||||
Together,
|
||||
HuggingFaceTGI,
|
||||
HuggingFaceInferenceAPI,
|
||||
LlamaCpp,
|
||||
OpenAI,
|
||||
} from "core/llm/llms";
|
||||
import { ModelDescription } from "core/config";
|
||||
import { LLM } from "core/llm";
|
||||
|
||||
function modelDescriptionToLLM(desc: ModelDescription): LLM {
|
||||
let cls: typeof LLM;
|
||||
const providerClasses = {
|
||||
"openai-free-trial": FreeTrial,
|
||||
anthropic: Anthropic,
|
||||
"google-palm": GooglePalm,
|
||||
lmstudio: LMStudio,
|
||||
llamafile: Llamafile,
|
||||
ollama: Ollama,
|
||||
replicate: Replicate,
|
||||
"text-gen-webui": TextGenWebUI,
|
||||
together: Together,
|
||||
"huggingface-tgi": HuggingFaceTGI,
|
||||
"huggingface-inference-api": HuggingFaceInferenceAPI,
|
||||
"llama.cpp": LlamaCpp,
|
||||
"openai-aiohttp": OpenAI,
|
||||
openai: OpenAI,
|
||||
};
|
||||
|
||||
cls = providerClasses[desc.provider];
|
||||
|
||||
if (!cls) {
|
||||
throw new Error(`Unknown provider ${desc.provider}`);
|
||||
}
|
||||
|
||||
return new (cls as any)({ ...desc, uniqueId: "None" });
|
||||
}
|
||||
|
||||
function useModels() {
|
||||
const [defaultModel, setDefaultModel] = useState<LLM>(
|
||||
new FreeTrial({ uniqueId: "None", model: "gpt-3.5-turbo" })
|
||||
);
|
||||
const models = useSelector(
|
||||
(store: RootStore) => store.state.config?.models || []
|
||||
);
|
||||
const defaultTitle = useSelector(
|
||||
(store: RootStore) => store.state.config.modelRoles.default
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const model = models.find((model) => model.title === defaultTitle);
|
||||
if (model) {
|
||||
setDefaultModel(modelDescriptionToLLM(model));
|
||||
}
|
||||
}, [models, defaultTitle]);
|
||||
|
||||
return { defaultModel };
|
||||
}
|
||||
|
||||
export default useModels;
|
||||
|
|
@ -3,8 +3,8 @@ import { useEffect } from "react";
|
|||
import { setServerStatusMessage } from "../redux/slices/miscSlice";
|
||||
import { postToIde } from "../util/ide";
|
||||
|
||||
import { setVscMachineId } from "../redux/slices/configSlice";
|
||||
import { ExtensionIde } from "core/ide/index";
|
||||
import { setVscMachineId } from "../redux/slices/configSlice";
|
||||
import { setConfig } from "../redux/slices/serverStateReducer";
|
||||
import { addHighlightedCode, setInactive } from "../redux/slices/stateSlice";
|
||||
|
||||
|
|
|
|||
|
|
@ -29,14 +29,13 @@ import ErrorStepContainer from "../components/gui/ErrorStepContainer";
|
|||
import StepContainer from "../components/gui/StepContainer";
|
||||
import TimelineItem from "../components/gui/TimelineItem";
|
||||
import ComboBox from "../components/mainInput/ComboBox";
|
||||
import useChatHandler from "../hooks/useChatHandler";
|
||||
import useHistory from "../hooks/useHistory";
|
||||
import useModels from "../hooks/useModels";
|
||||
import { setTakenActionTrue } from "../redux/slices/miscSlice";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import {
|
||||
newSession,
|
||||
resubmitAtIndex,
|
||||
setInactive,
|
||||
streamUpdate,
|
||||
submitMessage,
|
||||
} from "../redux/slices/stateSlice";
|
||||
import {
|
||||
|
|
@ -129,9 +128,8 @@ function GUI(props: GUIProps) {
|
|||
|
||||
// #region Selectors
|
||||
const sessionState = useSelector((state: RootStore) => state.state);
|
||||
const workspacePaths = (window as any).workspacePaths || [];
|
||||
|
||||
const { defaultModel } = useModels();
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
const sessionTitle = useSelector((state: RootStore) => state.state.title);
|
||||
const active = useSelector((state: RootStore) => state.state.active);
|
||||
|
|
@ -162,7 +160,6 @@ function GUI(props: GUIProps) {
|
|||
const bottomMessage = useSelector(
|
||||
(state: RootStore) => state.uiState.bottomMessage
|
||||
);
|
||||
const takenAction = useSelector((state: RootStore) => state.misc.takenAction);
|
||||
useEffect(() => {
|
||||
if (!aboveComboBoxDivRef.current) return;
|
||||
dispatch(
|
||||
|
|
@ -231,6 +228,8 @@ function GUI(props: GUIProps) {
|
|||
|
||||
// #endregion
|
||||
|
||||
const { streamResponse } = useChatHandler(dispatch);
|
||||
|
||||
const sendInput = useCallback(
|
||||
(input: string) => {
|
||||
if (
|
||||
|
|
@ -265,13 +264,7 @@ function GUI(props: GUIProps) {
|
|||
|
||||
const messages = constructMessages([...state.history, historyItem]);
|
||||
dispatch(submitMessage(message));
|
||||
|
||||
(async () => {
|
||||
for await (const update of defaultModel.streamChat(messages)) {
|
||||
dispatch(streamUpdate(update.content));
|
||||
}
|
||||
dispatch(setInactive());
|
||||
})();
|
||||
streamResponse(messages);
|
||||
|
||||
// Increment localstorage counter for popup
|
||||
const counter = localStorage.getItem("mainTextEntryCounter");
|
||||
|
|
@ -347,7 +340,13 @@ function GUI(props: GUIProps) {
|
|||
localStorage.setItem("mainTextEntryCounter", "1");
|
||||
}
|
||||
},
|
||||
[sessionState.history, sessionState.contextItems, defaultModel, state]
|
||||
[
|
||||
sessionState.history,
|
||||
sessionState.contextItems,
|
||||
defaultModel,
|
||||
state,
|
||||
streamResponse,
|
||||
]
|
||||
);
|
||||
|
||||
const { saveSession } = useHistory();
|
||||
|
|
@ -377,8 +376,6 @@ function GUI(props: GUIProps) {
|
|||
}, [sendInput]);
|
||||
|
||||
const onMainTextInput = (event?: any) => {
|
||||
console.log("onMainTextInput");
|
||||
dispatch(setTakenActionTrue(null));
|
||||
if (mainTextInputRef.current) {
|
||||
let input = (mainTextInputRef.current as any).inputValue;
|
||||
|
||||
|
|
|
|||
|
|
@ -129,8 +129,8 @@ function Settings() {
|
|||
useEffect(() => {
|
||||
if (!config) return;
|
||||
|
||||
formMethods.setValue("system_message", config.system_message);
|
||||
formMethods.setValue("temperature", config.completion_options?.temperature);
|
||||
formMethods.setValue("system_message", config.systemMessage);
|
||||
formMethods.setValue("temperature", config.completionOptions?.temperature);
|
||||
}, [config]);
|
||||
|
||||
return (
|
||||
|
|
@ -202,7 +202,7 @@ function Settings() {
|
|||
<div className="text-center" style={{ marginTop: "-25px" }}>
|
||||
<p className="text-sm text-gray-500">
|
||||
{(formMethods.watch("temperature") as number | undefined) ||
|
||||
config.completion_options?.temperature ||
|
||||
config.completionOptions?.temperature ||
|
||||
"-"}
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
import { RootStore } from "../store";
|
||||
|
||||
export const contextLengthSelector = (state: RootStore) => {
|
||||
return (
|
||||
{
|
||||
"gpt-4": 8096,
|
||||
"gpt-3.5-turbo": 4096,
|
||||
"gpt-3.5-turbo-16k": 16384,
|
||||
"gpt-4-32k": 32768,
|
||||
"claude-2": 16384,
|
||||
}[state.serverState.config.model_roles?.default] || 4096
|
||||
);
|
||||
};
|
||||
|
||||
export const defaultModelSelector = (state: RootStore) => {
|
||||
const title = state.serverState.config.model_roles?.default;
|
||||
if (!Array.isArray(state.serverState.config.models)) return;
|
||||
return state.serverState.config.models?.find(
|
||||
(model) => model.title === title
|
||||
);
|
||||
};
|
||||
10
gui/src/redux/selectors/modelSelectors.ts
Normal file
10
gui/src/redux/selectors/modelSelectors.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { RootStore } from "../store";
|
||||
|
||||
export const defaultModelSelector = (state: RootStore) => {
|
||||
const title = state.state.defaultModelTitle;
|
||||
return state.serverState.config.models.find((model) => model.title === title);
|
||||
};
|
||||
|
||||
export const contextLengthSelector = (state: RootStore) => {
|
||||
return defaultModelSelector(state)?.contextLength || 4096;
|
||||
};
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { SerializedContinueConfig } from "core/config";
|
||||
import { loadSerializedConfig } from "core/config/load";
|
||||
import FreeTrial from "core/llm/llms/FreeTrial";
|
||||
import { RootStore } from "../store";
|
||||
|
||||
const TEST_SLASH_COMMANDS = [
|
||||
|
|
@ -21,8 +24,10 @@ const initialState: RootStore["serverState"] = {
|
|||
slashCommands: [],
|
||||
selectedContextItems: [],
|
||||
config: {
|
||||
system_message: "",
|
||||
temperature: 0.5,
|
||||
models: [
|
||||
new FreeTrial({ model: "gpt-4" }),
|
||||
new FreeTrial({ model: "gpt-3.5-turbo" }),
|
||||
],
|
||||
},
|
||||
contextProviders: [],
|
||||
savedContextGroups: [],
|
||||
|
|
@ -49,10 +54,11 @@ export const serverStateSlice = createSlice({
|
|||
contextProviders: action.payload,
|
||||
};
|
||||
},
|
||||
setConfig: (state, action) => {
|
||||
setConfig: (state, { payload }: { payload: SerializedContinueConfig }) => {
|
||||
const config = loadSerializedConfig(payload);
|
||||
return {
|
||||
...state,
|
||||
config: action.payload,
|
||||
config,
|
||||
};
|
||||
},
|
||||
setIndexingProgress: (state, { payload }: { payload: number }) => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { RootStore } from "../store";
|
||||
import { ContextItem, ContextItemId } from "core/llm/types";
|
||||
import defaultConfig from "core/config/default";
|
||||
import { v4 } from "uuid";
|
||||
import { loadSerializedConfig } from "core/config/load";
|
||||
import { ContextItem, ContextItemId } from "core/llm/types";
|
||||
import { PersistedSessionInfo } from "core/types";
|
||||
import { v4 } from "uuid";
|
||||
import { RootStore } from "../store";
|
||||
|
||||
const TEST_CONTEXT_ITEMS: ContextItem[] = [
|
||||
{
|
||||
|
|
@ -83,9 +84,10 @@ const initialState: RootStore["state"] = {
|
|||
history: [],
|
||||
contextItems: [],
|
||||
active: false,
|
||||
config: defaultConfig,
|
||||
config: loadSerializedConfig(defaultConfig),
|
||||
title: "New Session",
|
||||
sessionId: v4(),
|
||||
defaultModelTitle: "GPT-4",
|
||||
};
|
||||
|
||||
export const stateSlice = createSlice({
|
||||
|
|
@ -324,6 +326,16 @@ export const stateSlice = createSlice({
|
|||
};
|
||||
}
|
||||
},
|
||||
setDefaultModel: (state, action) => {
|
||||
const model = state.config.models.find(
|
||||
(model) => model.title === action.payload
|
||||
);
|
||||
if (!model) return;
|
||||
return {
|
||||
...state,
|
||||
defaultModelTitle: action.payload,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -339,5 +351,6 @@ export const {
|
|||
resubmitAtIndex,
|
||||
addHighlightedCode,
|
||||
setEditingAtIds,
|
||||
setDefaultModel,
|
||||
} = stateSlice.actions;
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
import { combineReducers, configureStore } from "@reduxjs/toolkit";
|
||||
import configReducer from "./slices/configSlice";
|
||||
import miscReducer from "./slices/miscSlice";
|
||||
import uiStateReducer from "./slices/uiStateSlice";
|
||||
import serverStateReducer from "./slices/serverStateReducer";
|
||||
import stateReducer from "./slices/stateSlice";
|
||||
import { ContinueConfig } from "../schema/ContinueConfig";
|
||||
import { ContextItem } from "core/llm/types";
|
||||
import { ContextProviderDescription } from "../schema/ContextProviderDescription";
|
||||
import { SlashCommandDescription } from "../schema/SlashCommandDescription";
|
||||
import configReducer from "./slices/configSlice";
|
||||
import miscReducer from "./slices/miscSlice";
|
||||
import serverStateReducer from "./slices/serverStateReducer";
|
||||
import stateReducer from "./slices/stateSlice";
|
||||
import uiStateReducer from "./slices/uiStateSlice";
|
||||
|
||||
import storage from "redux-persist/lib/storage";
|
||||
import { persistReducer, persistStore, createTransform } from "redux-persist";
|
||||
import { ContinueConfig } from "core/config";
|
||||
import { ChatHistory } from "core/llm/types";
|
||||
import { SerializedContinueConfig } from "core/config";
|
||||
import { createTransform } from "redux-persist";
|
||||
import storage from "redux-persist/lib/storage";
|
||||
|
||||
export interface ChatMessage {
|
||||
role: "system" | "user" | "assistant";
|
||||
|
|
@ -24,9 +23,10 @@ export interface RootStore {
|
|||
history: ChatHistory;
|
||||
contextItems: ContextItem[];
|
||||
active: boolean;
|
||||
config: SerializedContinueConfig;
|
||||
config: ContinueConfig;
|
||||
title: string;
|
||||
sessionId: string;
|
||||
defaultModelTitle: string;
|
||||
};
|
||||
|
||||
config: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue