From db89fe5582bf6f77f891be50ebf02229fdcb64a6 Mon Sep 17 00:00:00 2001 From: Tamas Szucs Date: Tue, 7 Nov 2023 16:08:36 +0100 Subject: [PATCH 1/3] use api proxy --- crates/neatcoder/src/models/chat.rs | 4 +++- vsce/src/utils/httpClient.ts | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/neatcoder/src/models/chat.rs b/crates/neatcoder/src/models/chat.rs index 3868161..ae5284e 100644 --- a/crates/neatcoder/src/models/chat.rs +++ b/crates/neatcoder/src/models/chat.rs @@ -176,7 +176,9 @@ impl Model { pub fn new(id: String) -> Model { Self { id, - uri: String::from("https://api.openai.com/v1/chat/completions"), + uri: String::from( + "https://openai-proxy-66mt7edr2a-ew.a.run.app/chat", + ), interface: String::from("OpenAI"), } } diff --git a/vsce/src/utils/httpClient.ts b/vsce/src/utils/httpClient.ts index 40859bb..e1290d2 100644 --- a/vsce/src/utils/httpClient.ts +++ b/vsce/src/utils/httpClient.ts @@ -27,11 +27,11 @@ export async function makeRequest(body: string): Promise { const apiKey = await getOrSetApiKey(); try { - const response = await fetch("https://api.openai.com/v1/chat/completions", { + const response = await fetch("https://openai-proxy-66mt7edr2a-ew.a.run.app/chat", { method: "POST", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${apiKey}`, + // Authorization: `Bearer ${apiKey}`, }, body, }); @@ -61,7 +61,7 @@ export async function makeStreamingRequest( activeTextDocument: TextDocument ): Promise { cleanup(); - const apiKey = await getOrSetApiKey(); + //const apiKey = await getOrSetApiKey(); return new Promise((resolve, reject) => { // let responseLog: string[] = []; // TODO: Only debug @@ -70,7 +70,7 @@ export async function makeStreamingRequest( let messageBuffer = new MessageBuffer(); try { - const urlString = "https://api.openai.com/v1/chat/completions"; + const urlString = "https://openai-proxy-66mt7edr2a-ew.a.run.app/chat"; const parsedUrl = url.parse(urlString); const options = { @@ -78,7 +78,7 @@ export async function makeStreamingRequest( method: "POST", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${apiKey}`, + //Authorization: `Bearer ${apiKey}`, }, }; From e20db1523748e52649171f0bdb81d2369f784510 Mon Sep 17 00:00:00 2001 From: Tamas Szucs Date: Tue, 7 Nov 2023 16:08:43 +0100 Subject: [PATCH 2/3] default model "gpt-4-1106-preview" --- vsce/src/utils/utils.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/vsce/src/utils/utils.ts b/vsce/src/utils/utils.ts index 455a9fc..aa45d05 100644 --- a/vsce/src/utils/utils.ts +++ b/vsce/src/utils/utils.ts @@ -279,13 +279,14 @@ export async function getOrSetModelVersion(): Promise let modelVersion = config.get("modelVersion") as string; if (!modelVersion) { - const value = await vscode.window.showQuickPick( - ["gpt-3.5-turbo-1106", "gpt-4-1106-preview"], - { - canPickMany: false, - placeHolder: "Select an OpenAI model", // This is the placeholder text - } - ); + const value = "gpt-4-1106-preview"; + // const value = await vscode.window.showQuickPick( + // ["gpt-3.5-turbo-1106", "gpt-4-1106-preview"], + // { + // canPickMany: false, + // placeHolder: "Select an OpenAI model", // This is the placeholder text + // } + // ); if (value) { await config.update( "modelVersion", From db9d43f47500aa589e4dee42a47d20e27a5350d4 Mon Sep 17 00:00:00 2001 From: Tamas Szucs Date: Tue, 7 Nov 2023 16:32:40 +0100 Subject: [PATCH 3/3] cleanup settings --- vsce/src/chat/commands.ts | 5 +++-- vsce/src/chat/handlers.ts | 8 ++++---- vsce/src/utils/httpClient.ts | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/vsce/src/chat/commands.ts b/vsce/src/chat/commands.ts index 1b6c6bd..78ff8c6 100644 --- a/vsce/src/chat/commands.ts +++ b/vsce/src/chat/commands.ts @@ -43,7 +43,8 @@ export async function initChat( path.join(context.extensionPath, "assets", "robot-32-30.png") ); - let modelVersion = await getOrSetModelVersion(); + const modelVersion = await getOrSetModelVersion(); + console.log(`Model version: ${modelVersion}`); const sessionId = uuidv4(); const chat = new wasm.Chat(sessionId, "Chat with Neat"); chat.addModel(modelVersion!); @@ -134,7 +135,7 @@ const setupWebviewSockets = async ( const msgs: Array = message.msgs; const isFirst = msgs.length === 1 ? true : false; - await getOrSetApiKey(); + //await getOrSetApiKey(); promptLLM(panel, message); diff --git a/vsce/src/chat/handlers.ts b/vsce/src/chat/handlers.ts index 7f55842..5805b42 100644 --- a/vsce/src/chat/handlers.ts +++ b/vsce/src/chat/handlers.ts @@ -10,7 +10,7 @@ export async function buildRequest( msgs: Array, stream: boolean ): Promise<[any, any]> { - const apiKey = await getOrSetApiKey(); + //const apiKey = await getOrSetApiKey(); try { console.log("Messages: " + JSON.stringify(msgs.map((msg) => msg.payload))); @@ -21,7 +21,7 @@ export async function buildRequest( llmParams, stream ); - return [apiKey, body]; + return ["", body]; } catch (err) { console.error(`Failed to build request: ${err}`); throw new Error((err as Error).message); @@ -41,7 +41,7 @@ export async function promptLLM( let messageBuffer = new MessageBuffer(); try { - const urlString = "https://api.openai.com/v1/chat/completions"; + const urlString = "https://openai-proxy-66mt7edr2a-ew.a.run.app/chat"; const parsedUrl = url.parse(urlString); const options = { @@ -49,7 +49,7 @@ export async function promptLLM( method: "POST", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${apiKey}`, + // Authorization: `Bearer ${apiKey}`, }, }; diff --git a/vsce/src/utils/httpClient.ts b/vsce/src/utils/httpClient.ts index e1290d2..62a1585 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 = await getOrSetApiKey(); + // const apiKey = await getOrSetApiKey(); try { const response = await fetch("https://openai-proxy-66mt7edr2a-ew.a.run.app/chat", {