⚡️ improved OpenAI autocomplete support
This commit is contained in:
parent
4053f1ad60
commit
abec395a4c
2 changed files with 11 additions and 6 deletions
|
|
@ -79,12 +79,11 @@ const deepseekFimTemplateWrongPipeChar: AutocompleteTemplate = {
|
|||
};
|
||||
|
||||
const gptAutocompleteTemplate: AutocompleteTemplate = {
|
||||
template: `Your task is to complete the line at the end of this code block:
|
||||
\`\`\`
|
||||
{{{prefix}}}
|
||||
template: `\`\`\`
|
||||
{{{prefix}}}[BLANK]{{{suffix}}}
|
||||
\`\`\`
|
||||
|
||||
The last line is incomplete, and you should provide the rest of that line. If the line is already complete, just return a new line. Otherwise, DO NOT provide explanation, a code block, or extra whitespace, just the code that should be added to the last line to complete it:`,
|
||||
Fill in the blank to complete the code block. Your response should include only the code to replace [BLANK], without surrounding backticks.`,
|
||||
completionOptions: { stop: ["\n"] },
|
||||
};
|
||||
|
||||
|
|
@ -113,7 +112,10 @@ export function getTemplateForModel(model: string): AutocompleteTemplate {
|
|||
return deepseekFimTemplate;
|
||||
}
|
||||
|
||||
if (lowerCaseModel.includes("gpt") || lowerCaseModel.includes("davinci-002")) {
|
||||
if (
|
||||
lowerCaseModel.includes("gpt") ||
|
||||
lowerCaseModel.includes("davinci-002")
|
||||
) {
|
||||
return gptAutocompleteTemplate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class OpenAI extends BaseLLM {
|
|||
}
|
||||
|
||||
protected _convertArgs(options: any, messages: ChatMessage[]) {
|
||||
const url = new URL(this.apiBase!);
|
||||
const finalOptions = {
|
||||
messages: messages.map(this._convertMessage),
|
||||
model: options.model,
|
||||
|
|
@ -76,7 +77,9 @@ class OpenAI extends BaseLLM {
|
|||
presence_penalty: options.presencePenalty,
|
||||
stop:
|
||||
// Jan + Azure OpenAI don't truncate and will throw an error
|
||||
this.apiBase?.includes(":1337") || this.apiType === "azure"
|
||||
url.port === "1337" ||
|
||||
url.host === "api.openai.com" ||
|
||||
this.apiType === "azure"
|
||||
? options.stop?.slice(0, 4)
|
||||
: options.stop,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue