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) {
|
||||
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 = {};
|
||||
i18nStrings["chatgpt_api_request_failed"] = browser.i18n.getMessage('chatgpt_api_request_failed');
|
||||
i18nStrings["error_connection_interrupted"] = browser.i18n.getMessage('error_connection_interrupted');
|
||||
messageInput.setModel(prefs_api.chatgpt_model);
|
||||
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");
|
||||
browser.runtime.sendMessage({command: "openai_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -23,11 +23,13 @@ export class OpenAI {
|
|||
|
||||
apiKey = '';
|
||||
model = '';
|
||||
developer_messages = '';
|
||||
stream = false;
|
||||
|
||||
constructor(apiKey, model, stream) {
|
||||
constructor(apiKey, model, developer_messages, stream) {
|
||||
this.apiKey = apiKey;
|
||||
this.model = model;
|
||||
this.developer_messages = developer_messages;
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +71,13 @@ export class OpenAI {
|
|||
}
|
||||
|
||||
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 {
|
||||
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
||||
method: "POST",
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@
|
|||
async initWorker() {
|
||||
switch (this.llm) {
|
||||
case "chatgpt_api": {
|
||||
let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: ''});
|
||||
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: ''});
|
||||
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, chatgpt_developer_messages: prefs_api.chatgpt_developer_messages, do_debug: this.do_debug, i18nStrings: ''});
|
||||
break;
|
||||
}
|
||||
case "google_gemini_api": {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ self.onmessage = async function(event) {
|
|||
if (event.data.type === 'init') {
|
||||
chatgpt_api_key = event.data.chatgpt_api_key;
|
||||
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;
|
||||
i18nStrings = event.data.i18nStrings;
|
||||
taLog = new taLogger('model-worker-openai', do_debug);
|
||||
|
|
|
|||
Loading…
Reference in a new issue