Skip to content

Commit df74da2

Browse files
authored
Merge pull request #68 from neatwork-ai/hotfix-include-webview-build
New OpenAI models
2 parents b83e48a + cdd72a7 commit df74da2

File tree

12 files changed

+137
-118
lines changed

12 files changed

+137
-118
lines changed

bin/cross_build.py

Lines changed: 90 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,90 @@
1-
import subprocess
2-
import os
3-
import shutil
4-
5-
6-
def move(src, dest):
7-
if os.path.isdir(src):
8-
shutil.move(src, dest)
9-
else:
10-
shutil.copy2(src, dest)
11-
os.remove(src)
12-
13-
14-
def run_command(cmd, working_dir=None):
15-
print(f"Executing in directory: {working_dir}")
16-
print(f"Executing command: {cmd}")
17-
18-
process = subprocess.Popen(
19-
cmd, shell=True,
20-
stdout=subprocess.PIPE,
21-
stderr=subprocess.STDOUT,
22-
cwd=working_dir,
23-
text=True,
24-
encoding='utf-8'
25-
)
26-
27-
# Stream output in real-time
28-
while True:
29-
output = process.stdout.readline()
30-
if output == '' and process.poll() is not None:
31-
break
32-
if output:
33-
print(output.strip())
34-
35-
rc = process.poll()
36-
return rc
37-
38-
39-
def build():
40-
script_dir = os.path.dirname(os.path.realpath(__file__))
41-
project_root = os.path.dirname(script_dir)
42-
43-
vsce_dir = os.path.join(project_root, 'vsce')
44-
crates_dir = os.path.join(project_root, 'crates', 'neatcoder')
45-
webview_dir = os.path.join(project_root, 'webview')
46-
47-
# Building WASM
48-
run_command("wasm-pack build --target nodejs --dev",
49-
working_dir=crates_dir)
50-
51-
# Workaround: Copy neatcoder.d.ts to expected location by create_interface.py
52-
dest_dir = os.path.join(project_root, "pkg")
53-
# exist_ok=True ensures no error if directory already exists
54-
os.makedirs(dest_dir, exist_ok=True)
55-
56-
shutil.copy2(os.path.join(crates_dir, "pkg", "neatcoder.d.ts"),
57-
os.path.join(dest_dir, "neatcoder.d.ts"))
58-
59-
run_command("python3 bin/create_interface.py", working_dir=project_root)
60-
61-
# Move the output file to desired location
62-
move(os.path.join(project_root, "neatcoderInterface.d.ts"),
63-
os.path.join(webview_dir, "wasm", "neatcoderInterface.d.ts"))
64-
65-
# Clean up by removing the copied file
66-
# os.remove(os.path.join(project_root, "pkg", "neatcoder.d.ts"))
67-
68-
# Remove the existing pkg directory in vsce_dir if it exists
69-
dest_pkg_dir = os.path.join(vsce_dir, "pkg")
70-
if os.path.exists(dest_pkg_dir):
71-
shutil.rmtree(dest_pkg_dir)
72-
73-
# Now move the pkg directory from crates_dir to vsce_dir
74-
move(os.path.join(crates_dir, "pkg"), dest_pkg_dir)
75-
76-
# Building WebView
77-
run_command("npm install", working_dir=webview_dir)
78-
run_command("npm run build", working_dir=webview_dir)
79-
80-
# Building Client
81-
run_command("yarn install", working_dir=vsce_dir)
82-
run_command("vsce package --out ../vsix", working_dir=vsce_dir)
83-
84-
85-
if __name__ == '__main__':
86-
build()
1+
import subprocess
2+
import os
3+
import shutil
4+
5+
6+
def move(src, dest):
7+
if os.path.isdir(src):
8+
shutil.move(src, dest)
9+
else:
10+
shutil.copy2(src, dest)
11+
os.remove(src)
12+
13+
14+
def run_command(cmd, working_dir=None):
15+
print(f"Executing in directory: {working_dir}")
16+
print(f"Executing command: {cmd}")
17+
18+
process = subprocess.Popen(
19+
cmd, shell=True,
20+
stdout=subprocess.PIPE,
21+
stderr=subprocess.STDOUT,
22+
cwd=working_dir,
23+
text=True,
24+
encoding='utf-8'
25+
)
26+
27+
# Stream output in real-time
28+
while True:
29+
output = process.stdout.readline()
30+
if output == '' and process.poll() is not None:
31+
break
32+
if output:
33+
print(output.strip())
34+
35+
rc = process.poll()
36+
return rc
37+
38+
39+
def build():
40+
script_dir = os.path.dirname(os.path.realpath(__file__))
41+
project_root = os.path.dirname(script_dir)
42+
43+
vsce_dir = os.path.join(project_root, 'vsce')
44+
crates_dir = os.path.join(project_root, 'crates', 'neatcoder')
45+
webview_dir = os.path.join(project_root, 'webview')
46+
47+
# Building WASM
48+
run_command("wasm-pack build --target nodejs --dev",
49+
working_dir=crates_dir)
50+
51+
# Workaround: Copy neatcoder.d.ts to expected location by create_interface.py
52+
dest_dir = os.path.join(project_root, "pkg")
53+
# exist_ok=True ensures no error if directory already exists
54+
os.makedirs(dest_dir, exist_ok=True)
55+
56+
shutil.copy2(os.path.join(crates_dir, "pkg", "neatcoder.d.ts"),
57+
os.path.join(dest_dir, "neatcoder.d.ts"))
58+
59+
run_command("python3 bin/create_interface.py", working_dir=project_root)
60+
61+
# Move the output file to desired location
62+
move(os.path.join(project_root, "neatcoderInterface.d.ts"),
63+
os.path.join(webview_dir, "wasm", "neatcoderInterface.d.ts"))
64+
65+
# Clean up by removing the copied file
66+
# os.remove(os.path.join(project_root, "pkg", "neatcoder.d.ts"))
67+
68+
# Remove the existing pkg directory in vsce_dir if it exists
69+
dest_pkg_dir = os.path.join(vsce_dir, "pkg")
70+
if os.path.exists(dest_pkg_dir):
71+
shutil.rmtree(dest_pkg_dir)
72+
73+
# Now move the pkg directory from crates_dir to vsce_dir
74+
move(os.path.join(crates_dir, "pkg"), dest_pkg_dir)
75+
76+
# Building WebView
77+
run_command("npm install", working_dir=webview_dir)
78+
run_command("npm run build", working_dir=webview_dir)
79+
dest_webview_build_dir = os.path.join(vsce_dir, "webview", "build")
80+
if os.path.exists(dest_webview_build_dir):
81+
shutil.rmtree(dest_webview_build_dir)
82+
move(os.path.join(webview_dir, "build"), dest_webview_build_dir)
83+
84+
# Building Client
85+
run_command("yarn install", working_dir=vsce_dir)
86+
run_command("vsce package --out ../vsix", working_dir=vsce_dir)
87+
88+
89+
if __name__ == '__main__':
90+
build()

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.2"
3+
version = "0.2.3"
44
edition = "2021"
55

66
[lib]

crates/neatcoder/src/openai/params.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum OpenAIModels {
1818
Gpt4,
1919
Gpt35Turbo,
2020
Gpt35Turbo16k,
21+
Gpt35Turbo1106,
22+
Gpt41106Preview,
2123
}
2224

2325
impl Default for OpenAIModels {
@@ -223,6 +225,8 @@ impl OpenAIModels {
223225
"gpt-4" => OpenAIModels::Gpt4,
224226
"gpt-3.5-turbo" => OpenAIModels::Gpt35Turbo,
225227
"gpt-3.5-turbo-16k" => OpenAIModels::Gpt35Turbo16k,
228+
"gpt-3.5-turbo-1106" => OpenAIModels::Gpt35Turbo1106,
229+
"gpt-4-1106-preview" => OpenAIModels::Gpt41106Preview,
226230
_ => panic!("Invalid model {}", model),
227231
};
228232

@@ -235,6 +239,8 @@ impl OpenAIModels {
235239
OpenAIModels::Gpt4 => String::from("gpt-4"),
236240
OpenAIModels::Gpt35Turbo => String::from("gpt-3.5-turbo"),
237241
OpenAIModels::Gpt35Turbo16k => String::from("gpt-3.5-turbo-16k"),
242+
OpenAIModels::Gpt35Turbo1106 => String::from("gpt-3.5-turbo-1106"),
243+
OpenAIModels::Gpt41106Preview => String::from("gpt-4-1106-preview"),
238244
}
239245
}
240246
}

crates/neatcoder/src/openai/request.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use wasm_bindgen_futures::JsFuture;
1111
#[wasm_bindgen(js_name = requestBody)]
1212
pub fn request_body_(
1313
msgs: IOpenAIMsg,
14+
job: OpenAIParams,
1415
stream: bool,
1516
) -> Result<JsValue, JsError> {
1617
let msgs: Vec<OpenAIMsg> = Vec::from_extern(msgs).map_err(|e| {
@@ -20,7 +21,7 @@ pub fn request_body_(
2021
))
2122
})?;
2223

23-
let job = OpenAIParams::default();
24+
// let job = OpenAIParams::default();
2425

2526
let mut data = json!({
2627
"model": job.model.as_string(),

vsce/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ 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.3] - 07/11/2023
8+
9+
### Added
10+
- New Open AI models `gpt-3.5-turbo-1106` and `gpt-4-1106-preview` now available
11+
12+
### Fixed
13+
- Fix openChat command webview build URI
14+
- Fix: Chat view works with both gpt3 and gpt4
15+
716
## [0.2.2] - 05/11/2023
817

918
### Fixed

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.2",
5+
"version": "0.2.3",
66
"publisher": "NeatworkAi",
77
"repository": {
88
"url": "https://github.com/neatwork-ai/neatcoder-issues.git",

vsce/src/chat/commands.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ export async function initChat(
6161
);
6262

6363
setWebviewContent(panel, context);
64-
console.log("hahaha");
6564
activePanels.set(panelCounter, panel);
66-
console.log("ebebebeb");
6765
panelCounter++;
6866

6967
panel.onDidDispose(() => {
@@ -90,9 +88,7 @@ export async function openChat(
9088
enableScripts: true,
9189
retainContextWhenHidden: true,
9290
localResourceRoots: [
93-
vscode.Uri.file(
94-
path.join(context.extensionPath, "..", "webview", "build")
95-
),
91+
vscode.Uri.file(path.join(context.extensionPath, "webview", "build")),
9692
],
9793
}
9894
);

vsce/src/chat/handlers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import * as wasm from "../../pkg/neatcoder";
44
import * as https from "https";
55
import * as url from "url";
66
import { MessageBuffer } from "../utils/httpClient";
7+
import { getLLMParams } from "../utils/utils";
78

89
export async function buildRequest(
910
msgs: Array<wasm.Message>,
1011
stream: boolean
1112
): Promise<[any, any]> {
12-
console.log("GOING FOR IT");
1313
const apiKey = await getOrSetApiKey();
14-
console.log("Skipping API KEY");
1514

1615
try {
1716
console.log("Messages: " + JSON.stringify(msgs.map((msg) => msg.payload)));
17+
let llmParams = await getLLMParams();
18+
1819
const body = wasm.requestBody(
1920
msgs.map((msg) => msg.payload),
21+
llmParams,
2022
stream
2123
);
2224
return [apiKey, body];

vsce/src/chat/webview.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ export function setWebviewContent(
1414
let content = fs.readFileSync(entryHtml, "utf8");
1515

1616
// Use asWebviewUri to get the correct URI for the assets
17-
console.log("a");
1817
content = content.replace(/src="\/static\/js\/(.*?)"/g, (match, filename) => {
1918
const scriptSrc = panel.webview.asWebviewUri(
2019
vscode.Uri.file(path.join(reactBuildPath, "static", "js", filename))
2120
);
2221
return `src="${scriptSrc}"`;
2322
});
2423

25-
console.log("b");
2624
content = content.replace(
2725
/href="\/static\/css\/(.*?)"/g,
2826
(match, filename) => {
@@ -33,19 +31,15 @@ export function setWebviewContent(
3331
}
3432
);
3533

36-
console.log("c");
3734
const publicPath = vscode.Uri.file(reactBuildPath);
38-
console.log("d");
3935
const webviewPath = panel.webview.asWebviewUri(publicPath);
40-
console.log("e");
4136

4237
// Injecting the public path
4338
const inlineScript = `<script>window.publicPath = "${webviewPath.toString()}";</script>`;
4439
content = content.replace(
4540
'<script id="pathInjection"></script>',
4641
inlineScript
4742
);
48-
console.log("f");
4943

5044
if (chatHistory) {
5145
const historyScript = `<script>window.initialChatHistory = ${JSON.stringify(
@@ -59,5 +53,4 @@ export function setWebviewContent(
5953
}
6054

6155
panel.webview.html = content;
62-
console.log("g");
6356
}

vsce/src/extension.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import {
2424
import { initCodeBase, appDataManager, setupDotNeatWatcher } from "./core";
2525
import { initStatusBar, initLogger, logger } from "./utils";
2626
import { ChatProvider, initChat, setupChatWatcher } from "./chat";
27-
import { getOrSetModelVersion, setModelVersion } from "./utils/utils";
27+
import {
28+
getLLMParams,
29+
getOrSetModelVersion,
30+
setModelVersion,
31+
} from "./utils/utils";
2832
import { ChatItem } from "./chat/providers";
2933
import { openChat, removeChat } from "./chat/commands";
3034
import MixpanelHelper from "./utils/mixpanelHelper";
@@ -226,17 +230,6 @@ export async function activate(context: vscode.ExtensionContext) {
226230
);
227231
}
228232

229-
async function getLLMParams(): Promise<wasm.OpenAIParams> {
230-
let modelVersion = await getOrSetModelVersion();
231-
if (modelVersion === null) {
232-
modelVersion = wasm.OpenAIModels.Gpt4;
233-
vscode.window.showErrorMessage(
234-
"Invalid model version, defaulting to Gpt4."
235-
);
236-
}
237-
return wasm.OpenAIParams.empty(modelVersion);
238-
}
239-
240233
// This method is called when the extension is deactivated
241234
export function deactivate() {
242235
let mixpanel = MixpanelHelper.getInstance();

0 commit comments

Comments
 (0)