Spaces:
Running
Running
//var database_url="http://127.0.0.1:7860/endpoint"; | |
var database_url= "https://llmbb-llmbb-agent.hf.space/endpoint"; | |
function send_data(msg){ | |
chrome.storage.local.get(['access_token'], function(result) { | |
console.log(result) | |
if (result.access_token) { | |
console.log('access_token currently is ' + result.access_token); | |
fetch(database_url, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": result.access_token | |
}, | |
body: JSON.stringify(msg), | |
}) | |
.then((response) => { | |
return response.json(); | |
}) | |
.then((data) => { | |
console.log(msg["task"]) | |
if(msg["task"]=="cache"){ | |
chrome.notifications.create("cache_url", { | |
type: 'basic', | |
iconUrl: 'img/popup.png', | |
title: 'add page', | |
message: 'add page success!' | |
}); | |
} | |
console.log(data); | |
}); | |
} | |
}); | |
} | |
chrome.runtime.onMessage.addListener(async (msg, sender) => { | |
if (msg.flag == "open_tab_and_cache_from_content"){ | |
var url = ""; | |
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | |
url = tabs[0].url; | |
console.log(url); | |
if (msg.data) { | |
chrome.storage.sync.get(['data'], function(result) { | |
chrome.storage.sync.set({ data: result.data }, function() { | |
send_data({ 'content' : msg.data, 'query': '', 'url': url, 'task':'cache', 'type':msg.type}); | |
}); | |
}); | |
} | |
}); | |
} | |
if (msg.flag == "open_popup_and_send_url_from_popup"){ | |
if (msg.data) { | |
chrome.storage.sync.get(['data'], function(result) { | |
chrome.storage.sync.set({ data: result.data }, function() { | |
send_data({ 'url' : msg.data, 'task':'pop_url'}); | |
}); | |
}); | |
} | |
} | |
// if (msg.flag == "set_addr"){ | |
// if (msg.data) { | |
// chrome.storage.sync.get(['data'], function(result) { | |
// chrome.storage.sync.set({ data: result.data }, function() { | |
// send_data({ 'addr' : msg.data, 'task':'set_addr'}); | |
// }); | |
// }); | |
// } | |
// } | |
}); | |
// Listen for when the extension is installed | |
chrome.runtime.onInstalled.addListener(function () { | |
// Set default API model | |
let defaultModel = "gpt-35-turbo"; | |
chrome.storage.local.set({ apiModel: defaultModel }); | |
// Set empty chat history | |
chrome.storage.local.set({ chatHistory: [] }); | |
// Open the options page | |
chrome.runtime.openOptionsPage(); | |
}); |