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

Update Embedding Cache Sent from the engine #254

Merged
merged 4 commits into from
Apr 21, 2024
Merged
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
17 changes: 15 additions & 2 deletions vscode/src/providers/chat_view_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,24 @@ export class FlutterGPTViewProvider implements vscode.WebviewViewProvider {
task.sendStepResponse(message, {});
this._view?.webview.postMessage({ type: 'loaderUpdate', value: JSON.stringify(message?.params?.args) });
});

task.onProcessStep('cache', async (message) => {
const cache = await CacheManager.getInstance().getGeminiCache();
task.sendStepResponse(message, { value: cache });
});
task.onProcessStep('update_cache', async (message) => {
const embd = JSON.parse(message.params.args.embeddings);
var cacheMap: { [filePath: string]: { codehash: string, embedding: { values: number[] } } } = {};

// Iterate over each object in the list
for (const cacheItem of embd) {
// Extract filePath from the keys of each object in the list
const filePath = Object.keys(cacheItem)[0];

// Add the extracted object to the map
cacheMap[filePath] = cacheItem[filePath];
}
await CacheManager.getInstance().setGeminiCache(cacheMap);
});
task.onProcessStep('workspace_details', async (message) => {
const workspaceFolder = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0];
if (!workspaceFolder) {
Expand All @@ -243,7 +256,7 @@ export class FlutterGPTViewProvider implements vscode.WebviewViewProvider {
}
task.sendStepResponse(message, { path: workspaceFolder.uri.fsPath });
});

task.onProcessStep('replace_in_file', async (message) => {
const { originalCode, path, optimizedCode } = message.params.args.file;
const editor = vscode.window.activeTextEditor;
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/repository/gemini-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class GeminiRepository extends GenerationRepository {
constructor(apiKey: string) {
super(apiKey);
this.genAI = new GoogleGenerativeAI(apiKey);
this.migrateCache();
// this.migrateCache();
GeminiRepository._instance = this;
}

Expand Down
15 changes: 10 additions & 5 deletions vscode/src/utilities/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,24 @@ export class CacheManager {
}
// Get all the flutter projects in the workspace
const flutterProjects = pubspecs.map((uri) => uri.fsPath);
const cache: { [flutterProject: string]: { [filePath: string]: { codehash: string, embedding: ContentEmbedding } } } = {};

// ITERATE OVER ALL THE FILES IN THE CACHE
// Find the flutter project for the file
// Add the file to the cache of that flutter project
for (const filePath in cacheData) {
const parentProjectPath = this.findParentFlutterProject(filePath, flutterProjects);
if (parentProjectPath) {
const key = "gemini-cache-" + computeCodehash(parentProjectPath);
await this.setGlobalValue(key, JSON.stringify(cacheData));
const key = "gemini-cache-" + (parentProjectPath);
var currentCache = this.getGlobalValue<string>(key);
if (currentCache) {
var cache = JSON.parse(currentCache);
} else {
cache = {};
}
cache[filePath] = cacheData[filePath];
await this.setGlobalValue(key, JSON.stringify(cache));
}
}

}

async getGeminiCache(): Promise<string | undefined> {
Expand All @@ -98,7 +103,7 @@ export class CacheManager {
// Return cache only for the parent flutter project of the current workspace
for (const projectPath of flutterProjects) {
const projectDir = path.dirname(projectPath);
const key = "gemini-cache-" + projectDir;
const key = "gemini-cache-" + (projectDir);
// await this.setGlobalValue<String>(key, "value");
const cacheString = await this.getGlobalValue<string>(key);
if (!cacheString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class DartCLIClient {

public connect() {
this.proc = child_process.spawn(this.executablePath, ['process']);

let buffer = '';

this.proc.stdout.on('data', (data) => {
Expand Down Expand Up @@ -169,7 +169,7 @@ export class DartCLIClient {

} if (method === 'log') {
console.log(params);
} if (method==='debug_message'){
} if (method === 'debug_message') {
console.log('debug_message: ' + params);
}
}
Expand Down
Loading