Skip to content

Commit

Permalink
add model
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhoune committed Nov 18, 2023
1 parent 2b2254e commit 67f5b6c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 53 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ services:
ports:
- "8088:8088"
depends_on:
- db

- db
18 changes: 8 additions & 10 deletions src/statistics/improvements-recommender.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class ImprovementRec extends LitElement {
Store token locally
</label>
</div>
<select class="form-select" aria-label="GPT model selection">
<option selected value="gpt-3.5-turbo-1106">GPT 3.5</option>
<option value="gpt-4-1106-preview">GPT 4</option>
</select>
<button type="submit" class="btn btn-primary">
Set <i class="bi bi-check ms-1"></i>
</button>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions src/statistics/recommender/custom-improvements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
});
Expand Down
26 changes: 15 additions & 11 deletions src/statistics/recommender/general-improvements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
63 changes: 33 additions & 30 deletions src/statistics/recommender/intent-improvements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 67f5b6c

Please sign in to comment.