uising the optional api key in the openai comp api see #144
This commit is contained in:
parent
205574626b
commit
f9832a1860
3 changed files with 7 additions and 5 deletions
|
|
@ -97,13 +97,13 @@ switch (llm) {
|
|||
break;
|
||||
}
|
||||
case "openai_comp_api": {
|
||||
let prefs_api = await browser.storage.sync.get({openai_comp_host: '', openai_comp_model: '', openai_comp_chat_name: ''});
|
||||
let prefs_api = await browser.storage.sync.get({openai_comp_host: '', openai_comp_model: '', openai_comp_api_key: '', openai_comp_chat_name: ''});
|
||||
let i18nStrings = {};
|
||||
i18nStrings["OpenAIComp_api_request_failed"] = browser.i18n.getMessage('OpenAIComp_api_request_failed');
|
||||
i18nStrings["error_connection_interrupted"] = browser.i18n.getMessage('error_connection_interrupted');
|
||||
messageInput.setModel(prefs_api.openai_comp_model);
|
||||
messagesArea.setLLMName(prefs_api.openai_comp_chat_name);
|
||||
worker.postMessage({ type: 'init', openai_comp_host: prefs_api.openai_comp_host, openai_comp_model: prefs_api.openai_comp_model, i18nStrings: i18nStrings});
|
||||
worker.postMessage({ type: 'init', openai_comp_host: prefs_api.openai_comp_host, openai_comp_model: prefs_api.openai_comp_model, openai_comp_api_key: prefs_api.openai_comp_api_key, i18nStrings: i18nStrings});
|
||||
messagesArea.appendUserMessage(browser.i18n.getMessage("OpenAIComp_api_connecting") + " \"" + prefs_api.openai_comp_host + "\" " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.openai_comp_model + "\"...", "info");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { OpenAIComp } from '../js/api/openai_comp.js';
|
|||
|
||||
let openai_comp_host = null;
|
||||
let openai_comp_model = '';
|
||||
let openai_comp_api_key = '';
|
||||
let openai_comp = null;
|
||||
let stopStreaming = false;
|
||||
|
||||
|
|
@ -34,11 +35,12 @@ self.onmessage = async function(event) {
|
|||
if (event.data.type === 'init') {
|
||||
openai_comp_host = event.data.openai_comp_host;
|
||||
openai_comp_model = event.data.openai_comp_model;
|
||||
openai_comp = new OpenAIComp(openai_comp_host, openai_comp_model, true);
|
||||
openai_comp_api_key = event.data.openai_comp_api_key;
|
||||
openai_comp = new OpenAIComp(openai_comp_host, openai_comp_model, openai_comp_api_key, true);
|
||||
} else if (event.data.type === 'chatMessage') {
|
||||
conversationHistory.push({ role: 'user', content: event.data.message });
|
||||
|
||||
const response = await openai.fetchResponse(conversationHistory); //4096);
|
||||
const response = await openai_comp.fetchResponse(conversationHistory); //4096);
|
||||
postMessage({ type: 'messageSent' });
|
||||
|
||||
if (!response.ok) {
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ select_openai_comp_model.addEventListener("change", warn_OpenAIComp_HostEmpty);
|
|||
|
||||
document.getElementById('btnUpdateOpenAICompModels').addEventListener('click', async () => {
|
||||
document.getElementById('openai_comp_model_fetch_loading').style.display = 'inline';
|
||||
let openai_comp = new OpenAIComp(document.getElementById("openai_comp_host").value, true);
|
||||
let openai_comp = new OpenAIComp(document.getElementById("openai_comp_host").value , null, document.getElementById("openai_comp_api_key").value, true);
|
||||
openai_comp.fetchModels().then((data) => {
|
||||
if(!data.ok){
|
||||
let errorDetail = JSON.parse(data.error);
|
||||
|
|
|
|||
Loading…
Reference in a new issue