Compare commits
10 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c270586071 | ||
|
|
6dc2638de0 | ||
|
|
954e6c55d8 | ||
|
|
e702ab9c1a | ||
|
|
e85ecc9e50 | ||
|
|
589c8fef5b | ||
|
|
a924f946a5 | ||
|
|
2d02bc1bb8 | ||
|
|
59b3bd5019 | ||
|
|
b5efe247cf |
5 changed files with 45 additions and 16 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ self.onmessage = async function(event) {
|
|||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
let chunk = '';
|
||||
|
||||
while (true) {
|
||||
if (stopStreaming) {
|
||||
|
|
@ -124,12 +125,25 @@ self.onmessage = async function(event) {
|
|||
break;
|
||||
}
|
||||
// lots of low-level OpenAI response parsing stuff
|
||||
const chunk = decoder.decode(value);
|
||||
chunk += decoder.decode(value);
|
||||
console.log(">>>>>>>>>>>>>> [ThunderAI] chunk: " + JSON.stringify(chunk));
|
||||
const lines = chunk.split("\n");
|
||||
const parsedLines = lines
|
||||
let parsedLines = [];
|
||||
try{
|
||||
parsedLines = lines
|
||||
.map((line) => line.replace(/^data: /, "").trim()) // Remove the "data: " prefix
|
||||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||
.map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
.map((line) => {
|
||||
console.log(">>>>>>>>>>>>> [ThunderAI] line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
});
|
||||
chunk = chunk.substring(chunk.lastIndexOf('\n') + 1);
|
||||
console.log(">>>>>>>>>>>>>> [ThunderAI] last chunk: " + JSON.stringify(chunk));
|
||||
}catch(e){
|
||||
console.log(">>>>>>>>>>>>>> [ThunderAI] last chunk: " + JSON.stringify(chunk));
|
||||
console.error(">>>>>>>>>>>>> [ThunderAI] error: " + e);
|
||||
}
|
||||
|
||||
for (const parsedLine of parsedLines) {
|
||||
const { choices } = parsedLine;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
@ -58,6 +60,7 @@ self.onmessage = async function(event) {
|
|||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
let chunk = '';
|
||||
|
||||
while (true) {
|
||||
if (stopStreaming) {
|
||||
|
|
@ -76,12 +79,24 @@ self.onmessage = async function(event) {
|
|||
break;
|
||||
}
|
||||
// lots of low-level OpenAI response parsing stuff
|
||||
const chunk = decoder.decode(value);
|
||||
chunk += decoder.decode(value);
|
||||
console.log(">>>>>>>>>>>>>> [ThunderAI] chunk: " + JSON.stringify(chunk));
|
||||
const lines = chunk.split("\n");
|
||||
const parsedLines = lines
|
||||
let parsedLines = [];
|
||||
try{
|
||||
parsedLines = lines
|
||||
.map((line) => line.replace(/^data: /, "").trim()) // Remove the "data: " prefix
|
||||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||
.map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||
.map((line) => {
|
||||
console.log(">>>>>>>>>>>>> [ThunderAI] line: " + JSON.stringify(line));
|
||||
return JSON.parse(line);
|
||||
});
|
||||
chunk = chunk.substring(chunk.lastIndexOf('\n') + 1);
|
||||
console.log(">>>>>>>>>>>>>> [ThunderAI] last chunk: " + JSON.stringify(chunk));
|
||||
}catch(e){
|
||||
console.error(">>>>>>>>>>>>> [ThunderAI] error: " + JSON.stringify(e));
|
||||
}
|
||||
|
||||
for (const parsedLine of parsedLines) {
|
||||
const { choices } = parsedLine;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 2,
|
||||
"name": "ThunderAI",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"version": "2.2.0pre4",
|
||||
"version": "2.2.0_i145_v4",
|
||||
"author": "Mic (m@micz.it)",
|
||||
"homepage_url": "https://micz.it/thunderbird-addon-thunderai/",
|
||||
"browser_specific_settings": {
|
||||
|
|
|
|||
|
|
@ -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