Skip to content

Commit d1ba7c9

Browse files
authored
feat: Support Granite 4 FIM and tool calling correctly (#8531)
* feat: Use the correct FIM template for Granite 4 models Branch: GraniteFourTemplates Signed-off-by: Gabe Goodhart <[email protected]> * feat: Add granite4 name variants to the list of models that natively support tools Branch: GraniteFourTemplates Signed-off-by: Gabe Goodhart <[email protected]> --------- Signed-off-by: Gabe Goodhart <[email protected]>
1 parent 88c11a1 commit d1ba7c9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

core/autocomplete/templating/AutocompleteTemplate.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ const qwenCoderFimTemplate: AutocompleteTemplate = {
7171
},
7272
};
7373

74+
// https://www.ibm.com/granite/docs/models/granite#fim
75+
const granite4FimTemplate: AutocompleteTemplate = {
76+
template:
77+
"<|fim_prefix|>{{{prefix}}}<|fim_suffix|>{{{suffix}}}<|fim_middle|>",
78+
completionOptions: {
79+
stop: [
80+
"<|end_of_text|>",
81+
"<|fim_prefix|>",
82+
"<|fim_middle|>",
83+
"<|fim_suffix|>",
84+
"<|fim_pad|>",
85+
],
86+
},
87+
};
88+
7489
const seedCoderFimTemplate: AutocompleteTemplate = {
7590
template:
7691
"<[fim-prefix]>{{{prefix}}}<[fim-suffix]>{{{suffix}}}<[fim-middle]>",
@@ -442,6 +457,10 @@ export function getTemplateForModel(model: string): AutocompleteTemplate {
442457
return qwenCoderFimTemplate;
443458
}
444459

460+
if (lowerCaseModel.includes("granite") && lowerCaseModel.includes("4")) {
461+
return granite4FimTemplate;
462+
}
463+
445464
if (lowerCaseModel.includes("seed") && lowerCaseModel.includes("coder")) {
446465
return seedCoderFimTemplate;
447466
}

core/llm/toolSupport.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
189189
"llama3-groq",
190190
"granite3",
191191
"granite-3",
192+
"granite4",
193+
"granite-4",
192194
"aya-expanse",
193195
"firefunction-v2",
194196
"mistral",

0 commit comments

Comments
 (0)