Skip to content

Commit

Permalink
Change embedding model from Xenova/all-MiniLM-L6-v2 to text-embedding…
Browse files Browse the repository at this point in the history
…-004

Refactor ICodeRepository interface and related methods
Update error message display in utils.ts
Modify extension.ts to include database connection and code indexing
Implement new CodeIndexingService and update related services
  • Loading branch information
Olasunkanmi Oyinlola authored and Olasunkanmi Oyinlola committed Jan 22, 2025
1 parent aeb0456 commit 35ea6d5
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 360 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ node_modules
.sentryclirc
config.ts
patterns
webviewUi/dist
webviewUi/dist
samples
2 changes: 1 addition & 1 deletion src/application/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ export const EmbeddingsConfig = {
maxRetries: 3,
retryDelay: 1000,
rateLimit: 1500,
embeddingModel: "Xenova/all-MiniLM-L6-v2",
embeddingModel: "text-embedding-004",
textModel: "gemini-1.5-flash",
};
10 changes: 4 additions & 6 deletions src/application/interfaces/code.repository.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ResultSet, Row } from "@libsql/client/.";
import { ResultSet, Row } from "@libsql/client";

export interface ICodeRepository {
CreateTable(values: string): Promise<ResultSet[] | undefined>;
searchSimilarFunctions(
queryEmbeddings: number[],
limit: number,
): Promise<Row[] | undefined>;
createFunctionsTable(): Promise<ResultSet | undefined>;
insertFunctions(values: string): Promise<ResultSet | undefined>;
searchSimilarFunctions(queryEmbeddings: number[], limit: number): Promise<Row[] | undefined>;
}
15 changes: 4 additions & 11 deletions src/application/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const formatText = (text?: string): string => {
return "";
};

export const getConfigValue: GetConfigValueType<any> = <T>(
key: string,
): T | undefined => {
export const getConfigValue: GetConfigValueType<any> = <T>(key: string): T | undefined => {
return vscode.workspace.getConfiguration().get<T>(key);
};

Expand Down Expand Up @@ -68,11 +66,7 @@ export const getGenerativeAiModel = (): string | undefined => {
return getConfigValue("generativeAi.option");
};

export function getUri(
webview: vscode.Webview,
extensionUri: vscode.Uri,
pathList: string[],
) {
export function getUri(webview: vscode.Webview, extensionUri: vscode.Uri, pathList: string[]) {
return webview.asWebviewUri(vscode.Uri.joinPath(extensionUri, ...pathList));
}

Expand All @@ -81,8 +75,7 @@ export function getUri(
// and ensure script integrity when using Content Security Policy (CSP)
export const getNonce = () => {
let text = "";
const possible =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
Expand All @@ -95,5 +88,5 @@ export const handleError = (error: unknown, message?: string): void => {
};

export const showInfoMessage = (message?: string): void => {
vscode.window.showErrorMessage(`${message}`);
vscode.window.showInformationMessage(`${message}`);
};
137 changes: 40 additions & 97 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as vscode from "vscode";
import {
APP_CONFIG,
generativeAiModels,
OLA_ACTIONS,
USER_MESSAGE,
} from "./application/constant";
import { APP_CONFIG, generativeAiModels, OLA_ACTIONS, USER_MESSAGE } from "./application/constant";
import { getConfigValue } from "./application/utils";
import { Comments } from "./events/comment";
import { ExplainCode } from "./events/explain";
Expand All @@ -22,37 +17,33 @@ import { AnthropicWebViewProvider } from "./providers/anthropic-web-view-provide
import { CodeActionsProvider } from "./providers/code-actions-provider";
import { GeminiWebViewProvider } from "./providers/gemini-web-view-provider";
import { GroqWebViewProvider } from "./providers/groq-web-view-provider";
import { CodeIndexingService } from "./services/code-indexing-service";
import { FileUploader } from "./services/file-uploader";
import { setUpGenerativeAiModel } from "./services/generative-ai-model-manager";
import { Brain } from "./services/memory";
import { TypeScriptAtsMapper } from "./services/typescript-ats.service";
import { CodeStructureMapper } from "./services/code-structure.mapper.service";
import { dbManager } from "./infrastructure/repository/data-base-manager";

const {
geminiKey,
geminiModel,
groqApiKey,
groqModel,
anthropicApiKey,
anthropicModel,
grokApiKey,
grokModel,
} = APP_CONFIG;
const { geminiKey, geminiModel, groqApiKey, groqModel, anthropicApiKey, anthropicModel, grokApiKey, grokModel } =
APP_CONFIG;

const connectDB = async () => {
await dbManager.connect("file:/Users/olasunkanmi/Documents/Github/codebuddy/patterns/dev.db");
};

export async function activate(context: vscode.ExtensionContext) {
try {
Brain.getInstance();
await connectDB();
const fileUpload = new FileUploader(context);
await fileUpload.createFile("allx.db");

const getKnowledgeBase = async () => {
const codeMapper = new TypeScriptAtsMapper();
const mappedCode = await codeMapper.buildCodebaseMap();
const ats = Object.values(mappedCode).flatMap((repo) =>
Object.values(repo.modules)
);
const mapper = new CodeStructureMapper(ats);
return mapper.normalizeData();
};
getKnowledgeBase();
const files = await fileUpload.getFiles();
const names = await fileUpload.getFileNames();
console.log(files, names);

const index = CodeIndexingService.createInstance();
const result = index.insertFunctionsinDB();
console.log(result);
const {
comment,
review,
Expand All @@ -68,52 +59,19 @@ export async function activate(context: vscode.ExtensionContext) {
generateCodeChart,
inlineChat,
} = OLA_ACTIONS;
const getComment = new Comments(
`${USER_MESSAGE} generates the code comments...`,
context
);
const getInLineChat = new InLineChat(
`${USER_MESSAGE} generates a response...`,
context
);
const generateOptimizeCode = new OptimizeCode(
`${USER_MESSAGE} optimizes the code...`,
context
);
const generateRefactoredCode = new RefactorCode(
`${USER_MESSAGE} refactors the code...`,
context
);
const explainCode = new ExplainCode(
`${USER_MESSAGE} explains the code...`,
context
);
const generateReview = new ReviewCode(
`${USER_MESSAGE} reviews the code...`,
context
);
const codeChartGenerator = new CodeChartGenerator(
`${USER_MESSAGE} creates the code chart...`,
context
);
const codePattern = new FileUploader(context);
const knowledgeBase = new ReadFromKnowledgeBase(
`${USER_MESSAGE} generate your code pattern...`,
context
);
const generateCommitMessage = new GenerateCommitMessage(
`${USER_MESSAGE} generates a commit message...`,
context
);
const generateInterviewQuestions = new InterviewMe(
`${USER_MESSAGE} generates interview questions...`,
context
);
const getComment = new Comments(`${USER_MESSAGE} generates the code comments...`, context);
const getInLineChat = new InLineChat(`${USER_MESSAGE} generates a response...`, context);
const generateOptimizeCode = new OptimizeCode(`${USER_MESSAGE} optimizes the code...`, context);
const generateRefactoredCode = new RefactorCode(`${USER_MESSAGE} refactors the code...`, context);
const explainCode = new ExplainCode(`${USER_MESSAGE} explains the code...`, context);
const generateReview = new ReviewCode(`${USER_MESSAGE} reviews the code...`, context);
const codeChartGenerator = new CodeChartGenerator(`${USER_MESSAGE} creates the code chart...`, context);
const codePattern = fileUpload;
const knowledgeBase = new ReadFromKnowledgeBase(`${USER_MESSAGE} generate your code pattern...`, context);
const generateCommitMessage = new GenerateCommitMessage(`${USER_MESSAGE} generates a commit message...`, context);
const generateInterviewQuestions = new InterviewMe(`${USER_MESSAGE} generates interview questions...`, context);

const generateUnitTests = new GenerateUnitTest(
`${USER_MESSAGE} generates unit tests...`,
context
);
const generateUnitTests = new GenerateUnitTest(`${USER_MESSAGE} generates unit tests...`, context);

const actionMap = {
[comment]: () => getComment.execute(),
Expand All @@ -123,11 +81,7 @@ export async function activate(context: vscode.ExtensionContext) {
[interviewMe]: () => generateInterviewQuestions.execute(),
[generateUnitTest]: () => generateUnitTests.execute(),
[fix]: (errorMessage: string) =>
new FixError(
`${USER_MESSAGE} finds a solution to the error...`,
context,
errorMessage
).execute(errorMessage),
new FixError(`${USER_MESSAGE} finds a solution to the error...`, context, errorMessage).execute(errorMessage),
[explain]: () => explainCode.execute(),
[pattern]: () => codePattern.uploadFileHandler(),
[knowledge]: () => knowledgeBase.execute(),
Expand All @@ -136,18 +90,17 @@ export async function activate(context: vscode.ExtensionContext) {
[inlineChat]: () => getInLineChat.execute(),
};

const subscriptions: vscode.Disposable[] = Object.entries(actionMap).map(
([action, handler]) => vscode.commands.registerCommand(action, handler)
const subscriptions: vscode.Disposable[] = Object.entries(actionMap).map(([action, handler]) =>
vscode.commands.registerCommand(action, handler)
);

const selectedGenerativeAiModel = getConfigValue("generativeAi.option");

const quickFix = new CodeActionsProvider();
const quickFixCodeAction: vscode.Disposable =
vscode.languages.registerCodeActionsProvider(
{ scheme: "file", language: "*" },
quickFix
);
const quickFixCodeAction: vscode.Disposable = vscode.languages.registerCodeActionsProvider(
{ scheme: "file", language: "*" },
quickFix
);

const modelConfigurations: {
[key: string]: {
Expand Down Expand Up @@ -180,25 +133,15 @@ export async function activate(context: vscode.ExtensionContext) {
if (selectedGenerativeAiModel in modelConfigurations) {
const modelConfig = modelConfigurations[selectedGenerativeAiModel];
const { key, model, webviewProviderClass } = modelConfig;
setUpGenerativeAiModel(
context,
model,
key,
webviewProviderClass,
subscriptions,
quickFixCodeAction
);
setUpGenerativeAiModel(context, model, key, webviewProviderClass, subscriptions, quickFixCodeAction);
}
} catch (error) {
Brain.clear();
vscode.window.showErrorMessage(
"An Error occured while setting up generative AI model"
);
vscode.window.showErrorMessage("An Error occured while setting up generative AI model");
console.log(error);
}
}

export function deactivate(context: vscode.ExtensionContext) {
//TODO once the application is rewritten in React, delete the pattern file on deactivate
context.subscriptions.forEach((subscription) => subscription.dispose());
}
Loading

0 comments on commit 35ea6d5

Please sign in to comment.