feat: simplify typings

This commit is contained in:
Patrick Erichsen 2025-04-09 14:15:04 -07:00
parent 30ecadbdb8
commit c6fa6d78a7
4 changed files with 29 additions and 46 deletions

46
core/index.d.ts vendored
View file

@ -77,39 +77,19 @@ export type PromptTemplateFunction = (
export type PromptTemplate = string | PromptTemplateFunction;
export interface ILLM extends LLMOptions {
type RequiredLLMOptions =
| "uniqueId"
| "contextLength"
| "embeddingId"
| "maxEmbeddingChunkSize"
| "maxEmbeddingBatchSize"
| "completionOptions";
export interface ILLM
extends Omit<LLMOptions, RequiredLLMOptions>,
Required<Pick<LLMOptions, RequiredLLMOptions>> {
get providerName(): string;
uniqueId: string;
model: string;
title?: string;
systemMessage?: string;
contextLength: number;
maxStopWords?: number;
completionOptions: CompletionOptions;
requestOptions?: RequestOptions;
promptTemplates?: Record<string, PromptTemplate>;
templateMessages?: (messages: ChatMessage[]) => string;
llmLogger?: ILLMLogger;
llmRequestHook?: (model: string, prompt: string) => any;
apiKey?: string;
apiBase?: string;
cacheBehavior?: CacheBehavior;
capabilities?: ModelCapability;
roles?: ModelRole[];
deployment?: string;
apiVersion?: string;
apiType?: string;
region?: string;
projectId?: string;
// Embedding options
embeddingId: string;
maxEmbeddingChunkSize: number;
maxEmbeddingBatchSize: number;
complete(
prompt: string,
signal: AbortSignal,
@ -580,6 +560,7 @@ export interface LLMOptions {
title?: string;
uniqueId?: string;
systemMessage?: string;
baseSystem?: string;
contextLength?: number;
maxStopWords?: number;
completionOptions?: CompletionOptions;
@ -611,6 +592,9 @@ export interface LLMOptions {
maxEmbeddingChunkSize?: number;
maxEmbeddingBatchSize?: number;
// Chat options
baseChatSystemMessage?: string;
// Cloudflare options
accountId?: string;

View file

@ -33,7 +33,6 @@ import { isOllamaInstalled } from "../util/ollamaHelper.js";
import { Telemetry } from "../util/posthog.js";
import { withExponentialBackoff } from "../util/withExponentialBackoff.js";
import { serializePromptTemplates } from "../config/util.js";
import {
autodetectPromptTemplates,
autodetectTemplateFunction,
@ -127,7 +126,7 @@ export abstract class BaseLLM implements ILLM {
model: string;
title?: string;
_systemMessage?: string;
systemMessage?: string;
contextLength: number;
maxStopWords?: number | undefined;
completionOptions: CompletionOptions;
@ -195,7 +194,7 @@ export abstract class BaseLLM implements ILLM {
this.title = options.title;
this.uniqueId = options.uniqueId ?? "None";
this._systemMessage = options.systemMessage;
this.baseSystemMessage = options.baseSystemMessage;
this.contextLength =
options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH;
this.maxStopWords = options.maxStopWords ?? this.maxStopWords;
@ -267,11 +266,6 @@ export abstract class BaseLLM implements ILLM {
this.embeddingId = `${this.constructor.name}::${this.model}::${this.maxEmbeddingChunkSize}`;
}
get systemMessage() {
const serializedTemplates = serializePromptTemplates(this.promptTemplates);
return serializedTemplates?.baseSystemPrompt ?? this._systemMessage;
}
getConfigurationStatus() {
return LLMConfigurationStatuses.VALID;
}
@ -311,7 +305,7 @@ export abstract class BaseLLM implements ILLM {
supportsImages: this.supportsImages(),
prompt: undefined,
functions,
systemMessage: this.systemMessage,
baseSystemMessage: this.baseSystemMessage,
rules: this.rules ?? [],
});
}
@ -323,9 +317,9 @@ export abstract class BaseLLM implements ILLM {
const msgs: ChatMessage[] = [{ role: "user", content: prompt }];
const systemMessage = this.systemMessage;
if (systemMessage) {
msgs.unshift({ role: "system", content: systemMessage });
const baseSystemMessage = this.baseSystemMessage;
if (baseSystemMessage) {
msgs.unshift({ role: "system", content: baseSystemMessage });
}
return this.templateMessages(msgs);

View file

@ -147,7 +147,7 @@ The `models` section defines the language models used in your configuration. Mod
- `capabilities`: Array of strings denoting model capabilities, which will overwrite Continue's autodetection based on provider and model. Supported capabilities include `tool_use` and `image_input`.
- `promptTemplates`: Can be used to override the default prompt templates for different model roles. Valid values are [`edit`](./customize/model-roles/edit.mdx#prompt-templating) and [`apply`](./customize/model-roles/apply.mdx#prompt-templating).
- `chatOptions`: If the model includes role `chat`, these settings apply for Chat and Agent mode:
- `baseSystemPrompt`: Can be used to override the default system prompt.
- `baseSystemMessage`: Can be used to override the default system prompt.
- `embedOptions`: If the model includes role `embed`, these settings apply for embeddings:
- `maxChunkSize`: Maximum tokens per document chunk. Minimum is 128 tokens.
- `maxBatchSize`: Maximum number of chunks per request. Minimum is 1 chunk.

View file

@ -56,12 +56,16 @@ export const embedOptionsSchema = z.object({
});
export type EmbedOptions = z.infer<typeof embedOptionsSchema>;
export const chatOptionsSchema = z.object({
baseSystemMessage: z.string().optional(),
});
export type ChatOptions = z.infer<typeof chatOptionsSchema>;
/** Prompt templates use Handlebars syntax */
const promptTemplatesSchema = z.object({
apply: z.string().optional(),
edit: z.string().optional(),
baseSystemPrompt: z.string().optional(),
} as const);
});
export type PromptTemplates = z.infer<typeof promptTemplatesSchema>;
const baseModelFields = {
@ -74,6 +78,7 @@ const baseModelFields = {
defaultCompletionOptions: completionOptionsSchema.optional(),
requestOptions: requestOptionsSchema.optional(),
embedOptions: embedOptionsSchema.optional(),
chatOptions: chatOptionsSchema.optional(),
promptTemplates: promptTemplatesSchema.optional(),
env: z
.record(z.string(), z.union([z.string(), z.boolean(), z.number()]))