using chatgpt_developer_messages option. fixes #218
This commit is contained in:
parent
97d52fa0ee
commit
a049fb59db
4 changed files with 15 additions and 6 deletions
|
|
@ -66,13 +66,13 @@ messageInput.setMessagesArea(messagesArea);
|
||||||
|
|
||||||
switch (llm) {
|
switch (llm) {
|
||||||
case "chatgpt_api": {
|
case "chatgpt_api": {
|
||||||
let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: '', do_debug: false});
|
let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: '', chatgpt_developer_messages:'', do_debug: false});
|
||||||
let i18nStrings = {};
|
let i18nStrings = {};
|
||||||
i18nStrings["chatgpt_api_request_failed"] = browser.i18n.getMessage('chatgpt_api_request_failed');
|
i18nStrings["chatgpt_api_request_failed"] = browser.i18n.getMessage('chatgpt_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.chatgpt_model);
|
messageInput.setModel(prefs_api.chatgpt_model);
|
||||||
messagesArea.setLLMName("ChatGPT");
|
messagesArea.setLLMName("ChatGPT");
|
||||||
worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
|
worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model, chatgpt_developer_messages: prefs_api.chatgpt_developer_messages, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
|
||||||
messagesArea.appendUserMessage(browser.i18n.getMessage("chagpt_api_connecting") + " " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.chatgpt_model + "\"...", "info");
|
messagesArea.appendUserMessage(browser.i18n.getMessage("chagpt_api_connecting") + " " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.chatgpt_model + "\"...", "info");
|
||||||
browser.runtime.sendMessage({command: "openai_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
|
browser.runtime.sendMessage({command: "openai_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,13 @@ export class OpenAI {
|
||||||
|
|
||||||
apiKey = '';
|
apiKey = '';
|
||||||
model = '';
|
model = '';
|
||||||
|
developer_messages = '';
|
||||||
stream = false;
|
stream = false;
|
||||||
|
|
||||||
constructor(apiKey, model, stream) {
|
constructor(apiKey, model, developer_messages, stream) {
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.developer_messages = developer_messages;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,6 +71,13 @@ export class OpenAI {
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchResponse = async (messages, maxTokens = 0) => {
|
fetchResponse = async (messages, maxTokens = 0) => {
|
||||||
|
|
||||||
|
if(this.developer_messages !== ''){
|
||||||
|
messages.push({role: "developer", content: [{"type": "text", "text": this.developer_messages}]});
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(">>>>>>>>>>> OpenAI API request: " + JSON.stringify(messages));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@
|
||||||
async initWorker() {
|
async initWorker() {
|
||||||
switch (this.llm) {
|
switch (this.llm) {
|
||||||
case "chatgpt_api": {
|
case "chatgpt_api": {
|
||||||
let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: ''});
|
let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: '', chatgpt_developer_messages: ''});
|
||||||
this.worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model, do_debug: this.do_debug, i18nStrings: ''});
|
this.worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model, chatgpt_developer_messages: prefs_api.chatgpt_developer_messages, do_debug: this.do_debug, i18nStrings: ''});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "google_gemini_api": {
|
case "google_gemini_api": {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ self.onmessage = async function(event) {
|
||||||
if (event.data.type === 'init') {
|
if (event.data.type === 'init') {
|
||||||
chatgpt_api_key = event.data.chatgpt_api_key;
|
chatgpt_api_key = event.data.chatgpt_api_key;
|
||||||
chatgpt_model = event.data.chatgpt_model;
|
chatgpt_model = event.data.chatgpt_model;
|
||||||
openai = new OpenAI(chatgpt_api_key, chatgpt_model, true);
|
openai = new OpenAI(chatgpt_api_key, chatgpt_model, event.data.chatgpt_developer_messages, true);
|
||||||
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', do_debug);
|
taLog = new taLogger('model-worker-openai', do_debug);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue