Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 11ce1c2

Browse files
development -> main (#316)
* Fix LMStudio and Oobabooga max_tokens in request body (#311) OpenAI-like API expect 'max_tokens' parameter * Add FIM template for Codestral-22B (#312) * started adding codestral * final additions for codestral * 3.16.5 --------- Co-authored-by: AndrewRocky <79256277+AndrewRocky@users.noreply.github.com>
1 parent 391985f commit 11ce1c2

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "twinny",
33
"displayName": "twinny - AI Code Completion and Chat",
44
"description": "Locally hosted AI code completion plugin for vscode",
5-
"version": "3.16.4",
5+
"version": "3.16.5",
66
"icon": "assets/icon.png",
77
"keywords": [
88
"code-inference",

src/common/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const FIM_TEMPLATE_FORMAT = {
195195
codegemma: 'codegemma',
196196
codellama: 'codellama',
197197
codeqwen: 'codeqwen',
198+
codestral: 'codestral',
198199
custom: 'custom-template',
199200
deepseek: 'deepseek',
200201
llama: 'llama',
@@ -216,6 +217,8 @@ export const STOP_STARCODER = ['<|endoftext|>', '<file_sep>']
216217

217218
export const STOP_CODEGEMMA = ['<|file_separator|>', '<|end_of_turn|>', '<eos>']
218219

220+
export const STOP_CODESTRAL = ['[PREFIX]', '[SUFFIX]']
221+
219222
export const DEFAULT_TEMPLATE_NAMES = defaultTemplates.map(({ name }) => name)
220223

221224
export const DEFAULT_ACTION_TEMPLATES = [

src/extension/fim-templates.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
STOP_DEEPSEEK,
44
STOP_LLAMA,
55
STOP_STARCODER,
6-
STOP_CODEGEMMA
6+
STOP_CODEGEMMA,
7+
STOP_CODESTRAL
78
} from '../common/constants'
89
import { supportedLanguages } from '../common/languages'
910
import { FimPromptTemplate } from '../common/types'
@@ -61,6 +62,23 @@ export const getFimPromptTemplateDeepseek = ({
6162
return `<|fim▁begin|>${fileContext}\n${heading}${prefix}<|fim▁hole|>${suffix}<|fim▁end|>`
6263
}
6364

65+
export const getFimPromptTemplateCodestral = ({
66+
context,
67+
header,
68+
fileContextEnabled,
69+
prefixSuffix,
70+
language
71+
}: FimPromptTemplate) => {
72+
const { prefix, suffix } = prefixSuffix
73+
const { fileContext, heading } = getFileContext(
74+
fileContextEnabled,
75+
context,
76+
language,
77+
header
78+
)
79+
return `${fileContext}\n\n[SUFFIX]${suffix}[PREFIX]${heading}${prefix}`
80+
}
81+
6482
export const getFimPromptTemplateOther = ({
6583
context,
6684
header,
@@ -90,6 +108,10 @@ function getFimTemplateAuto(fimModel: string, args: FimPromptTemplate) {
90108
return getFimPromptTemplateDeepseek(args)
91109
}
92110

111+
if (fimModel.includes(FIM_TEMPLATE_FORMAT.codestral)) {
112+
return getFimPromptTemplateCodestral(args)
113+
}
114+
93115
if (
94116
fimModel.includes(FIM_TEMPLATE_FORMAT.stableCode) ||
95117
fimModel.includes(FIM_TEMPLATE_FORMAT.starcoder) ||
@@ -111,6 +133,10 @@ function getFimTemplateChosen(format: string, args: FimPromptTemplate) {
111133
return getFimPromptTemplateDeepseek(args)
112134
}
113135

136+
if (format === FIM_TEMPLATE_FORMAT.codestral) {
137+
return getFimPromptTemplateCodestral(args)
138+
}
139+
114140
if (
115141
format === FIM_TEMPLATE_FORMAT.stableCode ||
116142
format === FIM_TEMPLATE_FORMAT.starcoder ||
@@ -157,6 +183,10 @@ export const getStopWordsAuto = (fimModel: string) => {
157183
return STOP_CODEGEMMA
158184
}
159185

186+
if (fimModel.includes(FIM_TEMPLATE_FORMAT.codestral)) {
187+
return STOP_CODESTRAL
188+
}
189+
160190
return STOP_LLAMA
161191
}
162192

@@ -169,6 +199,7 @@ export const getStopWordsChosen = (format: string) => {
169199
)
170200
return STOP_STARCODER
171201
if (format === FIM_TEMPLATE_FORMAT.codegemma) return STOP_CODEGEMMA
202+
if (format === FIM_TEMPLATE_FORMAT.codestral) return STOP_CODESTRAL
172203
return STOP_LLAMA
173204
}
174205

src/extension/provider-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ export function createStreamRequestBodyFim(
7676
prompt,
7777
stream: true,
7878
temperature: options.temperature,
79-
n_predict: options.numPredictFim
79+
max_tokens: options.numPredictFim
8080
}
8181
case apiProviders.LlamaCpp:
8282
case apiProviders.Oobabooga:
8383
return {
8484
prompt,
8585
stream: true,
8686
temperature: options.temperature,
87-
n_predict: options.numPredictFim
87+
max_tokens: options.numPredictFim
8888
}
8989
case apiProviders.LiteLLM:
9090
return {

0 commit comments

Comments
 (0)