🐛 fix config loading

This commit is contained in:
Nate Sesti 2023-12-09 18:10:57 -08:00
parent c61aebd3d4
commit ca0fc2a11f
8 changed files with 32 additions and 14 deletions

View file

@ -14,7 +14,9 @@ function loadSerializedConfig(
): ContinueConfig {
const models: LLM[] = [];
for (const desc of initial.models) {
models.push(llmFromDescription(desc, initial.completionOptions));
const llm = llmFromDescription(desc, initial.completionOptions);
if (!llm) continue;
models.push(llm);
}
const slashCommands: SlashCommand[] = [];
@ -31,6 +33,10 @@ function loadSerializedConfig(
const contextProviders: ContextProvider[] = [];
for (const provider of initial.contextProviders || []) {
const cls = contextProviderClassFromName(provider.name) as any;
if (!cls) {
console.warn(`Unknown context provider ${provider.name}`);
continue;
}
contextProviders.push(new cls(provider.params));
}

View file

@ -18,11 +18,11 @@ const Providers: (typeof ContextProvider)[] = [
export function contextProviderClassFromName(
name: ContextProviderName
): typeof ContextProvider {
): typeof ContextProvider | undefined {
const cls = Providers.find((cls) => cls.description.title === name);
if (!cls) {
throw new Error(`Unknown provider ${name}`);
return undefined;
}
return cls;

View file

@ -110,14 +110,16 @@ function pruneChatHistory(
}, 0);
// 0. Prune any messages that take up more than 1/3 of the context length
const longestMessages = chatHistory.toSorted(
(a, b) => b.content.length - a.content.length
);
const longestMessages = [...chatHistory];
longestMessages.sort((a, b) => b.content.length - a.content.length);
const longerThanOneThird = longestMessages.filter(
(message) => countTokens(message.content, modelName) > contextLength / 3
(message: ChatMessage) =>
countTokens(message.content, modelName) > contextLength / 3
);
const distanceFromThird = longerThanOneThird.map(
(message) => countTokens(message.content, modelName) - contextLength / 3
(message: ChatMessage) =>
countTokens(message.content, modelName) - contextLength / 3
);
for (let i = 0; i < longerThanOneThird.length; i++) {

View file

@ -33,11 +33,11 @@ const LLMs = [
export function llmFromDescription(
desc: ModelDescription,
completionOptions?: BaseCompletionOptions
): LLM {
): LLM | undefined {
const cls = LLMs.find((llm) => llm.providerName === desc.provider);
if (!cls) {
throw new Error(`Unknown provider ${desc.provider}`);
return undefined;
}
const finalCompletionOptions = {

View file

@ -189,6 +189,9 @@ const MainTextInput = styled.textarea<{
${(props) =>
props.inQueryForDynamicProvider ? buttonColor : "transparent"};
outline: 0.5px solid
${(props) => (props.inQueryForDynamicProvider ? buttonColor : lightGray)};
&:focus {
outline: 0.5px solid
${(props) => (props.inQueryForDynamicProvider ? buttonColor : lightGray)};

View file

@ -25,6 +25,7 @@ function useContextProviders() {
const provider = contextProviderClassFromName(
name as ContextProviderName
);
if (!provider) continue;
providersList.push((provider as any)(options));
descriptionsList.push(provider.description);
}

View file

@ -5,8 +5,11 @@ import { postToIde } from "../util/ide";
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";
import {
addHighlightedCode,
setConfig,
setInactive,
} from "../redux/slices/stateSlice";
function useSetup(dispatch: Dispatch<any>) {
// Load config from the IDE

View file

@ -1,4 +1,5 @@
import { createSlice } from "@reduxjs/toolkit";
import { SerializedContinueConfig } from "core/config";
import defaultConfig from "core/config/default";
import { loadSerializedConfig } from "core/config/load";
import { ChatMessage, ContextItem, ContextItemId } from "core/llm/types";
@ -94,10 +95,11 @@ export const stateSlice = createSlice({
name: "state",
initialState,
reducers: {
setConfig: (state, action) => {
setConfig: (state, { payload }: { payload: SerializedContinueConfig }) => {
const config = loadSerializedConfig(payload);
return {
...state,
config: action.payload,
config,
};
},
addContextItemsAtIndex: (state, action) => {
@ -363,5 +365,6 @@ export const {
addHighlightedCode,
setEditingAtIds,
setDefaultModel,
setConfig,
} = stateSlice.actions;
export default stateSlice.reducer;