chatgpt api prefs renamed

This commit is contained in:
mic 2024-07-29 23:35:10 +02:00
parent 6ce6872e7f
commit 9bff8a0358
7 changed files with 28 additions and 28 deletions

View file

@ -55,10 +55,10 @@ let promptData = null;
// ============================== TESTING - END
const params = new URLSearchParams(window.location.search);
let prefs_api = await browser.storage.sync.get({api_key_chatgpt: '', model_chatgpt: ''});
let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: ''});
// const openaiApiKey = params.get('openapi-key');
//console.log(">>>>>>>>>>> api_key_chatgpt: " + prefs_api_key.api_key_chatgpt);
worker.postMessage({ type: 'init', api_key_chatgpt: prefs_api.api_key_chatgpt, model_chatgpt: prefs_api.model_chatgpt});
//console.log(">>>>>>>>>>> chatgpt_api_key: " + prefs_api_key.chatgpt_api_key);
worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model});
messagesArea.appendUserMessage(browser.i18n.getMessage("chagtp_api_connecting"), "info");
// Event listeners for worker messages

View file

@ -107,8 +107,8 @@ class MessageInput extends HTMLElement {
async init(worker) {
this.worker = worker;
let prefs_api = await browser.storage.sync.get({model_chatgpt: ''});
this._sendButton.title = await browser.i18n.getMessage("chagtp_api_send_button") + ": " + prefs_api.model_chatgpt;
let prefs_api = await browser.storage.sync.get({chatgpt_model: ''});
this._sendButton.title = await browser.i18n.getMessage("chagtp_api_send_button") + ": " + prefs_api.chatgpt_model;
}
setMessagesArea(messagesAreaComponent) {

View file

@ -39,8 +39,8 @@ import { OpenAI } from '../js/api/openai.js';
//========================== for testing - END
let api_key_chatgpt = null;
let model_chatgpt = '';
let chatgpt_api_key = null;
let chatgpt_model = '';
let openai = null;
let conversationHistory = [];
@ -48,10 +48,10 @@ let assistantResponseAccumulator = '';
self.onmessage = async function(event) {
if (event.data.type === 'init') {
api_key_chatgpt = event.data.api_key_chatgpt;
model_chatgpt = event.data.model_chatgpt;
//console.log(">>>>>>>>>>> api_key_chatgpt: " + api_key_chatgpt);
openai = new OpenAI(api_key_chatgpt, model_chatgpt, true);
chatgpt_api_key = event.data.chatgpt_api_key;
chatgpt_model = event.data.chatgpt_model;
//console.log(">>>>>>>>>>> chatgpt_api_key: " + chatgpt_api_key);
openai = new OpenAI(chatgpt_api_key, chatgpt_model, true);
} else if (event.data.type === 'chatMessage') {
conversationHistory.push({ role: 'user', content: event.data.message });

View file

@ -148,11 +148,11 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
}
// check if the API is present, otherwise open the web interface
if (prefs.api_key_chatgpt == '') {
if (prefs.chatgpt_api_key == '') {
showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_apikey'));
prefs.connection_type = 'chatgpt_web';
}
if (prefs.model_chatgpt == '') {
if (prefs.chatgpt_model == '') {
showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_model'));
prefs.connection_type = 'chatgpt_web';
}

View file

@ -23,6 +23,6 @@ export const prefs_default = {
chatgpt_keep_formatting: false,
default_chatgpt_lang: '',
connection_type: 'chatgpt_web', //Other values: 'chatgpt_api'
api_key_chatgpt: '',
model_chatgpt: '',
chatgpt_api_key: '',
chatgpt_model: '',
}

View file

@ -103,7 +103,7 @@
</label></td>
<td>
<label>
<input type="text" id="api_key_chatgpt" name="api_key_chatgpt" class="option-input" style="width:28em" />
<input type="text" id="chatgpt_api_key" name="chatgpt_api_key" class="option-input" style="width:28em" />
&nbsp;<span></span>
</label>
</td>
@ -117,7 +117,7 @@
<td>
<button id="btnUpdateChatGPTModels">__MSG_ChatGPT_Models_Fetch__</button> <span id="model_fetch_loading">__MSG_ChatGPT_Models_Loading__</span><br>
<label>
<select id="model_chatgpt" name="model_chatgpt" class="option-input">
<select id="chatgpt_model" name="chatgpt_model" class="option-input">
</select>
</label>
</td>

View file

@ -111,9 +111,9 @@ function showConnectionOptions() {
}
function warnAPIKeyEmpty() {
let apiKeyInput = document.getElementById('api_key_chatgpt');
let apiKeyInput = document.getElementById('chatgpt_api_key');
let btnFetchModels = document.getElementById('btnUpdateChatGPTModels');
let modelChatGPT = document.getElementById('model_chatgpt');
let modelChatGPT = document.getElementById('chatgpt_model');
if(apiKeyInput.value === ''){
apiKeyInput.style.border = '2px solid red';
btnFetchModels.disabled = true;
@ -157,16 +157,16 @@ document.addEventListener('DOMContentLoaded', async () => {
let conntype_select = document.getElementById("connection_type");
conntype_select.addEventListener("change", showConnectionOptions);
conntype_select.addEventListener("change", warnAPIKeyEmpty);
document.getElementById("api_key_chatgpt").addEventListener("change", warnAPIKeyEmpty);
document.getElementById("chatgpt_api_key").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');
let prefs = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: ''});
let openai = new OpenAI(prefs.chatgpt_api_key, true);
let select_chatgpt_model = document.getElementById('chatgpt_model');
const option = document.createElement('option');
option.value = prefs.model_chatgpt;
option.text = prefs.model_chatgpt;
select_model_chatgpt.appendChild(option);
option.value = prefs.chatgpt_model;
option.text = prefs.chatgpt_model;
select_chatgpt_model.appendChild(option);
document.getElementById('btnUpdateChatGPTModels').addEventListener('click', () => {
document.getElementById('model_fetch_loading').style.display = 'inline';
@ -179,11 +179,11 @@ document.addEventListener('DOMContentLoaded', async () => {
}
console.log(">>>>>>>>> ChatGPT models: " + JSON.stringify(data));
data.forEach(model => {
if (!Array.from(select_model_chatgpt.options).some(option => option.value === model.id)) {
if (!Array.from(select_chatgpt_model.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);
select_chatgpt_model.appendChild(option);
}
});
document.getElementById('model_fetch_loading').style.display = 'none';