Elffuss BraidHub

kikocis/continue public

e8ee99375f3e · 5.4 KiBRawPermalink
1import { z } from "zod";
2
3export const clientCertificateOptionsSchema = z.object({
4 cert: z.string(),
5 key: z.string(),
6 passphrase: z.string().optional(),
7});
8export type ClientCertificateOptions = z.infer<
9 typeof clientCertificateOptionsSchema
10>;
11
12export const requestOptionsSchema = z.object({
13 timeout: z.number().optional(),
14 verifySsl: z.boolean().optional(),
15 caBundlePath: z.union([z.string(), z.array(z.string())]).optional(),
16 proxy: z.string().optional(),
17 headers: z.record(z.string()).optional(),
18 extraBodyProperties: z.record(z.any()).optional(),
19 noProxy: z.array(z.string()).optional(),
20 clientCertificate: clientCertificateOptionsSchema.optional(),
21});
22export type RequestOptions = z.infer<typeof requestOptionsSchema>;
23export const modelRolesSchema = z.enum([
24 "chat",
25 "autocomplete",
26 "embed",
27 "rerank",
28 "edit",
29 "apply",
30 "summarize",
31]);
32export type ModelRole = z.infer<typeof modelRolesSchema>;
33
34// TODO consider just using array of strings for model capabilities
35// To allow more dynamic string parsing
36export const modelCapabilitySchema = z.union([
37 z.literal("tool_use"),
38 z.literal("image_input"),
39]);
40export type ModelCapability = z.infer<typeof modelCapabilitySchema>;
41
42export const completionOptionsSchema = z.object({
43 contextLength: z.number().optional(),
44 maxTokens: z.number().optional(),
45 temperature: z.number().optional(),
46 topP: z.number().optional(),
47 topK: z.number().optional(),
48 minP: z.number().optional(),
49 presencePenalty: z.number().optional(),
50 frequencyPenalty: z.number().optional(),
51 stop: z.array(z.string()).optional(),
52 n: z.number().optional(),
53 reasoning: z.boolean().optional(),
54 reasoningBudgetTokens: z.number().optional(),
55 promptCaching: z.boolean().optional(),
56 stream: z.boolean().optional(),
57});
58export type CompletionOptions = z.infer<typeof completionOptionsSchema>;
59
60export const embeddingTasksSchema = z.union([
61 z.literal("chunk"),
62 z.literal("query"),
63]);
64export type EmbeddingTasks = z.infer<typeof embeddingTasksSchema>;
65
66export const embeddingPrefixesSchema = z.record(
67 embeddingTasksSchema,
68 z.string(),
69);
70export type EmbeddingPrefixes = z.infer<typeof embeddingPrefixesSchema>;
71
72export const cacheBehaviorSchema = z.object({
73 cacheSystemMessage: z.boolean().optional(),
74 cacheConversation: z.boolean().optional(),
75});
76export type CacheBehavior = z.infer<typeof cacheBehaviorSchema>;
77
78export const embedOptionsSchema = z.object({
79 maxChunkSize: z.number().optional(),
80 maxBatchSize: z.number().optional(),
81 embeddingPrefixes: embeddingPrefixesSchema.optional(),
82});
83export type EmbedOptions = z.infer<typeof embedOptionsSchema>;
84
85export const chatOptionsSchema = z.object({
86 baseSystemMessage: z.string().optional(),
87 baseAgentSystemMessage: z.string().optional(),
88 basePlanSystemMessage: z.string().optional(),
89});
90export type ChatOptions = z.infer<typeof chatOptionsSchema>;
91
92const templateSchema = z.enum([
93 "llama2",
94 "alpaca",
95 "zephyr",
96 "phi2",
97 "phind",
98 "anthropic",
99 "chatml",
100 "none",
101 "openchat",
102 "deepseek",
103 "xwin-coder",
104 "neural-chat",
105 "codellama-70b",
106 "llava",
107 "gemma",
108 "granite",
109 "llama3",
110 "codestral",
111]);
112
113export const autocompleteOptionsSchema = z.object({
114 disable: z.boolean().optional(),
115 maxPromptTokens: z.number().optional(),
116 debounceDelay: z.number().optional(),
117 modelTimeout: z.number().optional(),
118 maxSuffixPercentage: z.number().optional(),
119 prefixPercentage: z.number().optional(),
120 template: z.string().optional(),
121 onlyMyCode: z.boolean().optional(),
122});
123
124/** Prompt templates use Handlebars syntax */
125const promptTemplatesSchema = z.object({
126 apply: z.string().optional(),
127 chat: templateSchema.optional(),
128 edit: z.string().optional(),
129 autocomplete: z.string().optional(),
130});
131export type PromptTemplates = z.infer<typeof promptTemplatesSchema>;
132
133const baseModelFields = {
134 name: z.string(),
135 model: z.string(),
136 apiKey: z.string().optional(),
137 apiBase: z.string().optional(),
138 maxStopWords: z.number().optional(),
139 roles: modelRolesSchema.array().optional(),
140 capabilities: modelCapabilitySchema.array().optional(),
141 defaultCompletionOptions: completionOptionsSchema.optional(),
142 cacheBehavior: cacheBehaviorSchema.optional(),
143 requestOptions: requestOptionsSchema.optional(),
144 embedOptions: embedOptionsSchema.optional(),
145 chatOptions: chatOptionsSchema.optional(),
146 promptTemplates: promptTemplatesSchema.optional(),
147 useLegacyCompletionsEndpoint: z.boolean().optional(),
148 env: z
149 .record(z.string(), z.union([z.string(), z.boolean(), z.number()]))
150 .optional(),
151 autocompleteOptions: autocompleteOptionsSchema.optional(),
152};
153
154export const modelSchema = z.union([
155 z.object({
156 ...baseModelFields,
157 provider: z.literal("continue-proxy"),
158 apiKeyLocation: z.string().optional(),
159 envSecretLocations: z.record(z.string(), z.string()).optional(),
160 orgScopeId: z.string().nullable(),
161 onPremProxyUrl: z.string().nullable(),
162 }),
163 z.object({
164 ...baseModelFields,
165 provider: z.string().refine((val) => val !== "continue-proxy"),
166 }),
167]);
168
169export const partialModelSchema = z.union([
170 z
171 .object({
172 ...baseModelFields,
173 provider: z.literal("continue-proxy"),
174 apiKeyLocation: z.string().optional(),
175 envSecretLocations: z.record(z.string(), z.string()).optional(),
176 })
177 .partial(),
178 z
179 .object({
180 ...baseModelFields,
181 provider: z.string().refine((val) => val !== "continue-proxy"),
182 })
183 .partial(),
184]);
185
186export type ModelConfig = z.infer<typeof modelSchema>;