✨ add 'mirostat' to completionOptions
This commit is contained in:
parent
f15470f33d
commit
098fb35dfc
10 changed files with 74 additions and 66 deletions
|
|
@ -134,17 +134,8 @@ declare global {
|
|||
message: string;
|
||||
}
|
||||
|
||||
export interface CompletionOptions {
|
||||
export interface CompletionOptions extends BaseCompletionOptions {
|
||||
model: string;
|
||||
|
||||
maxTokens: number;
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
topK?: number;
|
||||
minP?: number;
|
||||
presencePenalty?: number;
|
||||
frequencyPenalty?: number;
|
||||
stop?: string[];
|
||||
}
|
||||
|
||||
export type ChatMessageRole = "user" | "assistant" | "system";
|
||||
|
|
@ -187,20 +178,11 @@ declare global {
|
|||
|
||||
// LLM
|
||||
|
||||
export interface LLMFullCompletionOptions {
|
||||
export interface LLMFullCompletionOptions extends BaseCompletionOptions {
|
||||
raw?: boolean;
|
||||
log?: boolean;
|
||||
|
||||
model?: string;
|
||||
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
topK?: number;
|
||||
minP?: number;
|
||||
presencePenalty?: number;
|
||||
frequencyPenalty?: number;
|
||||
stop?: string[];
|
||||
maxTokens?: number;
|
||||
}
|
||||
export interface LLMOptions {
|
||||
model: string;
|
||||
|
|
@ -265,12 +247,19 @@ declare global {
|
|||
line: string;
|
||||
}
|
||||
|
||||
export class Problem {
|
||||
filepath: string;
|
||||
range: Range;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface IDE {
|
||||
getSerializedConfig(): Promise<SerializedContinueConfig>;
|
||||
getConfigJsUrl(): Promise<string | undefined>;
|
||||
getDiff(): Promise<string>;
|
||||
getTerminalContents(): Promise<string>;
|
||||
listWorkspaceContents(directory?: string): Promise<string[]>;
|
||||
listFolders(): Promise<string[]>;
|
||||
getWorkspaceDirs(): Promise<string[]>;
|
||||
writeFile(path: string, contents: string): Promise<void>;
|
||||
showVirtualFile(title: string, contents: string): Promise<void>;
|
||||
|
|
@ -293,6 +282,7 @@ declare global {
|
|||
getOpenFiles(): Promise<string[]>;
|
||||
getSearchResults(query: string): Promise<string>;
|
||||
subprocess(command: string): Promise<[string, string]>;
|
||||
getProblems(filepath?: string | undefined): Promise<Problem[]>;
|
||||
|
||||
// Embeddings
|
||||
/**
|
||||
|
|
@ -305,10 +295,9 @@ declare global {
|
|||
tags: string[]
|
||||
): void;
|
||||
retrieveChunks(
|
||||
v: number[],
|
||||
text: string,
|
||||
n: number,
|
||||
tags: string[],
|
||||
providerId: string
|
||||
directory: string | undefined
|
||||
): Promise<Chunk[]>;
|
||||
}
|
||||
|
||||
|
|
@ -320,7 +309,7 @@ declare global {
|
|||
addContextItem: (item: ContextItemWithId) => void;
|
||||
history: ChatMessage[];
|
||||
input: string;
|
||||
params?: any;
|
||||
params?: { [key: string]: any } | undefined;
|
||||
contextItems: ContextItemWithId[];
|
||||
}
|
||||
|
||||
|
|
@ -359,12 +348,15 @@ declare global {
|
|||
| "url"
|
||||
| "tree"
|
||||
| "http"
|
||||
| "codebase";
|
||||
| "codebase"
|
||||
| "problems"
|
||||
| "folder";
|
||||
|
||||
type TemplateType =
|
||||
| "llama2"
|
||||
| "alpaca"
|
||||
| "zephyr"
|
||||
| "phi2"
|
||||
| "phind"
|
||||
| "anthropic"
|
||||
| "chatml"
|
||||
|
|
@ -373,7 +365,7 @@ declare global {
|
|||
| "deepseek"
|
||||
| "xwin-coder"
|
||||
| "neural-chat";
|
||||
|
||||
|
||||
type ModelProvider =
|
||||
| "openai"
|
||||
| "free-trial"
|
||||
|
|
@ -410,6 +402,7 @@ declare global {
|
|||
| "codellama-7b"
|
||||
| "codellama-13b"
|
||||
| "codellama-34b"
|
||||
| "phi2"
|
||||
| "phind-codellama-34b"
|
||||
| "wizardcoder-7b"
|
||||
| "wizardcoder-13b"
|
||||
|
|
@ -468,8 +461,9 @@ declare global {
|
|||
minP?: number;
|
||||
presencePenalty?: number;
|
||||
frequencyPenalty?: number;
|
||||
mirostat?: number;
|
||||
stop?: string[];
|
||||
maxTokens: number;
|
||||
maxTokens?: number;
|
||||
}
|
||||
|
||||
export interface ModelDescription {
|
||||
|
|
@ -556,9 +550,9 @@ declare global {
|
|||
disableSessionTitles?: boolean;
|
||||
disableIndexing?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider?: EmbeddingsProvider;
|
||||
embeddingsProvider: EmbeddingsProvider;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export {};
|
||||
|
|
|
|||
25
core/index.d.ts
vendored
25
core/index.d.ts
vendored
|
|
@ -132,17 +132,8 @@ export interface ContinueError {
|
|||
message: string;
|
||||
}
|
||||
|
||||
export interface CompletionOptions {
|
||||
export interface CompletionOptions extends BaseCompletionOptions {
|
||||
model: string;
|
||||
|
||||
maxTokens: number;
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
topK?: number;
|
||||
minP?: number;
|
||||
presencePenalty?: number;
|
||||
frequencyPenalty?: number;
|
||||
stop?: string[];
|
||||
}
|
||||
|
||||
export type ChatMessageRole = "user" | "assistant" | "system";
|
||||
|
|
@ -185,20 +176,11 @@ export type ChatHistory = ChatHistoryItem[];
|
|||
|
||||
// LLM
|
||||
|
||||
export interface LLMFullCompletionOptions {
|
||||
export interface LLMFullCompletionOptions extends BaseCompletionOptions {
|
||||
raw?: boolean;
|
||||
log?: boolean;
|
||||
|
||||
model?: string;
|
||||
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
topK?: number;
|
||||
minP?: number;
|
||||
presencePenalty?: number;
|
||||
frequencyPenalty?: number;
|
||||
stop?: string[];
|
||||
maxTokens?: number;
|
||||
}
|
||||
export interface LLMOptions {
|
||||
model: string;
|
||||
|
|
@ -477,8 +459,9 @@ interface BaseCompletionOptions {
|
|||
minP?: number;
|
||||
presencePenalty?: number;
|
||||
frequencyPenalty?: number;
|
||||
mirostat?: number;
|
||||
stop?: string[];
|
||||
maxTokens: number;
|
||||
maxTokens?: number;
|
||||
}
|
||||
|
||||
export interface ModelDescription {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
const DEFAULT_MAX_TOKENS = 1000;
|
||||
const DEFAULT_MAX_TOKENS = 1024;
|
||||
const DEFAULT_CONTEXT_LENGTH = 4096;
|
||||
const DEFAULT_TEMPERATURE = 0.5;
|
||||
|
||||
const DEFAULT_ARGS = {
|
||||
max_tokens: DEFAULT_MAX_TOKENS,
|
||||
temperature: 0.5,
|
||||
maxTokens: DEFAULT_MAX_TOKENS,
|
||||
temperature: DEFAULT_TEMPERATURE,
|
||||
};
|
||||
|
||||
const CONTEXT_LENGTH_FOR_MODEL: { [name: string]: number } = {
|
||||
|
|
@ -22,6 +25,7 @@ const PROXY_URL = "http://localhost:65433";
|
|||
export {
|
||||
CONTEXT_LENGTH_FOR_MODEL,
|
||||
DEFAULT_ARGS,
|
||||
DEFAULT_CONTEXT_LENGTH,
|
||||
DEFAULT_MAX_TOKENS,
|
||||
PROXY_URL,
|
||||
TOKEN_BUFFER_FOR_SAFETY,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@ import {
|
|||
TemplateType,
|
||||
} from "..";
|
||||
import { ideRequest, ideStreamRequest } from "../ide/messaging";
|
||||
import { CONTEXT_LENGTH_FOR_MODEL, DEFAULT_ARGS } from "./constants";
|
||||
import {
|
||||
CONTEXT_LENGTH_FOR_MODEL,
|
||||
DEFAULT_ARGS,
|
||||
DEFAULT_CONTEXT_LENGTH,
|
||||
DEFAULT_MAX_TOKENS,
|
||||
} from "./constants";
|
||||
import {
|
||||
compileChatMessages,
|
||||
countTokens,
|
||||
|
|
@ -35,13 +40,13 @@ import {
|
|||
codellamaEditPrompt,
|
||||
deepseekEditPrompt,
|
||||
mistralEditPrompt,
|
||||
neuralChatEditPrompt,
|
||||
openchatEditPrompt,
|
||||
phindEditPrompt,
|
||||
simplestEditPrompt,
|
||||
simplifiedEditPrompt,
|
||||
xWinCoderEditPrompt,
|
||||
zephyrEditPrompt,
|
||||
neuralChatEditPrompt,
|
||||
} from "./templates/edit";
|
||||
|
||||
const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [
|
||||
|
|
@ -240,11 +245,11 @@ export abstract class BaseLLM implements ILLM {
|
|||
this.uniqueId = options.uniqueId || "None";
|
||||
this.model = options.model;
|
||||
this.systemMessage = options.systemMessage;
|
||||
this.contextLength = options.contextLength || 4096;
|
||||
this.contextLength = options.contextLength || DEFAULT_CONTEXT_LENGTH;
|
||||
this.completionOptions = {
|
||||
...options.completionOptions,
|
||||
model: options.model || "gpt-4",
|
||||
maxTokens: options.completionOptions?.maxTokens || 1024,
|
||||
maxTokens: options.completionOptions?.maxTokens || DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
this.requestOptions = options.requestOptions;
|
||||
this.promptTemplates = {
|
||||
|
|
@ -283,14 +288,15 @@ export abstract class BaseLLM implements ILLM {
|
|||
options.model !== this.model &&
|
||||
options.model in CONTEXT_LENGTH_FOR_MODEL
|
||||
) {
|
||||
contextLength = CONTEXT_LENGTH_FOR_MODEL[options.model] || 4096;
|
||||
contextLength =
|
||||
CONTEXT_LENGTH_FOR_MODEL[options.model] || DEFAULT_CONTEXT_LENGTH;
|
||||
}
|
||||
|
||||
return compileChatMessages(
|
||||
options.model,
|
||||
messages,
|
||||
contextLength,
|
||||
options.maxTokens,
|
||||
options.maxTokens || DEFAULT_MAX_TOKENS,
|
||||
undefined,
|
||||
functions,
|
||||
this.systemMessage
|
||||
|
|
@ -421,7 +427,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
completionOptions.model,
|
||||
this.contextLength,
|
||||
prompt,
|
||||
completionOptions.maxTokens
|
||||
completionOptions.maxTokens || DEFAULT_MAX_TOKENS
|
||||
);
|
||||
|
||||
if (!raw) {
|
||||
|
|
@ -466,7 +472,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
completionOptions.model,
|
||||
this.contextLength,
|
||||
prompt,
|
||||
completionOptions.maxTokens
|
||||
completionOptions.maxTokens || DEFAULT_MAX_TOKENS
|
||||
);
|
||||
|
||||
if (!raw) {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,23 @@ class FreeTrial extends BaseLLM {
|
|||
};
|
||||
}
|
||||
|
||||
private _convertArgs(options: CompletionOptions): any {
|
||||
return {
|
||||
model: options.model,
|
||||
frequency_penalty: options.frequencyPenalty,
|
||||
presence_penalty: options.presencePenalty,
|
||||
max_tokens: options.maxTokens,
|
||||
stop: options.stop,
|
||||
temperature: options.temperature,
|
||||
top_p: options.topP,
|
||||
};
|
||||
}
|
||||
|
||||
protected async *_streamComplete(
|
||||
prompt: string,
|
||||
options: CompletionOptions
|
||||
): AsyncGenerator<string> {
|
||||
const args = this.collectArgs(options);
|
||||
const args = this._convertArgs(this.collectArgs(options));
|
||||
|
||||
const response = await this.fetch(`${SERVER_URL}/stream_complete`, {
|
||||
method: "POST",
|
||||
|
|
@ -39,7 +51,7 @@ class FreeTrial extends BaseLLM {
|
|||
messages: ChatMessage[],
|
||||
options: CompletionOptions
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const args = this.collectArgs(options);
|
||||
const args = this._convertArgs(this.collectArgs(options));
|
||||
|
||||
const response = await this.fetch(`${SERVER_URL}/stream_chat`, {
|
||||
method: "POST",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class LlamaCpp extends BaseLLM {
|
|||
frequency_penalty: options.frequencyPenalty,
|
||||
presence_penalty: options.presencePenalty,
|
||||
min_p: options.minP,
|
||||
mirostat: options.mirostat,
|
||||
};
|
||||
|
||||
return finalOptions;
|
||||
|
|
@ -25,7 +26,7 @@ class LlamaCpp extends BaseLLM {
|
|||
): AsyncGenerator<string> {
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${this.apiKey}`,
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
...this.requestOptions?.headers,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ class Ollama extends BaseLLM {
|
|||
num_predict: options.maxTokens,
|
||||
stop: options.stop,
|
||||
num_ctx: this.contextLength,
|
||||
mirostat: options.mirostat,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
LLMOptions,
|
||||
ModelDescription,
|
||||
} from "../..";
|
||||
import { DEFAULT_MAX_TOKENS } from "../constants";
|
||||
import Anthropic from "./Anthropic";
|
||||
import Bedrock from "./Bedrock";
|
||||
import DeepInfra from "./DeepInfra";
|
||||
|
|
@ -125,7 +126,7 @@ export async function llmFromDescription(
|
|||
maxTokens:
|
||||
finalCompletionOptions.maxTokens ||
|
||||
cls.defaultOptions?.completionOptions?.maxTokens ||
|
||||
1024,
|
||||
DEFAULT_MAX_TOKENS,
|
||||
},
|
||||
systemMessage,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@
|
|||
"description": "The frequency penalty of the completion.",
|
||||
"type": "number"
|
||||
},
|
||||
"mirostat": {
|
||||
"title": "Mirostat",
|
||||
"description": "Enable Mirostat sampling, controlling perplexity during text generation (default: 0, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0). Only available for Ollama, LM Studio, and llama.cpp providers",
|
||||
"type": "number"
|
||||
},
|
||||
"stop": {
|
||||
"title": "Stop",
|
||||
"description": "The stop tokens of the completion.",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { DEFAULT_MAX_TOKENS } from "core/llm/constants";
|
||||
import { RootStore } from "../store";
|
||||
|
||||
export const defaultModelSelector = (state: RootStore) => {
|
||||
|
|
@ -6,5 +7,5 @@ export const defaultModelSelector = (state: RootStore) => {
|
|||
};
|
||||
|
||||
export const contextLengthSelector = (state: RootStore) => {
|
||||
return defaultModelSelector(state)?.contextLength || 4096;
|
||||
return defaultModelSelector(state)?.contextLength || DEFAULT_MAX_TOKENS;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue