diff --git a/bin/publish.sh b/bin/publish.sh new file mode 100755 index 0000000..d78f7be --- /dev/null +++ b/bin/publish.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Get the directory +DIR="$(dirname "$0")" + +# Run the first script +bash "$DIR/build_wasm.sh" + +# Check if the first script ran successfully +if [ $? -eq 0 ]; then + echo "Built WASM Library successfully" +else + echo "WASM Lib failed" + exit 1 +fi + +# Run the second script +bash "$DIR/build_webview.sh" + +# Check if the second script ran successfully +if [ $? -eq 0 ]; then + echo "Built VSCE successfully" +else + echo "VSCE failed" + exit 1 +fi + +#!/bin/sh + +# Navigate to the wasm-lib directory +cd vsce/ + +# Compile the wasm library (assuming you're using wasm-pack) +vsce publish + +cd ../ + + +# # Check if the second script ran successfully +# if [ $? -eq 0 ]; then +# echo "Built VSCE successfully" +# else +# echo "VSCE failed" +# exit 1 +# fi + +echo "Publishing complete" diff --git a/crates/neatcoder/Cargo.toml b/crates/neatcoder/Cargo.toml index 624d08b..38863ff 100644 --- a/crates/neatcoder/Cargo.toml +++ b/crates/neatcoder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "neatcoder" -version = "0.2.0" +version = "0.2.1" edition = "2021" [lib] diff --git a/vsce/CHANGELOG.md b/vsce/CHANGELOG.md index 2e34f18..cead29f 100644 --- a/vsce/CHANGELOG.md +++ b/vsce/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to the "neatcoder" extension will be documented in this file Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [0.2.1] - 05/11/2023 + +### Changed +- Lazily setup API Keys and LLM Model + ## [0.2.0] - 03/11/2023 ### Added diff --git a/vsce/README.md b/vsce/README.md index e5c3cf0..fc5efa4 100644 --- a/vsce/README.md +++ b/vsce/README.md @@ -2,7 +2,7 @@ Turn your IDE into an AI Software Engineer with Neatcoder 🧞‍♂️ -Neatwork AI enhances VS Code by integrating advanced AI capabilities. It provides you with the ability to dynamically scaffold entire codebases from a simple project description. Given that most software interacts with other software, Neatwork AI allows you to make its AI aware of external interfaces the software ought to communicate with. +Neatwork AI enhances VS Code by integrating advanced AI capabilities. It provides you with the ability to dynamically scaffold entire codebases from a simple project description. Given that most software interacts with other software, Neatwork AI allows you to make its AI aware of external interfaces, such as data models from your Databases or endpoints from your APIs. ## Features @@ -83,7 +83,7 @@ TLDR: 1. Are solely stored locally; 2. We do not store nor have access to them. 2. We collect analytics to learn how users are using the extension, for the purpose of improving the product -3. The data policy might change in future versions +3. The data policy might change in future versions as the product evolves You can find the full policy at [https://www.neatwork.ai/privacy](https://www.neatwork.ai/privacy) diff --git a/vsce/package.json b/vsce/package.json index df63006..4df0b80 100644 --- a/vsce/package.json +++ b/vsce/package.json @@ -2,7 +2,7 @@ "name": "neatcoder", "displayName": "Neatwork AI - GPT4 on Steroids", "description": "Turn your IDE into an AI Sofware engineer.", - "version": "0.2.0", + "version": "0.2.1", "publisher": "NeatworkAi", "repository": { "url": "https://github.com/neatwork-ai/neatcoder-issues.git", diff --git a/vsce/src/chat/commands.ts b/vsce/src/chat/commands.ts index 4ca0696..eaf9f00 100644 --- a/vsce/src/chat/commands.ts +++ b/vsce/src/chat/commands.ts @@ -6,6 +6,7 @@ import { getChatById, getOrCreateConfigPath, getOrInitConfig, + getOrSetApiKey, getOrSetModelVersion, getRoot, storeChat, @@ -137,6 +138,8 @@ const setupWebviewSockets = async ( const msgs: Array = message.msgs; const isFirst = msgs.length === 1 ? true : false; + await getOrSetApiKey(); + promptLLM(panel, message); if (isFirst) { diff --git a/vsce/src/chat/handlers.ts b/vsce/src/chat/handlers.ts index f35f49d..ea40542 100644 --- a/vsce/src/chat/handlers.ts +++ b/vsce/src/chat/handlers.ts @@ -5,11 +5,13 @@ import * as https from "https"; import * as url from "url"; import { MessageBuffer } from "../utils/httpClient"; -export function buildRequest( +export async function buildRequest( msgs: Array, stream: boolean -): [any, any] { - const apiKey = getOrSetApiKey(); +): Promise<[any, any]> { + console.log("GOING FOR IT"); + const apiKey = await getOrSetApiKey(); + console.log("Skipping API KEY"); try { console.log("Messages: " + JSON.stringify(msgs.map((msg) => msg.payload))); @@ -31,7 +33,7 @@ export async function promptLLM( const msgs: Array = message.msgs; const stream = message.stream; - const [apiKey, body] = buildRequest(msgs, stream); + const [apiKey, body] = await buildRequest(msgs, stream); return new Promise((resolve, reject) => { let messageBuffer = new MessageBuffer(); diff --git a/vsce/src/extension.ts b/vsce/src/extension.ts index 6982175..4b19514 100644 --- a/vsce/src/extension.ts +++ b/vsce/src/extension.ts @@ -22,7 +22,7 @@ import { TasksCompletedProvider, } from "./taskPool"; import { initCodeBase, appDataManager, setupDotNeatWatcher } from "./core"; -import { getOrSetApiKey, initStatusBar, initLogger, logger } from "./utils"; +import { initStatusBar, initLogger, logger } from "./utils"; import { ChatProvider, initChat, setupChatWatcher } from "./chat"; import { getOrSetModelVersion, setModelVersion } from "./utils/utils"; import { ChatItem } from "./chat/providers"; @@ -45,7 +45,6 @@ export async function activate(context: vscode.ExtensionContext) { initStatusBar(context); initLogger(context); - getOrSetApiKey(); // Create the output channel for logging logger.appendLine("[INFO] Extension Name: Neatcoder"); @@ -64,9 +63,9 @@ export async function activate(context: vscode.ExtensionContext) { // Read or Initialize Application state let appManager = new appDataManager(jobQueueProvider, auditTrailProvider); - let llmParams = await getLLMParams(); + // let llmParams = await getLLMParams(); - logger.appendLine("[INFO] Extension Activated. llmParams: " + llmParams); + // logger.appendLine("[INFO] Extension Activated. llmParams: " + llmParams); // === Setup File Watchers === diff --git a/vsce/src/utils/httpClient.ts b/vsce/src/utils/httpClient.ts index 6d32746..40859bb 100644 --- a/vsce/src/utils/httpClient.ts +++ b/vsce/src/utils/httpClient.ts @@ -24,7 +24,7 @@ let isCodeBlockEnded = false; * @return {Promise} - A promise that resolves to the response object from the OpenAI API. */ export async function makeRequest(body: string): Promise { - const apiKey = getOrSetApiKey(); + const apiKey = await getOrSetApiKey(); try { const response = await fetch("https://api.openai.com/v1/chat/completions", { @@ -61,6 +61,7 @@ export async function makeStreamingRequest( activeTextDocument: TextDocument ): Promise { cleanup(); + const apiKey = await getOrSetApiKey(); return new Promise((resolve, reject) => { // let responseLog: string[] = []; // TODO: Only debug @@ -68,7 +69,6 @@ export async function makeStreamingRequest( let messageBuffer = new MessageBuffer(); - const apiKey = getOrSetApiKey(); try { const urlString = "https://api.openai.com/v1/chat/completions"; const parsedUrl = url.parse(urlString); diff --git a/vsce/src/utils/utils.ts b/vsce/src/utils/utils.ts index 4684fcb..9688d8e 100644 --- a/vsce/src/utils/utils.ts +++ b/vsce/src/utils/utils.ts @@ -230,30 +230,48 @@ export function getFilename(filepath: string): string { return parts[parts.length - 1]; } -export function getOrSetApiKey(): any { - let config = vscode.workspace.getConfiguration("extension"); - let apiKey = config.get("apiKey"); - - if (!apiKey) { - vscode.window - .showInputBox({ - prompt: "Please enter your API key", - ignoreFocusOut: true, - }) - .then((value) => { - if (value) { - config.update("apiKey", value, vscode.ConfigurationTarget.Global); - vscode.window.showInformationMessage("API key saved!"); - } else { - // Handle the case where the input box was dismissed without entering a value - vscode.window.showErrorMessage( - "API key is required to use this extension." - ); - } - }); - } - - return apiKey; +export function getOrSetApiKey(): Promise { + return new Promise((resolve, reject) => { + let config = vscode.workspace.getConfiguration("extension"); + let apiKey = config.get("apiKey"); + + if (apiKey) { + // If the API key is already set, resolve the Promise immediately. + resolve(apiKey); + } else { + // Show the input box to the user to enter the API key. + vscode.window + .showInputBox({ + prompt: "Please enter your API key", + ignoreFocusOut: true, + }) + .then((value) => { + if (value) { + // Update the configuration with the new API key. + config + .update("apiKey", value, vscode.ConfigurationTarget.Global) + .then( + () => { + vscode.window.showInformationMessage("API key saved!"); + resolve(value); // Resolve the Promise with the new API key. + }, + (error) => { + vscode.window.showErrorMessage( + `Failed to save API key: ${error}` + ); + reject(error); // Reject the Promise if there was an error saving the API key. + } + ); + } else { + // Handle the case where the input box was dismissed without entering a value. + vscode.window.showErrorMessage( + "API key is required to use this extension." + ); + reject("API key not provided."); // Reject the Promise as no API key was provided. + } + }); + } + }); } export async function getOrSetModelVersion(): Promise { @@ -263,7 +281,10 @@ export async function getOrSetModelVersion(): Promise if (!modelVersion) { const value = await vscode.window.showQuickPick( ["gpt-3.5-turbo-16k", "gpt-4"], - { canPickMany: false } + { + canPickMany: false, + placeHolder: "Select an OpenAI model", // This is the placeholder text + } ); if (value) { await config.update( diff --git a/webview/package.json b/webview/package.json index 767b893..15e1d9c 100644 --- a/webview/package.json +++ b/webview/package.json @@ -1,6 +1,6 @@ { "name": "chat-view", - "version": "0.2.0", + "version": "0.2.1", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.17.0",