From 67f5b6cc93581b1b288d8366e8a84857964df839 Mon Sep 17 00:00:00 2001 From: lakhoune Date: Sat, 18 Nov 2023 13:11:47 +0100 Subject: [PATCH] add model --- docker-compose.yml | 3 +- src/statistics/improvements-recommender.js | 18 +++--- .../recommender/custom-improvements.js | 4 ++ .../recommender/general-improvements.js | 26 ++++---- .../recommender/intent-improvements.js | 63 ++++++++++--------- 5 files changed, 61 insertions(+), 53 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 81a9c9e..c853b8e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -113,5 +113,4 @@ services: ports: - "8088:8088" depends_on: - - db - + - db \ No newline at end of file diff --git a/src/statistics/improvements-recommender.js b/src/statistics/improvements-recommender.js index 524f406..8186040 100644 --- a/src/statistics/improvements-recommender.js +++ b/src/statistics/improvements-recommender.js @@ -59,6 +59,10 @@ class ImprovementRec extends LitElement { Store token locally + @@ -172,6 +176,10 @@ class ImprovementRec extends LitElement { localStorage.setItem("openai-token", e.target[0].value); } this.updateToken(e.target[0].value); + const model = e.target[2].value; + if (model) { + localStorage.setItem("openai-model", model); + } } updateToken(value) { @@ -208,16 +216,6 @@ class ImprovementRec extends LitElement { }, 100); } - async askGPT() { - this.loading = true; - document.querySelector("#askGPTButton").disabled = true; - this.fetchRecommendations(); - setTimeout(() => { - document.querySelector("#askGPTButton").disabled = false; - this.loading = false; - }, 50000); - } - async fetchRecommendations() { const eventLogEndpointInput = this.configMap .get("event-log-endpoint") diff --git a/src/statistics/recommender/custom-improvements.js b/src/statistics/recommender/custom-improvements.js index 706b7df..a3797b4 100644 --- a/src/statistics/recommender/custom-improvements.js +++ b/src/statistics/recommender/custom-improvements.js @@ -165,6 +165,9 @@ class IntentImprovement extends LitElement { try { const controller = new AbortController(); + const model = localStorage.getItem("openai-model") + ? localStorage.getItem("openai-model") + : "gpt-3.5-turbo-1106"; const timeoutId = setTimeout(() => controller.abort(), 300000); @@ -176,6 +179,7 @@ class IntentImprovement extends LitElement { body: JSON.stringify({ "openai-key": this.openaiToken, inputPrompt: this.quill.getText(), + "openai-model": model, }), signal: controller.signal, }); diff --git a/src/statistics/recommender/general-improvements.js b/src/statistics/recommender/general-improvements.js index c68fcdd..ba40780 100644 --- a/src/statistics/recommender/general-improvements.js +++ b/src/statistics/recommender/general-improvements.js @@ -107,19 +107,23 @@ class GeneralImprovement extends LitElement { url += "?event-log-url=" + eventLogEndpointInput; try { const controller = new AbortController(); + const model = localStorage.getItem("openai-model") + ? localStorage.getItem("openai-model") + : "gpt-3.5-turbo-1106"; - const timeoutId = setTimeout(() => controller.abort(), 1200000); + const timeoutId = setTimeout(() => controller.abort(), 1200000); - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - "openai-key": this.openaiToken, - }), - signal: controller.signal, - }); + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + "openai-key": this.openaiToken, + "openai-model": model, + }), + signal: controller.signal, + }); if (response.ok) clearTimeout(timeoutId); const result = await response.text(); this.shadowRoot.querySelector("#chatgptRes").innerHTML = result; diff --git a/src/statistics/recommender/intent-improvements.js b/src/statistics/recommender/intent-improvements.js index 8ac33f3..fb625ff 100644 --- a/src/statistics/recommender/intent-improvements.js +++ b/src/statistics/recommender/intent-improvements.js @@ -102,38 +102,41 @@ class IntentImprovement extends LitElement { "intent-improvements" ); const controller = new AbortController(); + const model = localStorage.getItem("openai-model") + ? localStorage.getItem("openai-model") + : "gpt-3.5-turbo-1106"; - const timeoutId = setTimeout(() => controller.abort(), 120000); + const timeoutId = setTimeout(() => controller.abort(), 120000); - try { - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - "openai-key": this.openaiToken, - }), - signal: controller.signal, - }); - const result = await response.text(); - clearTimeout(timeoutId); - this.shadowRoot.querySelector("#chatgptRes").innerHTML = result; - } catch (error) { - console.error(error); - if (error.message) - this.shadowRoot.querySelector("#chatgptRes").innerHTML = error.message; - else if (error instanceof DOMException) - this.shadowRoot.querySelector("#chatgptRes").innerHTML = - "A timeout occurred"; - else - this.shadowRoot.querySelector("#chatgptRes").innerHTML = - "Unknown error"; - } finally { - this.loading = false; - this.chatGPTRes = true; - this.shadowRoot.querySelector("#askGPTButton").disabled = false; - } + try { + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + "openai-key": this.openaiToken, + "openai-model": model, + }), + signal: controller.signal, + }); + const result = await response.text(); + clearTimeout(timeoutId); + this.shadowRoot.querySelector("#chatgptRes").innerHTML = result; + } catch (error) { + console.error(error); + if (error.message) + this.shadowRoot.querySelector("#chatgptRes").innerHTML = error.message; + else if (error instanceof DOMException) + this.shadowRoot.querySelector("#chatgptRes").innerHTML = + "A timeout occurred"; + else + this.shadowRoot.querySelector("#chatgptRes").innerHTML = "Unknown error"; + } finally { + this.loading = false; + this.chatGPTRes = true; + this.shadowRoot.querySelector("#askGPTButton").disabled = false; + } } }