diff --git a/api_webchat/controller.js b/api_webchat/controller.js index 6555c78b..72bf7ac4 100644 --- a/api_webchat/controller.js +++ b/api_webchat/controller.js @@ -80,13 +80,13 @@ switch (llm) { break; } case "openai_comp_api": { - let prefs_api = await browser.storage.sync.get({openai_comp_host: '', openai_comp_model: '', openai_comp_api_key: '', openai_comp_chat_name: '', do_debug: false}); + let prefs_api = await browser.storage.sync.get({openai_comp_host: '', openai_comp_model: '', openai_comp_api_key: '', openai_comp_use_v1: true, openai_comp_chat_name: '', do_debug: false}); 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, openai_comp_api_key: prefs_api.openai_comp_api_key, do_debug: prefs_api.do_debug, 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, openai_comp_use_v1: prefs_api.openai_comp_use_v1, do_debug: prefs_api.do_debug, 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"); browser.runtime.sendMessage({command: "openai_comp_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id}); break; diff --git a/api_webchat/model-worker-openai_comp.js b/api_webchat/model-worker-openai_comp.js index 5af68da8..20b1bf10 100644 --- a/api_webchat/model-worker-openai_comp.js +++ b/api_webchat/model-worker-openai_comp.js @@ -26,6 +26,7 @@ import { taLogger } from '../js/mzta-logger.js'; let openai_comp_host = null; let openai_comp_model = ''; let openai_comp_api_key = ''; +let openai_comp_use_v1 = true; let openai_comp = null; let stopStreaming = false; let i18nStrings = null; @@ -40,7 +41,8 @@ self.onmessage = async function(event) { openai_comp_host = event.data.openai_comp_host; openai_comp_model = event.data.openai_comp_model; 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); + openai_comp_use_v1 = event.data.openai_comp_use_v1; + openai_comp = new OpenAIComp(openai_comp_host, openai_comp_model, openai_comp_api_key, true, openai_comp_use_v1); do_debug = event.data.do_debug; i18nStrings = event.data.i18nStrings; taLog = new taLogger('model-worker-openai_comp', do_debug); diff --git a/js/api/openai_comp.js b/js/api/openai_comp.js index 0b5fefe2..fe80caaa 100644 --- a/js/api/openai_comp.js +++ b/js/api/openai_comp.js @@ -24,13 +24,15 @@ export class OpenAIComp { host = ''; model = ''; apiKey = ''; + use_v1 = true; stream = false; - constructor(host, model, apiKey = '', stream = false) { + constructor(host, model, apiKey = '', stream = false, use_v1 = true) { this.host = host.trim().replace(/\/+$/, ""); this.model = model; this.stream = stream; this.apiKey = apiKey; + this.use_v1 = use_v1; } @@ -40,7 +42,7 @@ export class OpenAIComp { }; if(this.apiKey !== '') curr_headers["Authorization"] = "Bearer "+ this.apiKey; - const response = await fetch(this.host + "/v1/models", { + const response = await fetch(this.host + (this.use_v1 ? "/v1" : "") + "/models", { method: "GET", headers: curr_headers, }); @@ -70,7 +72,7 @@ export class OpenAIComp { if(this.apiKey !== '') curr_headers["Authorization"] = "Bearer "+ this.apiKey; try { - const response = await fetch(this.host + "/v1/chat/completions", { + const response = await fetch(this.host + (this.use_v1 ? "/v1" : "") + "/chat/completions", { method: "POST", headers: curr_headers, body: JSON.stringify({ diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js index 1f055670..014eae76 100644 --- a/options/mzta-options-default.js +++ b/options/mzta-options-default.js @@ -29,6 +29,7 @@ export const prefs_default = { openai_comp_host: '', // For OpenAI Compatible API as LM-Studio openai_comp_model: '', openai_comp_api_key: '', + openai_comp_use_v1: true, openai_comp_chat_name: 'OpenAI Comp', dynamic_menu_force_enter: false, dynamic_menu_order_alphabet: true, diff --git a/options/mzta-options.html b/options/mzta-options.html index 050d87b5..73d0c328 100644 --- a/options/mzta-options.html +++ b/options/mzta-options.html @@ -170,6 +170,17 @@ + + + + + +