openai_comp_use_v1 pref added
This commit is contained in:
parent
0df2d61d83
commit
9fe528d6c8
6 changed files with 23 additions and 7 deletions
|
|
@ -80,13 +80,13 @@ switch (llm) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "openai_comp_api": {
|
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 = {};
|
let i18nStrings = {};
|
||||||
i18nStrings["OpenAIComp_api_request_failed"] = browser.i18n.getMessage('OpenAIComp_api_request_failed');
|
i18nStrings["OpenAIComp_api_request_failed"] = browser.i18n.getMessage('OpenAIComp_api_request_failed');
|
||||||
i18nStrings["error_connection_interrupted"] = browser.i18n.getMessage('error_connection_interrupted');
|
i18nStrings["error_connection_interrupted"] = browser.i18n.getMessage('error_connection_interrupted');
|
||||||
messageInput.setModel(prefs_api.openai_comp_model);
|
messageInput.setModel(prefs_api.openai_comp_model);
|
||||||
messagesArea.setLLMName(prefs_api.openai_comp_chat_name);
|
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");
|
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});
|
browser.runtime.sendMessage({command: "openai_comp_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import { taLogger } from '../js/mzta-logger.js';
|
||||||
let openai_comp_host = null;
|
let openai_comp_host = null;
|
||||||
let openai_comp_model = '';
|
let openai_comp_model = '';
|
||||||
let openai_comp_api_key = '';
|
let openai_comp_api_key = '';
|
||||||
|
let openai_comp_use_v1 = true;
|
||||||
let openai_comp = null;
|
let openai_comp = null;
|
||||||
let stopStreaming = false;
|
let stopStreaming = false;
|
||||||
let i18nStrings = null;
|
let i18nStrings = null;
|
||||||
|
|
@ -40,7 +41,8 @@ self.onmessage = async function(event) {
|
||||||
openai_comp_host = event.data.openai_comp_host;
|
openai_comp_host = event.data.openai_comp_host;
|
||||||
openai_comp_model = event.data.openai_comp_model;
|
openai_comp_model = event.data.openai_comp_model;
|
||||||
openai_comp_api_key = event.data.openai_comp_api_key;
|
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;
|
do_debug = event.data.do_debug;
|
||||||
i18nStrings = event.data.i18nStrings;
|
i18nStrings = event.data.i18nStrings;
|
||||||
taLog = new taLogger('model-worker-openai_comp', do_debug);
|
taLog = new taLogger('model-worker-openai_comp', do_debug);
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,15 @@ export class OpenAIComp {
|
||||||
host = '';
|
host = '';
|
||||||
model = '';
|
model = '';
|
||||||
apiKey = '';
|
apiKey = '';
|
||||||
|
use_v1 = true;
|
||||||
stream = false;
|
stream = false;
|
||||||
|
|
||||||
constructor(host, model, apiKey = '', stream = false) {
|
constructor(host, model, apiKey = '', stream = false, use_v1 = true) {
|
||||||
this.host = host.trim().replace(/\/+$/, "");
|
this.host = host.trim().replace(/\/+$/, "");
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
|
this.use_v1 = use_v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -40,7 +42,7 @@ export class OpenAIComp {
|
||||||
};
|
};
|
||||||
if(this.apiKey !== '') curr_headers["Authorization"] = "Bearer "+ this.apiKey;
|
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",
|
method: "GET",
|
||||||
headers: curr_headers,
|
headers: curr_headers,
|
||||||
});
|
});
|
||||||
|
|
@ -70,7 +72,7 @@ export class OpenAIComp {
|
||||||
if(this.apiKey !== '') curr_headers["Authorization"] = "Bearer "+ this.apiKey;
|
if(this.apiKey !== '') curr_headers["Authorization"] = "Bearer "+ this.apiKey;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.host + "/v1/chat/completions", {
|
const response = await fetch(this.host + (this.use_v1 ? "/v1" : "") + "/chat/completions", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: curr_headers,
|
headers: curr_headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ export const prefs_default = {
|
||||||
openai_comp_host: '', // For OpenAI Compatible API as LM-Studio
|
openai_comp_host: '', // For OpenAI Compatible API as LM-Studio
|
||||||
openai_comp_model: '',
|
openai_comp_model: '',
|
||||||
openai_comp_api_key: '',
|
openai_comp_api_key: '',
|
||||||
|
openai_comp_use_v1: true,
|
||||||
openai_comp_chat_name: 'OpenAI Comp',
|
openai_comp_chat_name: 'OpenAI Comp',
|
||||||
dynamic_menu_force_enter: false,
|
dynamic_menu_force_enter: false,
|
||||||
dynamic_menu_order_alphabet: true,
|
dynamic_menu_order_alphabet: true,
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,17 @@
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="conntype_openai_comp_api">
|
||||||
|
<td><label>
|
||||||
|
<span>__MSG_prefs_OptionText_openai_comp_use_v1__</span>
|
||||||
|
</label></td>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="openai_comp_use_v1" name="openai_comp_use_v1" class="option-input" />
|
||||||
|
<span>__MSG_prefs_OptionText_openai_comp_use_v1_info__</span>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr class="conntype_openai_comp_api">
|
<tr class="conntype_openai_comp_api">
|
||||||
<td><label>
|
<td><label>
|
||||||
<span>__MSG_prefs_OpenAIComp_API_Key__</span>
|
<span>__MSG_prefs_OpenAIComp_API_Key__</span>
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ select_openai_comp_model.addEventListener("change", warn_OpenAIComp_HostEmpty);
|
||||||
|
|
||||||
document.getElementById('btnUpdateOpenAICompModels').addEventListener('click', async () => {
|
document.getElementById('btnUpdateOpenAICompModels').addEventListener('click', async () => {
|
||||||
document.getElementById('openai_comp_model_fetch_loading').style.display = 'inline';
|
document.getElementById('openai_comp_model_fetch_loading').style.display = 'inline';
|
||||||
let openai_comp = new OpenAIComp(document.getElementById("openai_comp_host").value , null, document.getElementById("openai_comp_api_key").value, true);
|
let openai_comp = new OpenAIComp(document.getElementById("openai_comp_host").value , null, document.getElementById("openai_comp_api_key").value, true, document.getElementById("openai_comp_use_v1").checked);
|
||||||
openai_comp.fetchModels().then((data) => {
|
openai_comp.fetchModels().then((data) => {
|
||||||
if(!data.ok){
|
if(!data.ok){
|
||||||
let errorDetail;
|
let errorDetail;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue