managing model in the options page. see #92
This commit is contained in:
parent
59ec47b2e8
commit
93afbb2490
3 changed files with 41 additions and 0 deletions
|
|
@ -24,4 +24,5 @@ export const prefs_default = {
|
||||||
default_chatgpt_lang: '',
|
default_chatgpt_lang: '',
|
||||||
connection_type: 'chatgpt_web', //Other values: 'chatgpt_api'
|
connection_type: 'chatgpt_web', //Other values: 'chatgpt_api'
|
||||||
api_key_chatgpt: '',
|
api_key_chatgpt: '',
|
||||||
|
model_chatgpt: '',
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +108,20 @@
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="conntype_chatgpt_api">
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<span>__MSG_ChatGPT_Models__</span>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button id="btnUpdateChatGPTModels">__MSG_ChatGPT_Models_Fetch__</button><br>
|
||||||
|
<label>
|
||||||
|
<select id="model_chatgpt" name="model_chatgpt" class="option-input">
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div id="btn_custom_prompts">
|
<div id="btn_custom_prompts">
|
||||||
<button id="btnManagePrompts">__MSG_prefs_OptionText_btnManagePrompts__</button>
|
<button id="btnManagePrompts">__MSG_prefs_OptionText_btnManagePrompts__</button>
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
import { prefs_default } from './mzta-options-default.js';
|
import { prefs_default } from './mzta-options-default.js';
|
||||||
|
import { OpenAI } from '../js/api/openai.js';
|
||||||
|
|
||||||
function saveOptions(e) {
|
function saveOptions(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
@ -121,6 +122,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
element.addEventListener("change", saveOptions);
|
element.addEventListener("change", saveOptions);
|
||||||
});
|
});
|
||||||
showConnectionOptions();
|
showConnectionOptions();
|
||||||
|
|
||||||
document.getElementById('btnManagePrompts').addEventListener('click', () => {
|
document.getElementById('btnManagePrompts').addEventListener('click', () => {
|
||||||
// check if the tab is already there
|
// check if the tab is already there
|
||||||
browser.tabs.query({url: browser.runtime.getURL('../customprompts/mzta-custom-prompts.html')}).then((tabs) => {
|
browser.tabs.query({url: browser.runtime.getURL('../customprompts/mzta-custom-prompts.html')}).then((tabs) => {
|
||||||
|
|
@ -133,7 +135,31 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("connection_type").addEventListener("change", showConnectionOptions);
|
document.getElementById("connection_type").addEventListener("change", showConnectionOptions);
|
||||||
document.getElementById("connection_type").addEventListener("change", warnAPIKeyEmpty);
|
document.getElementById("connection_type").addEventListener("change", warnAPIKeyEmpty);
|
||||||
document.getElementById("api_key_chatgpt").addEventListener("change", warnAPIKeyEmpty);
|
document.getElementById("api_key_chatgpt").addEventListener("change", warnAPIKeyEmpty);
|
||||||
|
|
||||||
|
let prefs = await browser.storage.sync.get({api_key_chatgpt: '', model_chatgpt: ''});
|
||||||
|
let openai = new OpenAI(prefs.api_key_chatgpt, true);
|
||||||
|
let select_model_chatgpt = document.getElementById('model_chatgpt');
|
||||||
|
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = prefs.model_chatgpt;
|
||||||
|
option.text = prefs.model_chatgpt;
|
||||||
|
select_model_chatgpt.appendChild(option);
|
||||||
|
|
||||||
|
document.getElementById('btnUpdateChatGPTModels').addEventListener('click', () => {
|
||||||
|
openai.fetchModels().then((data) => {
|
||||||
|
console.log(">>>>>>>>> ChatGPT models: " + JSON.stringify(data));
|
||||||
|
data.forEach(model => {
|
||||||
|
if (!Array.from(select_model_chatgpt.options).some(option => option.value === model.id)) {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = model.id;
|
||||||
|
option.text = model.id;
|
||||||
|
select_model_chatgpt.appendChild(option);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue