✨ subprocess method on IDE class

This commit is contained in:
Nate Sesti 2024-01-11 12:07:59 -08:00
parent ae5137398b
commit db8a335c69
6 changed files with 34 additions and 6 deletions

View file

@ -1,7 +1,9 @@
const Types = `
declare global {
import { Chunk } from "./index/chunk";
export interface LLMReturnValue {
prompt: string;
completion: string;
}
export interface ILLM extends LLMOptions {
get providerName(): ModelProvider;
@ -33,12 +35,12 @@ declare global {
streamComplete(
prompt: string,
options?: LLMFullCompletionOptions
): AsyncGenerator<string>;
): AsyncGenerator<string, LLMReturnValue>;
streamChat(
messages: ChatMessage[],
options?: LLMFullCompletionOptions
): AsyncGenerator<ChatMessage>;
): AsyncGenerator<ChatMessage, LLMReturnValue>;
chat(
messages: ChatMessage[],
@ -277,6 +279,7 @@ declare global {
): Promise<void>;
getOpenFiles(): Promise<string[]>;
getSearchResults(query: string): Promise<string>;
subprocess(command: string): Promise<[string, string]>;
// Embeddings
/**
@ -538,8 +541,7 @@ declare global {
disableIndexing?: boolean;
userToken?: string;
embeddingsProvider?: EmbeddingsProvider;
}
}
}
export {};

View file

@ -108,6 +108,10 @@ class FileSystemIde implements IDE {
return "";
}
async subprocess(command: string): Promise<[string, string]> {
return ["", ""];
}
getFilesToEmbed(providerId: string): Promise<[string, string, string][]> {
return Promise.resolve([]);
}

View file

@ -88,6 +88,10 @@ export class ExtensionIde implements IDE {
return r("getSearchResults", { query });
}
subprocess(command: string): Promise<[string, string]> {
return r("subprocess", { command });
}
getFilesToEmbed(providerId: string): Promise<[string, string, string][]> {
return r("getFilesToEmbed", { providerId });
}

1
core/index.d.ts vendored
View file

@ -279,6 +279,7 @@ export interface IDE {
): Promise<void>;
getOpenFiles(): Promise<string[]>;
getSearchResults(query: string): Promise<string>;
subprocess(command: string): Promise<[string, string]>;
// Embeddings
/**

View file

@ -330,6 +330,10 @@ export function getSidebarContent(
respond(await ide.getSearchResults(data.message.query));
break;
}
case "subprocess": {
respond(await ide.subprocess(data.message.command));
break;
}
case "getFilesToEmbed": {
let filesToEmbed = await ide.getFilesToEmbed(data.message.providerId);
respond(filesToEmbed);

View file

@ -1,3 +1,4 @@
import { exec } from "child_process";
import defaultConfig from "core/config/default";
import {
getConfigJsPath,
@ -304,6 +305,18 @@ class VsCodeIde implements IDE {
return results.join("\n\n");
}
async subprocess(command: string): Promise<[string, string]> {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
console.warn(error);
reject(stderr);
}
resolve([stdout, stderr]);
});
});
}
async getFilesToEmbed(
providerId: string
): Promise<[string, string, string][]> {