Skip to content

Commit ac68bec

Browse files
committed
maxStopWords option
1 parent d8eb189 commit ac68bec

File tree

10 files changed

+39
-12
lines changed

10 files changed

+39
-12
lines changed

core/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface ILLM extends LLMOptions {
5858
title?: string;
5959
systemMessage?: string;
6060
contextLength: number;
61+
maxStopWords?: number;
6162
completionOptions: CompletionOptions;
6263
requestOptions?: RequestOptions;
6364
promptTemplates?: Record<string, PromptTemplate>;
@@ -321,6 +322,7 @@ export interface LLMOptions {
321322
uniqueId?: string;
322323
systemMessage?: string;
323324
contextLength?: number;
325+
maxStopWords?: number;
324326
completionOptions?: CompletionOptions;
325327
requestOptions?: RequestOptions;
326328
template?: TemplateType;
@@ -747,6 +749,7 @@ export interface ModelDescription {
747749
apiKey?: string;
748750
apiBase?: string;
749751
contextLength?: number;
752+
maxStopWords?: number;
750753
template?: TemplateType;
751754
completionOptions?: BaseCompletionOptions;
752755
systemMessage?: string;

core/llm/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export abstract class BaseLLM implements ILLM {
9191
title?: string;
9292
systemMessage?: string;
9393
contextLength: number;
94+
maxStopWords?: number | undefined;
9495
completionOptions: CompletionOptions;
9596
requestOptions?: RequestOptions;
9697
template?: TemplateType;
@@ -143,6 +144,7 @@ export abstract class BaseLLM implements ILLM {
143144
this.systemMessage = options.systemMessage;
144145
this.contextLength =
145146
options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH;
147+
this.maxStopWords = options.maxStopWords ?? this.maxStopWords;
146148
this.completionOptions = {
147149
...options.completionOptions,
148150
model: options.model || "gpt-4",

core/llm/llms/Deepseek.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Deepseek extends OpenAI {
1313
},
1414
useLegacyCompletionsEndpoint: false,
1515
};
16-
protected maxStopWords: number | undefined = 16;
16+
maxStopWords: number | undefined = 16;
1717

1818
supportsFim(): boolean {
1919
return true;

core/llm/llms/Groq.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Groq extends OpenAI {
66
static defaultOptions: Partial<LLMOptions> = {
77
apiBase: "https://api.groq.com/openai/v1/",
88
};
9-
protected maxStopWords: number | undefined = 4;
9+
maxStopWords: number | undefined = 4;
1010

1111
private static modelConversion: { [key: string]: string } = {
1212
"llama2-70b": "llama2-70b-4096",

core/llm/llms/OpenAI.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const CHAT_ONLY_MODELS = [
4242
class OpenAI extends BaseLLM {
4343
public useLegacyCompletionsEndpoint: boolean | undefined = undefined;
4444

45-
protected maxStopWords: number | undefined = undefined;
45+
maxStopWords: number | undefined = undefined;
4646

4747
constructor(options: LLMOptions) {
4848
super(options);
@@ -104,13 +104,13 @@ class OpenAI extends BaseLLM {
104104
this.maxStopWords !== undefined
105105
? options.stop?.slice(0, this.maxStopWords)
106106
: url.host === "api.deepseek.com"
107-
? options.stop?.slice(0, 16)
108-
: url.port === "1337" ||
109-
url.host === "api.openai.com" ||
110-
url.host === "api.groq.com" ||
111-
this.apiType === "azure"
112-
? options.stop?.slice(0, 4)
113-
: options.stop,
107+
? options.stop?.slice(0, 16)
108+
: url.port === "1337" ||
109+
url.host === "api.openai.com" ||
110+
url.host === "api.groq.com" ||
111+
this.apiType === "azure"
112+
? options.stop?.slice(0, 4)
113+
: options.stop,
114114
};
115115

116116
return finalOptions;

core/llm/llms/WatsonX.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const watsonxConfig = {
1313
},
1414
};
1515
class WatsonX extends BaseLLM {
16-
protected maxStopWords: number | undefined = undefined;
16+
maxStopWords: number | undefined = undefined;
1717

1818
constructor(options: LLMOptions) {
1919
super(options);
@@ -176,7 +176,9 @@ class WatsonX extends BaseLLM {
176176
throw new Error(`Something went wrong. Check your credentials, please.`);
177177
}
178178

179-
const stopToken = this.watsonxStopToken ?? (options.model.includes("granite") ? "<|im_end|>" : undefined);
179+
const stopToken =
180+
this.watsonxStopToken ??
181+
(options.model.includes("granite") ? "<|im_end|>" : undefined);
180182
var streamResponse = await fetch(
181183
`${this.watsonxUrl}/ml/v1/text/generation_stream?version=2023-05-29`,
182184
{

docs/static/schemas/config.json

+5
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@
239239
"default": 2048,
240240
"type": "integer"
241241
},
242+
"maxStopWords": {
243+
"title": "Max Stop Words",
244+
"description": "The maximum number of stop words that the API will accept. You can set this if you are receiving an error about the number of stop words, but otherwise should leave it undefined.",
245+
"type": "integer"
246+
},
242247
"template": {
243248
"title": "Template",
244249
"description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here. Choose none if you are using vLLM or another server that automatically handles prompting.",

extensions/intellij/src/main/resources/config_schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@
239239
"default": 2048,
240240
"type": "integer"
241241
},
242+
"maxStopWords": {
243+
"title": "Max Stop Words",
244+
"description": "The maximum number of stop words that the API will accept. You can set this if you are receiving an error about the number of stop words, but otherwise should leave it undefined.",
245+
"type": "integer"
246+
},
242247
"template": {
243248
"title": "Template",
244249
"description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here. Choose none if you are using vLLM or another server that automatically handles prompting.",

extensions/vscode/config_schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@
239239
"default": 2048,
240240
"type": "integer"
241241
},
242+
"maxStopWords": {
243+
"title": "Max Stop Words",
244+
"description": "The maximum number of stop words that the API will accept. You can set this if you are receiving an error about the number of stop words, but otherwise should leave it undefined.",
245+
"type": "integer"
246+
},
242247
"template": {
243248
"title": "Template",
244249
"description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here. Choose none if you are using vLLM or another server that automatically handles prompting.",

extensions/vscode/continue_rc_schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@
242242
"default": 2048,
243243
"type": "integer"
244244
},
245+
"maxStopWords": {
246+
"title": "Max Stop Words",
247+
"description": "The maximum number of stop words that the API will accept. You can set this if you are receiving an error about the number of stop words, but otherwise should leave it undefined.",
248+
"type": "integer"
249+
},
245250
"template": {
246251
"title": "Template",
247252
"description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here. Choose none if you are using vLLM or another server that automatically handles prompting.",

0 commit comments

Comments
 (0)