From 18854181770d63c4f677b1c14de2bfcc5ce8e4e2 Mon Sep 17 00:00:00 2001 From: ahliang2002 Date: Thu, 14 Nov 2024 21:25:52 +0800 Subject: [PATCH 1/4] update: autoCodeCompletion function update: ollamaService add 'stop' --- .../code-brt/.vscode/settings.json | 52 ++--- .../codeCompletion/constants/templates.ts | 141 +++++++++++++ .../providers/autoCodeCompletionProvider.ts | 46 ++-- .../strategies/autoCodeCompletionStrategy.ts | 197 +++++++++++++++++- .../codeCompletion/strategies/index.ts | 1 + .../services/languageModel/ollamaService.ts | 53 +++-- .../src/types/languageModelService.d.ts | 12 ++ .../Toolbar/CodeCompletionSettingsBar.tsx | 3 +- 8 files changed, 442 insertions(+), 63 deletions(-) diff --git a/VSCodeExtension/code-brt/.vscode/settings.json b/VSCodeExtension/code-brt/.vscode/settings.json index 0016c9d2..01ced073 100644 --- a/VSCodeExtension/code-brt/.vscode/settings.json +++ b/VSCodeExtension/code-brt/.vscode/settings.json @@ -1,29 +1,29 @@ // Place your settings in this file to overwrite default and user settings. { - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" - }, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "search.useIgnoreFiles": true, - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact" - ], - "files.exclude": { - ".vscode-test": true - }, - "search.exclude": { - "node_modules": true, - ".vscode-test": true, - "dist/**/*.js": true, - "dist/**/*.js.map": true, - "out/**/*.js": true, - "out/**/*.js.map": true - }, - "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true, - "code-brt.lastUsedHistoryID": "581a0dcb-b977-41a9-b514-1d456b252a82" + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "search.useIgnoreFiles": true, + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact" + ], + "files.exclude": { + ".vscode-test": true + }, + "search.exclude": { + "node_modules": true, + ".vscode-test": true, + "dist/**/*.js": true, + "dist/**/*.js.map": true, + "out/**/*.js": true, + "out/**/*.js.map": true + }, + "typescript.tsdk": "node_modules/typescript/lib", + "typescript.enablePromptUseWorkspaceTsdk": true, + "code-brt.lastUsedHistoryID": "581a0dcb-b977-41a9-b514-1d456b252a82" } diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts index 9f087cbd..f9eb34d1 100644 --- a/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts +++ b/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts @@ -113,3 +113,144 @@ export const MAIN_PROMPT_TEMPLATE = `{codeLanguage} TASK: Fill the {{FILL_HERE}} hole. Answer only with the CORRECT completion inside the tag. Do NOT include any explanations, markdown formatting, or extra content. Do it now. `; + +// ==================== 新增 Ollama 模型模板 ==================== + +export interface CompletionOptions { + maxTokens?: number; + temperature?: number; + topP?: number; + topK?: number; + presencePenalty?: number; + frequencyPenalty?: number; + stop?: string | string[]; +} + +export interface CompletionTemplate { + template: + | string + | (( + prefix: string, + suffix: string, + filepath: string, + language: string, + ) => string); + completionOptions?: Partial; +} + +// StableCode FIM 模板(默认) +const stableCodeFimTemplate: CompletionTemplate = { + template: '{{{prefix}}}{{{suffix}}}', + completionOptions: { + stop: [ + '', + '', + '', + '', + '<|endoftext|>', + '', + '', + ], + }, +}; + +// Qwen2.5-Coder 模板 +const qwenCoderFimTemplate: CompletionTemplate = { + template: + '<|fim_prefix|>{{{prefix}}}<|fim_suffix|>{{{suffix}}}<|fim_middle|>', + completionOptions: { + stop: [ + '<|endoftext|>', + '<|fim_prefix|>', + '<|fim_middle|>', + '<|fim_suffix|>', + '<|fim_pad|>', + '<|repo_name|>', + '<|file_sep|>', + '<|im_start|>', + '<|im_end|>', + ], + }, +}; + +// Codestral 模板 +const codestralFimTemplate: CompletionTemplate = { + template: '[SUFFIX]{{{suffix}}}[PREFIX]{{{prefix}}}', + completionOptions: { + stop: ['[PREFIX]', '[SUFFIX]'], + }, +}; + +// CodeLlama 模板 +const codeLlamaFimTemplate: CompletionTemplate = { + template: '
 {{{prefix}}} {{{suffix}}} ',
+  completionOptions: {
+    stop: ['
', '', '', ''],
+  },
+};
+
+// DeepSeek-Coder 模板
+const deepseekFimTemplate: CompletionTemplate = {
+  template:
+    '<|fim▁begin|>{{{prefix}}}<|fim▁hole|>{{{suffix}}}<|fim▁end|>',
+  completionOptions: {
+    stop: [
+      '<|fim▁begin|>',
+      '<|fim▁hole|>',
+      '<|fim▁end|>',
+      '//',
+      '<|end▁of▁sentence|>',
+    ],
+  },
+};
+
+const starCoderFimTemplate: CompletionTemplate = {
+  template: '{{{prefix}}}{{{suffix}}}',
+  completionOptions: {
+    stop: [
+      '',
+      '',
+      '',
+      '',
+      '<|endoftext|>',
+    ],
+  },
+};
+
+export const modelTemplates: { [modelName: string]: CompletionTemplate } = {
+  'deepseek-coder-v2': deepseekFimTemplate,
+  codellama: codeLlamaFimTemplate,
+  'deepseek-coder': deepseekFimTemplate,
+  'qwen2.5-coder': qwenCoderFimTemplate,
+  starcoder: starCoderFimTemplate,
+  codestral: codestralFimTemplate,
+};
+
+export function getTemplateForModel(modelName: string): CompletionTemplate {
+  const lowerCaseModel = modelName.toLowerCase();
+
+  if (lowerCaseModel.includes('qwen') && lowerCaseModel.includes('coder')) {
+    return qwenCoderFimTemplate;
+  }
+
+  if (
+    lowerCaseModel.includes('starcoder') ||
+    lowerCaseModel.includes('star-coder')
+  ) {
+    return starCoderFimTemplate;
+  }
+
+  if (lowerCaseModel.includes('codestral')) {
+    return codestralFimTemplate;
+  }
+
+  if (lowerCaseModel.includes('codellama')) {
+    return codeLlamaFimTemplate;
+  }
+
+  if (lowerCaseModel.includes('deepseek')) {
+    return deepseekFimTemplate;
+  }
+
+  return stableCodeFimTemplate;
+}
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts
index 2c768ce1..3fe45335 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts
@@ -1,26 +1,46 @@
-import vscode from 'vscode';
+// autoCodeCompletionProvider.ts
 
-import type { LoadedModelServices } from 'src/types';
+import * as vscode from 'vscode';
 import { AbstractCompletionProvider } from '../base';
 import { SettingsManager } from '../../../api';
+import { AutoCodeCompletionStrategy } from '../strategies';
 import { StatusBarManager } from '../ui/statusBarManager';
+import type { LoadedModelServices } from '../../../types';
 
-// TODO: Implement the AutoCodeCompletionProvider class
 export class AutoCodeCompletionProvider implements AbstractCompletionProvider {
+  private readonly completionStrategy: AutoCodeCompletionStrategy;
+
   constructor(
-    _ctx: vscode.ExtensionContext,
-    _settingsManager: SettingsManager,
-    _loadedModelServices: LoadedModelServices,
-    _statusBarManager: StatusBarManager,
-  ) {}
+    ctx: vscode.ExtensionContext,
+    settingsManager: SettingsManager,
+    loadedModelServices: LoadedModelServices,
+    statusBarManager: StatusBarManager,
+  ) {
+    this.completionStrategy = new AutoCodeCompletionStrategy(
+      ctx,
+      settingsManager,
+      loadedModelServices,
+      statusBarManager,
+    );
+  }
 
-  provideCompletionItems(
-    _document: vscode.TextDocument,
-    _position: vscode.Position,
-    _token: vscode.CancellationToken,
+  async provideCompletionItems(
+    document: vscode.TextDocument,
+    position: vscode.Position,
+    token: vscode.CancellationToken,
   ): Promise<
     vscode.InlineCompletionItem[] | vscode.InlineCompletionList | null
   > {
-    return Promise.resolve(null);
+    const completions = await this.completionStrategy.provideCompletion(
+      document,
+      position,
+      token,
+    );
+
+    if (!completions || completions.length === 0) {
+      return null;
+    }
+
+    return new vscode.InlineCompletionList(completions);
   }
 }
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts
index 49ebaae8..9317a1b8 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts
@@ -1 +1,196 @@
-// TODO: Implement the auto code completion strategy by Code Model
+// autoCodeCompletionStrategy.ts
+
+import * as vscode from 'vscode';
+import type { LoadedModelServices, ModelServiceType } from '../../../types';
+import { CompletionStrategy } from './index';
+import { getTemplateForModel } from '../constants/templates';
+import { SettingsManager, HistoryManager } from '../../../api';
+import { StatusBarManager } from '../ui/statusBarManager';
+import { postProcessCompletion } from '../utils';
+import { CodeLanguageId } from '../types/CodeLanguageId';
+import { FILE_TO_LANGUAGE, LANGUAGE_NAME_MAPPING } from '../constants';
+import { GetResponseOptionsWithCompletion } from '../../../../src/types';
+
+export class AutoCodeCompletionStrategy implements CompletionStrategy {
+  private readonly settingsManager: SettingsManager;
+  private readonly historyManager: HistoryManager;
+  private readonly loadedModelServices: LoadedModelServices;
+  private readonly statusBarManager: StatusBarManager;
+
+  constructor(
+    ctx: vscode.ExtensionContext,
+    settingsManager: SettingsManager,
+    loadedModelServices: LoadedModelServices,
+    statusBarManager: StatusBarManager,
+  ) {
+    this.settingsManager = settingsManager;
+    this.historyManager = new HistoryManager(
+      ctx,
+      'autoCodeCompletionIndex.json',
+      'autoCodeCompletionHistories',
+    );
+    this.loadedModelServices = loadedModelServices;
+    this.statusBarManager = statusBarManager;
+  }
+
+  private detectLanguageId(
+    document: vscode.TextDocument,
+  ): CodeLanguageId | 'unknown' {
+    const fileExtension =
+      document.uri.fsPath.split('.').pop()?.toLowerCase() || '';
+    const languageIdFromExtension = FILE_TO_LANGUAGE[fileExtension];
+    const languageId =
+      languageIdFromExtension || document.languageId.toLowerCase();
+
+    if (LANGUAGE_NAME_MAPPING[languageId as CodeLanguageId]) {
+      return languageId as CodeLanguageId;
+    } else {
+      return 'unknown';
+    }
+  }
+
+  private cleanCompletionResponse(response: string): string {
+    return response.trim();
+  }
+
+  private async getResponse(
+    prompt: string,
+    modelService: ModelServiceType,
+    modelName: string,
+    completionOptions?: Partial<{
+      maxTokens?: number;
+      temperature?: number;
+      topP?: number;
+      topK?: number;
+      presencePenalty?: number;
+      frequencyPenalty?: number;
+      stop?: string | string[]; 
+    }>,
+  ): Promise {
+    const history = this.historyManager.getCurrentHistory();
+    await this.historyManager.updateHistoryModelAdvanceSettings(history.root, {
+      ...history.advanceSettings,
+      systemPrompt: '',
+      temperature: completionOptions?.temperature || 0.7,
+      maxTokens: completionOptions?.maxTokens || 150,
+    });
+
+    const response = await this.loadedModelServices[
+      modelService
+    ].service.getResponse({
+      query: prompt,
+      historyManager: this.historyManager,
+      selectedModelName: modelName,
+      disableTools: true,
+      completionOptions: completionOptions, 
+    } as GetResponseOptionsWithCompletion);
+
+    return this.cleanCompletionResponse(response);
+  }
+
+  public async provideCompletion(
+    document: vscode.TextDocument,
+    position: vscode.Position,
+    token: vscode.CancellationToken,
+  ): Promise {
+    if (!this.settingsManager.get('autoTriggerCodeCompletion')) {
+      return null;
+    }
+
+    this.statusBarManager.showProcessing();
+
+    try {
+      const modelService = this.settingsManager.get(
+        'lastUsedAutoCodeCompletionModelService',
+      ) as ModelServiceType;
+      const modelName = this.settingsManager.get(
+        'lastSelectedAutoCodeCompletionModel',
+      )[modelService];
+
+      if (!this.loadedModelServices[modelService]) {
+        console.warn(`Model service ${modelService} is not loaded.`);
+        return null;
+      }
+
+      const languageId = this.detectLanguageId(document);
+      if (languageId === 'unknown') {
+        console.warn('Unsupported language for code completion.');
+        return null;
+      }
+
+      const language = LANGUAGE_NAME_MAPPING[languageId];
+
+      const template = getTemplateForModel(modelName);
+
+      if (!template) {
+        console.warn(`No template found for model ${modelName}`);
+        return null;
+      }
+
+      const maxLines = 20;
+      const startLine = Math.max(0, position.line - maxLines);
+      const endLine = Math.min(
+        document.lineCount - 1,
+        position.line + maxLines,
+      );
+
+      const prefix = document.getText(
+        new vscode.Range(new vscode.Position(startLine, 0), position),
+      );
+
+      const suffix = document.getText(
+        new vscode.Range(
+          position,
+          new vscode.Position(endLine, Number.MAX_VALUE),
+        ),
+      );
+
+      const filepath = document.uri.fsPath;
+
+      const prompt =
+        typeof template.template === 'function'
+          ? template.template(prefix, suffix, filepath, language)
+          : template.template
+              .replace('{{{prefix}}}', prefix)
+              .replace('{{{suffix}}}', suffix);
+
+      if (token.isCancellationRequested) {
+        return null;
+      }
+
+      const completionOptions = {
+        ...template.completionOptions,
+      };
+
+      const rawResponse = await this.getResponse(
+        prompt,
+        modelService,
+        modelName,
+        completionOptions,
+      );
+
+      const postProcessedResult = postProcessCompletion(
+        rawResponse,
+        prefix,
+        suffix,
+        modelName,
+      );
+
+      if (!postProcessedResult) {
+        return null;
+      }
+
+      const completionItem = new vscode.InlineCompletionItem(
+        postProcessedResult,
+        new vscode.Range(position, position),
+      );
+
+      return [completionItem];
+    } catch (error) {
+      console.error('Autocomplete error:', error);
+      return null;
+    } finally {
+      this.statusBarManager.showIdle();
+    }
+  }
+}
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts
index 6cfd9705..884d58fd 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts
@@ -9,3 +9,4 @@ export interface CompletionStrategy {
 }
 
 export * from './manuallyCodeCompletionStrategy';
+export * from './autoCodeCompletionStrategy';
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts b/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts
index 40294943..e7c9f22b 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts
@@ -6,7 +6,7 @@ import { Ollama } from 'ollama';
 
 import type {
   ConversationEntry,
-  GetResponseOptions,
+  GetResponseOptionsWithCompletion,
   ToolServiceType,
 } from '../../types';
 import { MODEL_SERVICE_CONSTANTS, toolsSchema } from '../../constants';
@@ -35,32 +35,38 @@ export class OllamaService extends AbstractLanguageModelService {
     );
   }
 
-  private getAdvanceSettings(historyManager: HistoryManager): {
+  private getAdvanceSettings(
+    historyManager: HistoryManager,
+    completionOptions?: GetResponseOptionsWithCompletion['completionOptions'], // 新增
+  ): {
     systemPrompt: string | undefined;
     generationConfig: Partial;
   } {
     const advanceSettings = historyManager.getCurrentHistory().advanceSettings;
 
-    if (!advanceSettings) {
-      return {
-        systemPrompt: undefined,
-        generationConfig: {},
+    let generationConfig: Partial = {};
+
+    if (completionOptions) {
+      const { stop, ...otherOptions } = completionOptions;
+
+      generationConfig = {
+        ...generationConfig,
+        ...otherOptions,
       };
+
+      if (stop !== undefined) {
+        generationConfig.stop = Array.isArray(stop) ? stop : [stop];
+      }
     }
 
+    const systemPrompt =
+      advanceSettings?.systemPrompt && advanceSettings.systemPrompt.length > 0
+        ? advanceSettings.systemPrompt
+        : undefined;
+
     return {
-      systemPrompt:
-        advanceSettings.systemPrompt.length > 0
-          ? advanceSettings.systemPrompt
-          : undefined,
-      generationConfig: {
-        num_ctx: advanceSettings.maxTokens,
-        temperature: advanceSettings.temperature,
-        top_p: advanceSettings.topP,
-        top_k: advanceSettings.topK,
-        presence_penalty: advanceSettings.presencePenalty,
-        frequency_penalty: advanceSettings.frequencyPenalty,
-      },
+      systemPrompt,
+      generationConfig,
     };
   }
 
@@ -290,7 +296,9 @@ export class OllamaService extends AbstractLanguageModelService {
     return newAvailableModelNames;
   }
 
-  public async getResponse(options: GetResponseOptions): Promise {
+  public async getResponse(
+    options: GetResponseOptionsWithCompletion,
+  ): Promise {
     if (this.currentModel === '') {
       vscode.window.showErrorMessage(
         'Make sure the model is selected before sending a message. Open the model selection dropdown and configure the model.',
@@ -307,6 +315,7 @@ export class OllamaService extends AbstractLanguageModelService {
       updateStatus,
       selectedModelName,
       disableTools,
+      completionOptions, // 新增
     } = options;
     const { client, conversationHistory, model } = await this.initModel(
       query,
@@ -323,8 +332,10 @@ export class OllamaService extends AbstractLanguageModelService {
     let functionCallCount = 0;
     const MAX_FUNCTION_CALLS = 5;
 
-    const { systemPrompt, generationConfig } =
-      this.getAdvanceSettings(historyManager);
+    const { systemPrompt, generationConfig } = this.getAdvanceSettings(
+      historyManager,
+      completionOptions,
+    );
 
     if (systemPrompt) {
       conversationHistory.unshift({
diff --git a/VSCodeExtension/code-brt/src/types/languageModelService.d.ts b/VSCodeExtension/code-brt/src/types/languageModelService.d.ts
index 2dd6502a..bc17f745 100644
--- a/VSCodeExtension/code-brt/src/types/languageModelService.d.ts
+++ b/VSCodeExtension/code-brt/src/types/languageModelService.d.ts
@@ -26,6 +26,18 @@ type GetResponseOptions = {
   disableTools?: boolean;
 };
 
+export interface GetResponseOptionsWithCompletion extends GetResponseOptions {
+  completionOptions?: Partial<{
+    maxTokens?: number;
+    temperature?: number;
+    topP?: number;
+    topK?: number;
+    presencePenalty?: number;
+    frequencyPenalty?: number;
+    stop?: string | string[];
+  }>;
+}
+
 export type LanguageModelService = {
   /**
    * Update the available models
diff --git a/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/Toolbar/CodeCompletionSettingsBar.tsx b/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/Toolbar/CodeCompletionSettingsBar.tsx
index 962672ab..b501c1ee 100644
--- a/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/Toolbar/CodeCompletionSettingsBar.tsx
+++ b/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/Toolbar/CodeCompletionSettingsBar.tsx
@@ -276,10 +276,9 @@ export const CodeCompletionSettingsBar: React.FC<
           
             
-              Enable Auto Trigger Code Completion (Soon)
+              Enable Auto Trigger Code Completion
             
           
         

From 7f0e91b6e3fc582b4f63f59583bef5e05ceaf735 Mon Sep 17 00:00:00 2001
From: whats2000 
Date: Thu, 14 Nov 2024 22:42:29 +0800
Subject: [PATCH 2/4] Add: Add support for stop sequence config

---
 .../code-brt/src/api/historyManager.ts        |   1 +
 .../src/constants/modelAdvanceSettings.ts     |  11 +
 .../codeCompletion/constants/templates.ts     | 207 +++++++-----------
 .../providers/autoCodeCompletionProvider.ts   |   3 +-
 .../strategies/autoCodeCompletionStrategy.ts  |  45 ++--
 .../codeCompletion/strategies/index.ts        |  10 -
 .../manuallyCodeCompletionStrategy.ts         |   9 +-
 ...odeLanguageId.d.ts => codeLanguageId.d.ts} |   0
 .../types/completionStrategy.d.ts             |   9 +
 .../types/completionTemplate.d.ts             |  15 ++
 .../services/codeCompletion/types/index.d.ts  |   4 +-
 .../utils/getTemplateForModel.ts              |  31 +++
 .../services/codeCompletion/utils/index.ts    |   1 +
 .../languageModel/anthropicService.ts         |   1 +
 .../base/abstractOpenaiLikeService.ts         |   1 +
 .../services/languageModel/cohereService.ts   |   1 +
 .../services/languageModel/geminiService.ts   |   1 +
 .../languageModel/huggingFaceService.ts       |   1 +
 .../services/languageModel/ollamaService.ts   |   1 +
 .../types/languageModelService.d.ts           |  12 -
 .../src/types/conversationHistory.d.ts        |   1 +
 .../ModelAdvanceSettingBar.tsx                |   1 +
 .../ModelAdvanceSettingFormItem.tsx           |  23 ++
 23 files changed, 200 insertions(+), 189 deletions(-)
 rename VSCodeExtension/code-brt/src/services/codeCompletion/types/{CodeLanguageId.d.ts => codeLanguageId.d.ts} (100%)
 create mode 100644 VSCodeExtension/code-brt/src/services/codeCompletion/types/completionStrategy.d.ts
 create mode 100644 VSCodeExtension/code-brt/src/services/codeCompletion/types/completionTemplate.d.ts
 create mode 100644 VSCodeExtension/code-brt/src/services/codeCompletion/utils/getTemplateForModel.ts

diff --git a/VSCodeExtension/code-brt/src/api/historyManager.ts b/VSCodeExtension/code-brt/src/api/historyManager.ts
index fc49d89b..87a7155a 100644
--- a/VSCodeExtension/code-brt/src/api/historyManager.ts
+++ b/VSCodeExtension/code-brt/src/api/historyManager.ts
@@ -91,6 +91,7 @@ export class HistoryManager implements IHistoryManager {
         topK: undefined,
         presencePenalty: undefined,
         frequencyPenalty: undefined,
+        stop: undefined,
       },
       entries: {},
     };
diff --git a/VSCodeExtension/code-brt/src/constants/modelAdvanceSettings.ts b/VSCodeExtension/code-brt/src/constants/modelAdvanceSettings.ts
index 9f0c369e..6453f567 100644
--- a/VSCodeExtension/code-brt/src/constants/modelAdvanceSettings.ts
+++ b/VSCodeExtension/code-brt/src/constants/modelAdvanceSettings.ts
@@ -91,4 +91,15 @@ export const MODEL_ADVANCE_SETTINGS: {
     },
     link: 'https://platform.openai.com/docs/guides/text-generation/parameter-details',
   },
+  stop: {
+    description:
+      `A list of tokens where the model should stop generating further tokens. ` +
+      `Separate each token with a new line for multiple tokens. ` +
+      `If you want to stop the model from generating more tokens, you can add a stop token here.`,
+    range: {
+      min: undefined,
+      max: undefined,
+    },
+    link: 'https://platform.openai.com/docs/api-reference/chat/create#chat-create-stop',
+  },
 };
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts
index f9eb34d1..6b55154d 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/constants/templates.ts
@@ -1,3 +1,5 @@
+import { CompletionTemplate } from '../types';
+
 /**
  * The follow code is modified from the original source code.
  * https://github.com/continuedev/continue/blob/main/core/autocomplete/templates.ts
@@ -114,143 +116,82 @@ export const MAIN_PROMPT_TEMPLATE = `{codeLanguage}
 TASK: Fill the {{FILL_HERE}} hole. Answer only with the CORRECT completion inside the  tag. Do NOT include any explanations, markdown formatting, or extra content. Do it now.
 `;
 
-// ==================== 新增 Ollama 模型模板 ====================
-
-export interface CompletionOptions {
-  maxTokens?: number;
-  temperature?: number;
-  topP?: number;
-  topK?: number;
-  presencePenalty?: number;
-  frequencyPenalty?: number;
-  stop?: string | string[];
-}
-
-export interface CompletionTemplate {
-  template:
-    | string
-    | ((
-        prefix: string,
-        suffix: string,
-        filepath: string,
-        language: string,
-      ) => string);
-  completionOptions?: Partial;
-}
-
-// StableCode FIM 模板(默认)
-const stableCodeFimTemplate: CompletionTemplate = {
-  template: '{{{prefix}}}{{{suffix}}}',
-  completionOptions: {
-    stop: [
-      '',
-      '',
-      '',
-      '',
-      '<|endoftext|>',
-      '',
-      '',
-    ],
+// ==================== Add Ollama Model Template ====================
+export const HOLE_FILLER_TEMPLATE: {
+  [key: string]: CompletionTemplate;
+} = {
+  // StableCode FIM Template (Default)
+  stableCodeFimTemplate: {
+    template: '{{{prefix}}}{{{suffix}}}',
+    completionOptions: {
+      stop: [
+        '',
+        '',
+        '',
+        '',
+        '<|endoftext|>',
+        '',
+        '',
+      ],
+    },
   },
-};
-
-// Qwen2.5-Coder 模板
-const qwenCoderFimTemplate: CompletionTemplate = {
-  template:
-    '<|fim_prefix|>{{{prefix}}}<|fim_suffix|>{{{suffix}}}<|fim_middle|>',
-  completionOptions: {
-    stop: [
-      '<|endoftext|>',
-      '<|fim_prefix|>',
-      '<|fim_middle|>',
-      '<|fim_suffix|>',
-      '<|fim_pad|>',
-      '<|repo_name|>',
-      '<|file_sep|>',
-      '<|im_start|>',
-      '<|im_end|>',
-    ],
+  // Qwen2.5-Coder Template
+  qwenCoderFimTemplate: {
+    template:
+      '<|fim_prefix|>{{{prefix}}}<|fim_suffix|>{{{suffix}}}<|fim_middle|>',
+    completionOptions: {
+      stop: [
+        '<|endoftext|>',
+        '<|fim_prefix|>',
+        '<|fim_middle|>',
+        '<|fim_suffix|>',
+        '<|fim_pad|>',
+        '<|repo_name|>',
+        '<|file_sep|>',
+        '<|im_start|>',
+        '<|im_end|>',
+      ],
+    },
   },
-};
-
-// Codestral 模板
-const codestralFimTemplate: CompletionTemplate = {
-  template: '[SUFFIX]{{{suffix}}}[PREFIX]{{{prefix}}}',
-  completionOptions: {
-    stop: ['[PREFIX]', '[SUFFIX]'],
+  // Codestral Template
+  codestralFimTemplate: {
+    template: '[SUFFIX]{{{suffix}}}[PREFIX]{{{prefix}}}',
+    completionOptions: {
+      stop: ['[PREFIX]', '[SUFFIX]'],
+    },
   },
-};
-
-// CodeLlama 模板
-const codeLlamaFimTemplate: CompletionTemplate = {
-  template: '
 {{{prefix}}} {{{suffix}}} ',
-  completionOptions: {
-    stop: ['
', '', '', ''],
+  // CodeLlama Template
+  codeLlamaFimTemplate: {
+    template: '
 {{{prefix}}} {{{suffix}}} ',
+    completionOptions: {
+      stop: ['
', '', '', ''],
+    },
   },
-};
-
-// DeepSeek-Coder 模板
-const deepseekFimTemplate: CompletionTemplate = {
-  template:
-    '<|fim▁begin|>{{{prefix}}}<|fim▁hole|>{{{suffix}}}<|fim▁end|>',
-  completionOptions: {
-    stop: [
-      '<|fim▁begin|>',
-      '<|fim▁hole|>',
-      '<|fim▁end|>',
-      '//',
-      '<|end▁of▁sentence|>',
-    ],
+  // DeepSeek-Coder Template
+  deepseekFimTemplate: {
+    template:
+      '<|fim▁begin|>{{{prefix}}}<|fim▁hole|>{{{suffix}}}<|fim▁end|>',
+    completionOptions: {
+      stop: [
+        '<|fim▁begin|>',
+        '<|fim▁hole|>',
+        '<|fim▁end|>',
+        '//',
+        '<|end▁of▁sentence|>',
+      ],
+    },
   },
-};
-
-const starCoderFimTemplate: CompletionTemplate = {
-  template: '{{{prefix}}}{{{suffix}}}',
-  completionOptions: {
-    stop: [
-      '',
-      '',
-      '',
-      '',
-      '<|endoftext|>',
-    ],
+  // StarCoder Template
+  starCoderFimTemplate: {
+    template: '{{{prefix}}}{{{suffix}}}',
+    completionOptions: {
+      stop: [
+        '',
+        '',
+        '',
+        '',
+        '<|endoftext|>',
+      ],
+    },
   },
 };
-
-export const modelTemplates: { [modelName: string]: CompletionTemplate } = {
-  'deepseek-coder-v2': deepseekFimTemplate,
-  codellama: codeLlamaFimTemplate,
-  'deepseek-coder': deepseekFimTemplate,
-  'qwen2.5-coder': qwenCoderFimTemplate,
-  starcoder: starCoderFimTemplate,
-  codestral: codestralFimTemplate,
-};
-
-export function getTemplateForModel(modelName: string): CompletionTemplate {
-  const lowerCaseModel = modelName.toLowerCase();
-
-  if (lowerCaseModel.includes('qwen') && lowerCaseModel.includes('coder')) {
-    return qwenCoderFimTemplate;
-  }
-
-  if (
-    lowerCaseModel.includes('starcoder') ||
-    lowerCaseModel.includes('star-coder')
-  ) {
-    return starCoderFimTemplate;
-  }
-
-  if (lowerCaseModel.includes('codestral')) {
-    return codestralFimTemplate;
-  }
-
-  if (lowerCaseModel.includes('codellama')) {
-    return codeLlamaFimTemplate;
-  }
-
-  if (lowerCaseModel.includes('deepseek')) {
-    return deepseekFimTemplate;
-  }
-
-  return stableCodeFimTemplate;
-}
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts
index 3fe45335..c2f2d0c3 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/providers/autoCodeCompletionProvider.ts
@@ -1,6 +1,5 @@
-// autoCodeCompletionProvider.ts
-
 import * as vscode from 'vscode';
+
 import { AbstractCompletionProvider } from '../base';
 import { SettingsManager } from '../../../api';
 import { AutoCodeCompletionStrategy } from '../strategies';
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts
index 9317a1b8..77085be5 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/autoCodeCompletionStrategy.ts
@@ -1,15 +1,16 @@
-// autoCodeCompletionStrategy.ts
-
 import * as vscode from 'vscode';
-import type { LoadedModelServices, ModelServiceType } from '../../../types';
-import { CompletionStrategy } from './index';
-import { getTemplateForModel } from '../constants/templates';
+
+import type {
+  CodeLanguageId,
+  CompletionStrategy,
+  CompletionTemplate,
+  LoadedModelServices,
+  ModelServiceType,
+} from '../../../types';
+import { FILE_TO_LANGUAGE, LANGUAGE_NAME_MAPPING } from '../constants';
 import { SettingsManager, HistoryManager } from '../../../api';
 import { StatusBarManager } from '../ui/statusBarManager';
-import { postProcessCompletion } from '../utils';
-import { CodeLanguageId } from '../types/CodeLanguageId';
-import { FILE_TO_LANGUAGE, LANGUAGE_NAME_MAPPING } from '../constants';
-import { GetResponseOptionsWithCompletion } from '../../../../src/types';
+import { getTemplateForModel, postProcessCompletion } from '../utils';
 
 export class AutoCodeCompletionStrategy implements CompletionStrategy {
   private readonly settingsManager: SettingsManager;
@@ -57,22 +58,15 @@ export class AutoCodeCompletionStrategy implements CompletionStrategy {
     prompt: string,
     modelService: ModelServiceType,
     modelName: string,
-    completionOptions?: Partial<{
-      maxTokens?: number;
-      temperature?: number;
-      topP?: number;
-      topK?: number;
-      presencePenalty?: number;
-      frequencyPenalty?: number;
-      stop?: string | string[]; 
-    }>,
+    template: CompletionTemplate,
   ): Promise {
     const history = this.historyManager.getCurrentHistory();
     await this.historyManager.updateHistoryModelAdvanceSettings(history.root, {
       ...history.advanceSettings,
       systemPrompt: '',
-      temperature: completionOptions?.temperature || 0.7,
-      maxTokens: completionOptions?.maxTokens || 150,
+      temperature: template.completionOptions?.temperature || 0.7,
+      maxTokens: template.completionOptions?.maxTokens || 150,
+      stop: template.completionOptions?.stop || undefined,
     });
 
     const response = await this.loadedModelServices[
@@ -82,10 +76,9 @@ export class AutoCodeCompletionStrategy implements CompletionStrategy {
       historyManager: this.historyManager,
       selectedModelName: modelName,
       disableTools: true,
-      completionOptions: completionOptions, 
-    } as GetResponseOptionsWithCompletion);
+    });
 
-    return this.cleanCompletionResponse(response);
+    return this.cleanCompletionResponse(response.textResponse);
   }
 
   public async provideCompletion(
@@ -158,15 +151,11 @@ export class AutoCodeCompletionStrategy implements CompletionStrategy {
         return null;
       }
 
-      const completionOptions = {
-        ...template.completionOptions,
-      };
-
       const rawResponse = await this.getResponse(
         prompt,
         modelService,
         modelName,
-        completionOptions,
+        template,
       );
 
       const postProcessedResult = postProcessCompletion(
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts
index 884d58fd..d34de29b 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/index.ts
@@ -1,12 +1,2 @@
-import * as vscode from 'vscode';
-
-export interface CompletionStrategy {
-  provideCompletion(
-    document: vscode.TextDocument,
-    position: vscode.Position,
-    token: vscode.CancellationToken,
-  ): Promise;
-}
-
 export * from './manuallyCodeCompletionStrategy';
 export * from './autoCodeCompletionStrategy';
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/manuallyCodeCompletionStrategy.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/manuallyCodeCompletionStrategy.ts
index 69fa990d..ba058cf3 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/manuallyCodeCompletionStrategy.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/strategies/manuallyCodeCompletionStrategy.ts
@@ -1,7 +1,11 @@
 import * as vscode from 'vscode';
 
-import type { LoadedModelServices, ModelServiceType } from '../../../types';
-import { CompletionStrategy } from './index';
+import type {
+  CodeLanguageId,
+  CompletionStrategy,
+  LoadedModelServices,
+  ModelServiceType,
+} from '../../../types';
 import {
   CHAIN_OF_THOUGHT,
   FEW_SHOT_EXAMPLES,
@@ -11,7 +15,6 @@ import {
   MAIN_PROMPT_TEMPLATE,
   SYSTEM_PROMPT,
 } from '../constants';
-import { CodeLanguageId } from '../types';
 import { HistoryManager, SettingsManager } from '../../../api';
 import { StatusBarManager } from '../ui/statusBarManager';
 import { postProcessCompletion } from '../utils';
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/types/CodeLanguageId.d.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/types/codeLanguageId.d.ts
similarity index 100%
rename from VSCodeExtension/code-brt/src/services/codeCompletion/types/CodeLanguageId.d.ts
rename to VSCodeExtension/code-brt/src/services/codeCompletion/types/codeLanguageId.d.ts
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/types/completionStrategy.d.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/types/completionStrategy.d.ts
new file mode 100644
index 00000000..68c7d1c8
--- /dev/null
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/types/completionStrategy.d.ts
@@ -0,0 +1,9 @@
+import vscode from 'vscode';
+
+export type CompletionStrategy = {
+  provideCompletion(
+    document: vscode.TextDocument,
+    position: vscode.Position,
+    token: vscode.CancellationToken,
+  ): Promise;
+};
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/types/completionTemplate.d.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/types/completionTemplate.d.ts
new file mode 100644
index 00000000..76135670
--- /dev/null
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/types/completionTemplate.d.ts
@@ -0,0 +1,15 @@
+import { ConversationModelAdvanceSettings } from '../../../types';
+
+export type CompletionTemplate = {
+  template:
+    | string
+    | ((
+        prefix: string,
+        suffix: string,
+        filepath: string,
+        language: string,
+      ) => string);
+  completionOptions?: Partial<
+    Omit
+  >;
+};
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/types/index.d.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/types/index.d.ts
index e49cc98b..3074e641 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/types/index.d.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/types/index.d.ts
@@ -1,2 +1,4 @@
-export type * from './CodeLanguageId';
+export type * from './codeLanguageId';
+export type * from './completionStrategy';
+export type * from './completionTemplate';
 export type * from './manuallyCodeComplete';
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/utils/getTemplateForModel.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/utils/getTemplateForModel.ts
new file mode 100644
index 00000000..a9caa26f
--- /dev/null
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/utils/getTemplateForModel.ts
@@ -0,0 +1,31 @@
+import { CompletionTemplate } from '../types';
+import { HOLE_FILLER_TEMPLATE } from '../constants';
+
+export const getTemplateForModel = (modelName: string): CompletionTemplate => {
+  const lowerCaseModel = modelName.toLowerCase();
+
+  if (lowerCaseModel.includes('qwen') && lowerCaseModel.includes('coder')) {
+    return HOLE_FILLER_TEMPLATE.qwenCoderFimTemplate;
+  }
+
+  if (
+    lowerCaseModel.includes('starcoder') ||
+    lowerCaseModel.includes('star-coder')
+  ) {
+    return HOLE_FILLER_TEMPLATE.starCoderFimTemplate;
+  }
+
+  if (lowerCaseModel.includes('codestral')) {
+    return HOLE_FILLER_TEMPLATE.codestralFimTemplate;
+  }
+
+  if (lowerCaseModel.includes('codellama')) {
+    return HOLE_FILLER_TEMPLATE.codeLlamaFimTemplate;
+  }
+
+  if (lowerCaseModel.includes('deepseek')) {
+    return HOLE_FILLER_TEMPLATE.deepseekFimTemplate;
+  }
+
+  return HOLE_FILLER_TEMPLATE.stableCodeFimTemplate;
+};
diff --git a/VSCodeExtension/code-brt/src/services/codeCompletion/utils/index.ts b/VSCodeExtension/code-brt/src/services/codeCompletion/utils/index.ts
index 393b17e5..8630b906 100644
--- a/VSCodeExtension/code-brt/src/services/codeCompletion/utils/index.ts
+++ b/VSCodeExtension/code-brt/src/services/codeCompletion/utils/index.ts
@@ -1 +1,2 @@
+export * from './getTemplateForModel';
 export * from './postProcessCompletion';
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/anthropicService.ts b/VSCodeExtension/code-brt/src/services/languageModel/anthropicService.ts
index 94f74128..8019270b 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/anthropicService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/anthropicService.ts
@@ -90,6 +90,7 @@ export class AnthropicService extends AbstractLanguageModelService {
           : undefined,
       generationConfig: {
         max_tokens: advanceSettings.maxTokens ?? 4096,
+        stop_sequences: advanceSettings.stop,
         ...generationConfig,
       },
     };
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/base/abstractOpenaiLikeService.ts b/VSCodeExtension/code-brt/src/services/languageModel/base/abstractOpenaiLikeService.ts
index 98e4d8ed..06432304 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/base/abstractOpenaiLikeService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/base/abstractOpenaiLikeService.ts
@@ -53,6 +53,7 @@ export abstract class AbstractOpenaiLikeService extends AbstractLanguageModelSer
         top_p: advanceSettings.topP,
         presence_penalty: advanceSettings.presencePenalty,
         frequency_penalty: advanceSettings.frequencyPenalty,
+        stop: advanceSettings.stop,
       },
     };
   }
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/cohereService.ts b/VSCodeExtension/code-brt/src/services/languageModel/cohereService.ts
index 7aee1fd3..16aaa6c4 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/cohereService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/cohereService.ts
@@ -73,6 +73,7 @@ export class CohereService extends AbstractLanguageModelService {
         frequencyPenalty: advanceSettings.frequencyPenalty
           ? (advanceSettings.frequencyPenalty + 2) / 4
           : undefined,
+        stopSequences: advanceSettings.stop,
       },
     };
   }
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/geminiService.ts b/VSCodeExtension/code-brt/src/services/languageModel/geminiService.ts
index 26aadf91..4530cf03 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/geminiService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/geminiService.ts
@@ -111,6 +111,7 @@ export class GeminiService extends AbstractLanguageModelService {
         temperature: advanceSettings.temperature,
         topP: advanceSettings.topP,
         topK: advanceSettings.topK,
+        stopSequences: advanceSettings.stop,
       },
     };
   }
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/huggingFaceService.ts b/VSCodeExtension/code-brt/src/services/languageModel/huggingFaceService.ts
index fe85ee0d..e1c24296 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/huggingFaceService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/huggingFaceService.ts
@@ -64,6 +64,7 @@ export class HuggingFaceService extends AbstractLanguageModelService {
         top_p: advanceSettings.topP,
         presence_penalty: advanceSettings.presencePenalty,
         frequency_penalty: advanceSettings.frequencyPenalty,
+        stop: advanceSettings.stop,
       },
     };
   }
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts b/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts
index c7464f8d..ba9e2c34 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/ollamaService.ts
@@ -62,6 +62,7 @@ export class OllamaService extends AbstractLanguageModelService {
         top_k: advanceSettings.topK,
         presence_penalty: advanceSettings.presencePenalty,
         frequency_penalty: advanceSettings.frequencyPenalty,
+        stop: advanceSettings.stop,
       },
     };
   }
diff --git a/VSCodeExtension/code-brt/src/services/languageModel/types/languageModelService.d.ts b/VSCodeExtension/code-brt/src/services/languageModel/types/languageModelService.d.ts
index 83e91636..6464cf69 100644
--- a/VSCodeExtension/code-brt/src/services/languageModel/types/languageModelService.d.ts
+++ b/VSCodeExtension/code-brt/src/services/languageModel/types/languageModelService.d.ts
@@ -38,18 +38,6 @@ type GetResponseOptions = {
   toolCallResponse?: ToolCallResponse;
 };
 
-export interface GetResponseOptionsWithCompletion extends GetResponseOptions {
-  completionOptions?: Partial<{
-    maxTokens?: number;
-    temperature?: number;
-    topP?: number;
-    topK?: number;
-    presencePenalty?: number;
-    frequencyPenalty?: number;
-    stop?: string | string[];
-  }>;
-}
-
 export type LanguageModelService = {
   /**
    * Update the available models
diff --git a/VSCodeExtension/code-brt/src/types/conversationHistory.d.ts b/VSCodeExtension/code-brt/src/types/conversationHistory.d.ts
index dd6dcf03..9a44b8a5 100644
--- a/VSCodeExtension/code-brt/src/types/conversationHistory.d.ts
+++ b/VSCodeExtension/code-brt/src/types/conversationHistory.d.ts
@@ -75,6 +75,7 @@ export type ConversationModelAdvanceSettings = {
   topK: number | undefined;
   presencePenalty: number | undefined;
   frequencyPenalty: number | undefined;
+  stop: string[] | undefined;
 };
 
 /**
diff --git a/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar.tsx b/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar.tsx
index f440d6bc..b888b362 100644
--- a/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar.tsx
+++ b/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar.tsx
@@ -28,6 +28,7 @@ const DEFAULT_ADVANCE_SETTINGS: ConversationModelAdvanceSettings = {
   topK: undefined,
   presencePenalty: undefined,
   frequencyPenalty: undefined,
+  stop: undefined,
 };
 
 export type ModelAdvanceSettingsProps = {
diff --git a/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar/ModelAdvanceSettingFormItem.tsx b/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar/ModelAdvanceSettingFormItem.tsx
index b26f6417..efb94fd1 100644
--- a/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar/ModelAdvanceSettingFormItem.tsx
+++ b/VSCodeExtension/code-brt/src/views/components/ChatActivityBar/ModelAdvanceSettingBar/ModelAdvanceSettingFormItem.tsx
@@ -63,6 +63,29 @@ export const ModelAdvanceSettingFormItem: React.FC<
           placeholder='Enter system prompt'
           autoSize={{ minRows: 2, maxRows: 10 }}
         />
+      ) : settingName === 'stop' ? (
+        
+          
+            
+                handleInputChange(settingName, e.target.value.split('\n'))
+              }
+              placeholder='Enter stop sequence separated by new line'
+              autoSize={{ minRows: 2, maxRows: 10 }}
+            />
+          
+          
+            
+