Skip to content

Commit c5a003a

Browse files
authored
Merge pull request #67 from neatwork-ai/hotfix-lazy-api-key-model-setup
Hotfix lazy api key model setup
2 parents c0e8798 + 8a4ef98 commit c5a003a

File tree

11 files changed

+117
-40
lines changed

11 files changed

+117
-40
lines changed

bin/publish.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Get the directory
4+
DIR="$(dirname "$0")"
5+
6+
# Run the first script
7+
bash "$DIR/build_wasm.sh"
8+
9+
# Check if the first script ran successfully
10+
if [ $? -eq 0 ]; then
11+
echo "Built WASM Library successfully"
12+
else
13+
echo "WASM Lib failed"
14+
exit 1
15+
fi
16+
17+
# Run the second script
18+
bash "$DIR/build_webview.sh"
19+
20+
# Check if the second script ran successfully
21+
if [ $? -eq 0 ]; then
22+
echo "Built VSCE successfully"
23+
else
24+
echo "VSCE failed"
25+
exit 1
26+
fi
27+
28+
#!/bin/sh
29+
30+
# Navigate to the wasm-lib directory
31+
cd vsce/
32+
33+
# Compile the wasm library (assuming you're using wasm-pack)
34+
vsce publish
35+
36+
cd ../
37+
38+
39+
# # Check if the second script ran successfully
40+
# if [ $? -eq 0 ]; then
41+
# echo "Built VSCE successfully"
42+
# else
43+
# echo "VSCE failed"
44+
# exit 1
45+
# fi
46+
47+
echo "Publishing complete"

crates/neatcoder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "neatcoder"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55

66
[lib]

vsce/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to the "neatcoder" extension will be documented in this file
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
## [0.2.1] - 05/11/2023
8+
9+
### Changed
10+
- Lazily setup API Keys and LLM Model
11+
712
## [0.2.0] - 03/11/2023
813

914
### Added

vsce/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Turn your IDE into an AI Software Engineer with Neatcoder 🧞‍♂️
44

5-
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.
5+
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.
66

77
## Features
88

@@ -83,7 +83,7 @@ TLDR:
8383
1. Are solely stored locally;
8484
2. We do not store nor have access to them.
8585
2. We collect analytics to learn how users are using the extension, for the purpose of improving the product
86-
3. The data policy might change in future versions
86+
3. The data policy might change in future versions as the product evolves
8787

8888
You can find the full policy at [https://www.neatwork.ai/privacy](https://www.neatwork.ai/privacy)
8989

vsce/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "neatcoder",
33
"displayName": "Neatwork AI - GPT4 on Steroids",
44
"description": "Turn your IDE into an AI Sofware engineer.",
5-
"version": "0.2.0",
5+
"version": "0.2.1",
66
"publisher": "NeatworkAi",
77
"repository": {
88
"url": "https://github.com/neatwork-ai/neatcoder-issues.git",

vsce/src/chat/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getChatById,
77
getOrCreateConfigPath,
88
getOrInitConfig,
9+
getOrSetApiKey,
910
getOrSetModelVersion,
1011
getRoot,
1112
storeChat,
@@ -137,6 +138,8 @@ const setupWebviewSockets = async (
137138
const msgs: Array<wasm.Message> = message.msgs;
138139
const isFirst = msgs.length === 1 ? true : false;
139140

141+
await getOrSetApiKey();
142+
140143
promptLLM(panel, message);
141144

142145
if (isFirst) {

vsce/src/chat/handlers.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import * as https from "https";
55
import * as url from "url";
66
import { MessageBuffer } from "../utils/httpClient";
77

8-
export function buildRequest(
8+
export async function buildRequest(
99
msgs: Array<wasm.Message>,
1010
stream: boolean
11-
): [any, any] {
12-
const apiKey = getOrSetApiKey();
11+
): Promise<[any, any]> {
12+
console.log("GOING FOR IT");
13+
const apiKey = await getOrSetApiKey();
14+
console.log("Skipping API KEY");
1315

1416
try {
1517
console.log("Messages: " + JSON.stringify(msgs.map((msg) => msg.payload)));
@@ -31,7 +33,7 @@ export async function promptLLM(
3133
const msgs: Array<wasm.Message> = message.msgs;
3234
const stream = message.stream;
3335

34-
const [apiKey, body] = buildRequest(msgs, stream);
36+
const [apiKey, body] = await buildRequest(msgs, stream);
3537

3638
return new Promise((resolve, reject) => {
3739
let messageBuffer = new MessageBuffer();

vsce/src/extension.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
TasksCompletedProvider,
2323
} from "./taskPool";
2424
import { initCodeBase, appDataManager, setupDotNeatWatcher } from "./core";
25-
import { getOrSetApiKey, initStatusBar, initLogger, logger } from "./utils";
25+
import { initStatusBar, initLogger, logger } from "./utils";
2626
import { ChatProvider, initChat, setupChatWatcher } from "./chat";
2727
import { getOrSetModelVersion, setModelVersion } from "./utils/utils";
2828
import { ChatItem } from "./chat/providers";
@@ -45,7 +45,6 @@ export async function activate(context: vscode.ExtensionContext) {
4545

4646
initStatusBar(context);
4747
initLogger(context);
48-
getOrSetApiKey();
4948

5049
// Create the output channel for logging
5150
logger.appendLine("[INFO] Extension Name: Neatcoder");
@@ -64,9 +63,9 @@ export async function activate(context: vscode.ExtensionContext) {
6463
// Read or Initialize Application state
6564

6665
let appManager = new appDataManager(jobQueueProvider, auditTrailProvider);
67-
let llmParams = await getLLMParams();
66+
// let llmParams = await getLLMParams();
6867

69-
logger.appendLine("[INFO] Extension Activated. llmParams: " + llmParams);
68+
// logger.appendLine("[INFO] Extension Activated. llmParams: " + llmParams);
7069

7170
// === Setup File Watchers ===
7271

vsce/src/utils/httpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let isCodeBlockEnded = false;
2424
* @return {Promise<object>} - A promise that resolves to the response object from the OpenAI API.
2525
*/
2626
export async function makeRequest(body: string): Promise<object> {
27-
const apiKey = getOrSetApiKey();
27+
const apiKey = await getOrSetApiKey();
2828

2929
try {
3030
const response = await fetch("https://api.openai.com/v1/chat/completions", {
@@ -61,14 +61,14 @@ export async function makeStreamingRequest(
6161
activeTextDocument: TextDocument
6262
): Promise<void> {
6363
cleanup();
64+
const apiKey = await getOrSetApiKey();
6465

6566
return new Promise((resolve, reject) => {
6667
// let responseLog: string[] = []; // TODO: Only debug
6768
let streamedTokens = 0;
6869

6970
let messageBuffer = new MessageBuffer();
7071

71-
const apiKey = getOrSetApiKey();
7272
try {
7373
const urlString = "https://api.openai.com/v1/chat/completions";
7474
const parsedUrl = url.parse(urlString);

vsce/src/utils/utils.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,48 @@ export function getFilename(filepath: string): string {
230230
return parts[parts.length - 1];
231231
}
232232

233-
export function getOrSetApiKey(): any {
234-
let config = vscode.workspace.getConfiguration("extension");
235-
let apiKey = config.get("apiKey");
236-
237-
if (!apiKey) {
238-
vscode.window
239-
.showInputBox({
240-
prompt: "Please enter your API key",
241-
ignoreFocusOut: true,
242-
})
243-
.then((value) => {
244-
if (value) {
245-
config.update("apiKey", value, vscode.ConfigurationTarget.Global);
246-
vscode.window.showInformationMessage("API key saved!");
247-
} else {
248-
// Handle the case where the input box was dismissed without entering a value
249-
vscode.window.showErrorMessage(
250-
"API key is required to use this extension."
251-
);
252-
}
253-
});
254-
}
255-
256-
return apiKey;
233+
export function getOrSetApiKey(): Promise<any> {
234+
return new Promise((resolve, reject) => {
235+
let config = vscode.workspace.getConfiguration("extension");
236+
let apiKey = config.get("apiKey");
237+
238+
if (apiKey) {
239+
// If the API key is already set, resolve the Promise immediately.
240+
resolve(apiKey);
241+
} else {
242+
// Show the input box to the user to enter the API key.
243+
vscode.window
244+
.showInputBox({
245+
prompt: "Please enter your API key",
246+
ignoreFocusOut: true,
247+
})
248+
.then((value) => {
249+
if (value) {
250+
// Update the configuration with the new API key.
251+
config
252+
.update("apiKey", value, vscode.ConfigurationTarget.Global)
253+
.then(
254+
() => {
255+
vscode.window.showInformationMessage("API key saved!");
256+
resolve(value); // Resolve the Promise with the new API key.
257+
},
258+
(error) => {
259+
vscode.window.showErrorMessage(
260+
`Failed to save API key: ${error}`
261+
);
262+
reject(error); // Reject the Promise if there was an error saving the API key.
263+
}
264+
);
265+
} else {
266+
// Handle the case where the input box was dismissed without entering a value.
267+
vscode.window.showErrorMessage(
268+
"API key is required to use this extension."
269+
);
270+
reject("API key not provided."); // Reject the Promise as no API key was provided.
271+
}
272+
});
273+
}
274+
});
257275
}
258276

259277
export async function getOrSetModelVersion(): Promise<wasm.OpenAIModels | null> {
@@ -263,7 +281,10 @@ export async function getOrSetModelVersion(): Promise<wasm.OpenAIModels | null>
263281
if (!modelVersion) {
264282
const value = await vscode.window.showQuickPick(
265283
["gpt-3.5-turbo-16k", "gpt-4"],
266-
{ canPickMany: false }
284+
{
285+
canPickMany: false,
286+
placeHolder: "Select an OpenAI model", // This is the placeholder text
287+
}
267288
);
268289
if (value) {
269290
await config.update(

webview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chat-view",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"private": true,
55
"dependencies": {
66
"@testing-library/jest-dom": "^5.17.0",

0 commit comments

Comments
 (0)