add promptOnly option to handle single prompt with suffix for Ollama provider
This commit is contained in:
parent
d92a7e08b9
commit
3d08fc96bf
2 changed files with 13 additions and 5 deletions
|
|
@ -11,6 +11,10 @@ import {
|
|||
AutocompleteSnippetType,
|
||||
} from "../snippets/types.js";
|
||||
|
||||
export interface AutocompleteCompletionOptions {
|
||||
promptOnly?: boolean;
|
||||
}
|
||||
|
||||
export interface AutocompleteTemplate {
|
||||
compilePrefixSuffix?: (
|
||||
prefix: string,
|
||||
|
|
@ -31,7 +35,7 @@ export interface AutocompleteTemplate {
|
|||
snippets: AutocompleteSnippet[],
|
||||
workspaceUris: string[],
|
||||
) => string);
|
||||
completionOptions?: Partial<CompletionOptions>;
|
||||
completionOptions?: Partial<CompletionOptions> & Partial<AutocompleteCompletionOptions>;
|
||||
}
|
||||
|
||||
// https://huggingface.co/stabilityai/stable-code-3b
|
||||
|
|
@ -105,6 +109,7 @@ const qwenCoderFimTemplate: AutocompleteTemplate = {
|
|||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
],
|
||||
promptOnly: true // with ollama provider this makes sure a single prompt is sent (with suffix as part of the prompt, not as a separate parameter)
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
|
|||
import { renderChatMessage } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamResponse } from "../stream.js";
|
||||
import { AutocompleteCompletionOptions } from "../../autocomplete/templating/AutocompleteTemplate.js";
|
||||
|
||||
type OllamaChatMessage = {
|
||||
role: "tool" | "user" | "assistant" | "system";
|
||||
|
|
@ -293,7 +294,7 @@ class Ollama extends BaseLLM {
|
|||
}
|
||||
|
||||
private _getGenerateOptions(
|
||||
options: CompletionOptions,
|
||||
options: CompletionOptions & Partial<AutocompleteCompletionOptions>,
|
||||
prompt: string,
|
||||
suffix?: string,
|
||||
): OllamaRawOptions {
|
||||
|
|
@ -303,13 +304,15 @@ class Ollama extends BaseLLM {
|
|||
raw: options.raw,
|
||||
options: this._getModelFileParams(options),
|
||||
keep_alive: options.keepAlive ?? 60 * 30, // 30 minutes
|
||||
suffix,
|
||||
stream: options.stream,
|
||||
// Not supported yet: context, images, system, template, format
|
||||
};
|
||||
|
||||
// Only add suffix if it's not empty. This allows composing the fim template in a way that uses prompt only
|
||||
if (suffix && suffix !== "") {
|
||||
generateOptions.suffix = suffix;
|
||||
if (options.promptOnly) {
|
||||
console.log("fim: removing suffix");
|
||||
|
||||
delete generateOptions.suffix;
|
||||
}
|
||||
|
||||
return generateOptions;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue