Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Wrogn template is used when two different model families used for chat and autocomplete #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/extension/src/ai/AIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as vscode from "vscode";
import { z } from "zod";
import { Logger } from "../logger";
import { ApiKeyManager } from "./ApiKeyManager";
import { EnumAsUnion } from '../types/util';

function getProviderBaseUrl(): string {
let defaultUrl = "http://localhost:8080/";
Expand Down Expand Up @@ -61,6 +62,11 @@ function getPromptTemplate() {
return ollama.prompt.Llama2;
}

enum MODE_PURPOSE {
CHAT = "chat",
AUTOCOMPLETE = "autocomplete"
};

export class AIClient {
private readonly apiKeyManager: ApiKeyManager;
private readonly logger: Logger;
Expand All @@ -76,7 +82,7 @@ export class AIClient {
this.logger = logger;
}

public getModel(feature: string = "chat"): string {
public getModel(feature: EnumAsUnion<typeof MODE_PURPOSE>): string {
if (feature != "chat") {
this.logger.log(["Autocomplete Model: ", getAutoCompleteModel()]);
return getAutoCompleteModel();
Expand Down Expand Up @@ -120,7 +126,7 @@ export class AIClient {
.CompletionTextGenerator({
api: await this.getProviderApiConfiguration(),
promptTemplate: getPromptTemplate(),
model: this.getModel(),
model: this.getModel("chat"),
maxGenerationTokens: maxTokens,
stopSequences: stop,
temperature,
Expand Down
2 changes: 1 addition & 1 deletion lib/extension/src/autocomplete/AutoCompleteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class AutoCompleteProvider
const additionalContext = this.getAdditionalContext(document);
const { prompt, stop } =
this.autoCompleteTemplateProvider.getAutoCompletePrompt(
this.ai.getModel(),
this.ai.getModel("autocomplete"),
{ additionalContext, prefix, suffix }
);
const response = await this.ai.generateText({
Expand Down
16 changes: 16 additions & 0 deletions lib/extension/src/types/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type StringValues<T> = {
[K in keyof T]: T[K] extends string ? T[K] : never;
}[keyof T];

type NumberValues<T> = {
[K in keyof T]: T[K] extends number ? T[K] : never;
}[keyof T];

type SymbolValues<T> = {
[K in keyof T]: T[K] extends symbol ? T[K] : never;
}[keyof T];

/**
* Usage : type EnumValues = EnumAsUnion<typeof anEnum>
*/
export type EnumAsUnion<T> = `${StringValues<T>}` | NumberValues<T> | SymbolValues<T>;