Skip to content

Commit 835f32c

Browse files
author
mmiscool
committed
build: Fixed broken openAI api call.
1 parent 7e2130f commit 835f32c

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

public/ChatManager.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export class ChatManager {
1313
this.setup(container, app_ctx);
1414
}
1515
async setup(container, app_ctx) {
16+
17+
18+
19+
1620
ctx = app_ctx;
1721
this.chatMode = 'chat';
1822
this.container = container;
@@ -22,6 +26,16 @@ export class ChatManager {
2226
this.conversationTitleInput = document.createElement('input');
2327
this.conversationTitleInput.type = 'text';
2428
this.conversationTitleInput.style.width = '100%';
29+
30+
31+
32+
33+
34+
//await this.populateModelSelect();
35+
36+
37+
38+
2539
//make it so that on change it saves the title
2640
this.conversationTitleInput.addEventListener('change', async () => {
2741
const conversationId = this.conversationPicker.value;
@@ -222,6 +236,50 @@ export class ChatManager {
222236
this.autoApplyCheckbox.checked = this.autoApplyMode;
223237
this.setInput('');
224238
}
239+
240+
async populateModelSelect() {
241+
242+
243+
// model selector
244+
const modelData = await doAjax('./llmSettings', {});
245+
246+
// add a select element to the container
247+
this.modelPicker = document.createElement('select');
248+
this.modelPicker.style.margin = '10px';
249+
this.modelPicker.style.width = '100%';
250+
this.modelPicker.size = 1;
251+
this.modelPicker.addEventListener('change', async () => {
252+
const selectedModel = this.modelPicker.value;
253+
alert(`Selected model: ${selectedModel}`);
254+
});
255+
256+
// add the model picker to the container
257+
this.container.appendChild(this.modelPicker);
258+
259+
260+
261+
// Clear existing options
262+
this.modelPicker.innerHTML = '';
263+
264+
Object.entries(modelData).forEach(([provider, data]) => {
265+
if (data.models && Array.isArray(data.models)) {
266+
// Create optgroup for each provider
267+
const group = document.createElement('optgroup');
268+
group.label = provider;
269+
270+
data.models.forEach(model => {
271+
const option = document.createElement('option');
272+
option.value = `${provider}:${model}`;
273+
option.textContent = model;
274+
group.appendChild(option);
275+
});
276+
277+
this.modelPicker.appendChild(group);
278+
}
279+
});
280+
}
281+
282+
225283
async submitButtonHandler() {
226284
// test if message is empty. If empty, do not add message.
227285
if (this.userInput.value !== '') {
@@ -253,7 +311,7 @@ export class ChatManager {
253311
});
254312
}
255313
async loadConversation(conversationId) {
256-
console.log('conversationId', conversationId);
314+
//console.log('conversationId', conversationId);
257315
const response = await doAjax('./pullMessages', { id: conversationId });
258316
ctx.targetFile = response.targetFile;
259317
await this.setTargetFile(response.targetFile);
@@ -524,11 +582,11 @@ export class ChatManager {
524582
});
525583
}
526584
codeElements = Array.from(codeElements);
527-
console.log('codeElements', codeElements);
585+
//console.log('codeElements', codeElements);
528586
if (codeElements.length === 0)
529587
return;
530588
codeElements.forEach(codeElement => {
531-
console.log('codeElement', codeElement);
589+
//console.log('codeElement', codeElement);
532590
// Create a wrapper to hold the code and toolbar
533591
const wrapper = document.createElement('div');
534592
wrapper.style.position = 'relative';

public/LLMSettingsManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class LLMSettingsManager {
1515
this.container.innerHTML = '';
1616
this.addRefreshButton();
1717
this.llmSettings = await this.fetchSettings();
18-
console.log(this.llmSettings);
18+
//console.log(this.llmSettings);
1919
this.createSettingsDiv();
2020
// check if there is an active LLM
2121
const activeLLM = await this.getActiveLLM();
@@ -177,7 +177,7 @@ export class LLMSettingsManager {
177177
return;
178178
}
179179

180-
console.log(newSettings);
180+
//console.log(newSettings);
181181
await doAjax('./llmSettingsUpdate', newSettings);
182182

183183
await this.init();

public/toolsManager.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class toolsManager {
3939
showOnlyStubsCheckbox.checked = localStorage.getItem('showOnlyStubs') === 'true';
4040
showOnlyStubsCheckbox.onchange = async () => {
4141
await localStorage.setItem('showOnlyStubs', showOnlyStubsCheckbox.checked);
42-
console.log('showOnlyStubs', showOnlyStubsCheckbox.checked);
42+
//console.log('showOnlyStubs', showOnlyStubsCheckbox.checked);
4343
this.onlyStubs = showOnlyStubsCheckbox.checked;
4444
await this.displayListOfStubsAndMethods();
4545
}
@@ -78,7 +78,7 @@ export class toolsManager {
7878
this.snippetTextArea.style.padding = '5px';
7979
this.snippetTextArea.placeholder = 'Paste the snippet here to merge and format';
8080
this.container.appendChild(this.snippetTextArea);
81-
return await console.log('showToolBar');
81+
//return await console.log('showToolBar');
8282
}
8383

8484
async displayListOfStubsAndMethods() {
@@ -124,7 +124,7 @@ export class toolsManager {
124124
}
125125
async pullMethodsList() {
126126
const listOfMethods = await doAjax('./getMethodsList', { targetFile: ctx.targetFile });
127-
console.log(listOfMethods);
127+
//console.log(listOfMethods);
128128
// the response contains
129129
for (const className in listOfMethods) {
130130
// console.log(className);
@@ -180,11 +180,11 @@ export class toolsManager {
180180
functionItemElement.style.color = 'green';
181181
functionItemElement.addEventListener('click', async () => {
182182
await this.addFunctionToChatPrompt(functionName, args, lineNumber);
183-
console.log('this is the line number ', lineNumber);
183+
//console.log('this is the line number ', lineNumber);
184184
await this.pullFunctionList(this.onlyStubs);
185185
});
186186
}
187-
console.log(this.onlyStubs, isStub);
187+
//console.log(this.onlyStubs, isStub);
188188

189189
this.container.appendChild(functionItemElement);
190190
this.container.appendChild(document.createElement('br'));

src/llmCall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ async function getOpenAIResponse(messages) {
327327

328328
let responseText = '';
329329

330-
const resultStream = openai.chat.completions.create({
330+
const resultStream = await openai.chat.completions.create({
331331
model: await readSetting('llmConfig/openai-model.txt'),
332332
messages,
333333
stream: true

0 commit comments

Comments
 (0)