Elffuss BraidHub

kikocis/continue public

main · 2.1 KiBRawPermalink
1import { ConfigYaml, configYamlSchema } from "./schemas/index.js";
2
3export interface ConfigValidationError {
4 fatal: boolean;
5 message: string;
6}
7
8export interface ConfigResult<T> {
9 config: T | undefined;
10 errors: ConfigValidationError[] | undefined;
11 configLoadInterrupted: boolean;
12}
13
14export function validateConfigYaml(
15 config: ConfigYaml,
16): ConfigValidationError[] {
17 const errors: ConfigValidationError[] = [];
18
19 try {
20 configYamlSchema.parse(config);
21 } catch (e: any) {
22 return [
23 {
24 fatal: true,
25 message: e.message,
26 },
27 ];
28 }
29
30 config.models?.forEach((model) => {
31 if ("uses" in model) {
32 return;
33 }
34 // Max tokens not too close to context length
35 if (
36 model.defaultCompletionOptions?.contextLength &&
37 model.defaultCompletionOptions?.maxTokens
38 ) {
39 const difference =
40 model.defaultCompletionOptions?.contextLength -
41 model.defaultCompletionOptions?.maxTokens;
42
43 if (difference < 1000) {
44 errors.push({
45 fatal: false,
46 message: `Model "${model.name}" has a contextLength of ${model.defaultCompletionOptions?.contextLength} and a maxTokens of ${model.defaultCompletionOptions?.maxTokens}. This leaves only ${difference} tokens for input context and will likely result in your inputs being truncated.`,
47 });
48 }
49 }
50
51 if (model.roles?.includes("autocomplete")) {
52 const modelName = model.model.toLocaleLowerCase();
53 const nonAutocompleteModels = [
54 // "gpt",
55 // "claude",
56 "mistral",
57 "instruct",
58 ];
59
60 if (
61 nonAutocompleteModels.some((m) => modelName.includes(m)) &&
62 !modelName.includes("deepseek") &&
63 !modelName.includes("codestral") &&
64 !modelName.toLowerCase().includes("coder")
65 ) {
66 errors.push({
67 fatal: false,
68 message: `${model.model} is not trained for tab-autocomplete, and will result in low-quality suggestions. See the docs to learn more about why: https://docs.continue.dev/features/tab-autocomplete#i-want-better-completions-should-i-use-gpt-4`,
69 });
70 }
71 }
72 });
73
74 return errors;
75}