Added error handling.
Replaced icon
@@ -19,13 +19,13 @@ The plugin can be configured by clicking the plugin button in the Chrome toolbar
|
|||||||
These are the tools that are currently available:
|
These are the tools that are currently available:
|
||||||
|
|
||||||
### Auto-complete
|
### Auto-complete
|
||||||
Select a text and press `Alt+c` to trigger the auto-complete tool.
|
Select a text and press `Alt+C` to trigger the auto-complete tool.
|
||||||
|
|
||||||
### Improve
|
### Improve
|
||||||
Select a text and press `Alt+i` to trigger the improvement tool. The original text will be commented out and the improved text will be inserted below it.
|
Select a text and press `Alt+I` to trigger the improvement tool. The original text will be commented out and the improved text will be inserted below it.
|
||||||
|
|
||||||
### Ask
|
### Ask
|
||||||
Select a text and press `Alt+a` to trigger the ask tool. The original text will be deleted and the answer will be inserted in its place.
|
Select a text and press `Alt+A` to trigger the ask tool. The original text will be deleted and the answer will be inserted in its place.
|
||||||
|
|
||||||
For example: "Create a table 4x3 that the first row is bold face" will be replaced with, e.g.,:
|
For example: "Create a table 4x3 that the first row is bold face" will be replaced with, e.g.,:
|
||||||
```latex
|
```latex
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "popup/popup.html",
|
"default_popup": "popup/popup.html",
|
||||||
"default_icon": "popup/icon.png"
|
"default_icon": "popup/LeafLLM.png"
|
||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
],
|
],
|
||||||
"description": "LLM-based tools for Overleaf",
|
"description": "LLM-based tools for Overleaf",
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "popup/icon_16.png",
|
"16": "popup/LeafLLM_16.png",
|
||||||
"48": "popup/icon_48.png",
|
"48": "popup/LeafLLM_48.png",
|
||||||
"128": "popup/icon_128.png"
|
"128": "popup/LeafLLM_128.png"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"Complete": {
|
"Complete": {
|
||||||
|
|||||||
BIN
popup/Leaf.png
Normal file
|
After Width: | Height: | Size: 320 KiB |
BIN
popup/LeafLLM.xcf
Normal file
BIN
popup/LeafLLM_128.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
popup/LeafLLM_16.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
popup/LeafLLM_48.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
popup/icon.png
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 12 KiB |
@@ -90,7 +90,7 @@ function commentText(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function improveTextHandler(openAI) {
|
async function improveTextHandler(openAI) {
|
||||||
if (!(await settingIsEnabled('textImprovement'))) return
|
if (!(await settingIsEnabled('textImprovement'))) throw new Error('Text improvement is not enabled.')
|
||||||
const selection = window.getSelection()
|
const selection = window.getSelection()
|
||||||
const selectedText = selection.toString()
|
const selectedText = selection.toString()
|
||||||
if (!selectedText) return
|
if (!selectedText) return
|
||||||
@@ -100,7 +100,7 @@ async function improveTextHandler(openAI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function completeTextHandler(openAI) {
|
async function completeTextHandler(openAI) {
|
||||||
if (!(await settingIsEnabled('textCompletion'))) return
|
if (!(await settingIsEnabled('textCompletion'))) throw new Error('Text completion is not enabled.')
|
||||||
const selection = window.getSelection()
|
const selection = window.getSelection()
|
||||||
const selectedText = selection.toString()
|
const selectedText = selection.toString()
|
||||||
if (!selectedText) return
|
if (!selectedText) return
|
||||||
@@ -109,7 +109,7 @@ async function completeTextHandler(openAI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function askHandler(openAI) {
|
async function askHandler(openAI) {
|
||||||
if (!(await settingIsEnabled('textAsk'))) return
|
if (!(await settingIsEnabled('textAsk'))) throw new Error('Text ask is not enabled.')
|
||||||
const selection = window.getSelection()
|
const selection = window.getSelection()
|
||||||
const selectedText = selection.toString()
|
const selectedText = selection.toString()
|
||||||
if (!selectedText) return
|
if (!selectedText) return
|
||||||
@@ -129,21 +129,20 @@ function setAPIKey(key) {
|
|||||||
currentAPIKey = key
|
currentAPIKey = key
|
||||||
if (currentAPIKey) {
|
if (currentAPIKey) {
|
||||||
openAI = new OpenAIAPI(currentAPIKey)
|
openAI = new OpenAIAPI(currentAPIKey)
|
||||||
console.log('AI4Overleaf: OpenAI API key set, enabling AI4Overleaf features.')
|
console.log('LeafLLM: OpenAI API key set, enabling LeafLLM features.')
|
||||||
} else {
|
} else {
|
||||||
openAI = undefined
|
openAI = undefined
|
||||||
console.log('AI4Overleaf: OpenAI API key is not set, AI4Overleaf features are disabled.')
|
console.log('LeafLLM: OpenAI API key is not set, LeafLLM features are disabled.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCommand(command) {
|
function handleCommand(command) {
|
||||||
console.log('Handling command')
|
|
||||||
if (command === 'Improve') {
|
if (command === 'Improve') {
|
||||||
improveTextHandler(openAI)
|
improveTextHandler(openAI).catch(e => console.error(`Failed to execute the '${command}' command. Error message: ${e}`))
|
||||||
} else if (command === 'Complete') {
|
} else if (command === 'Complete') {
|
||||||
completeTextHandler(openAI)
|
completeTextHandler(openAI).catch(e => console.error(`Failed to execute the '${command}' command. Error message: ${e}`))
|
||||||
} else if (command === 'Ask') {
|
} else if (command === 'Ask') {
|
||||||
askHandler(openAI)
|
askHandler(openAI).catch(e => console.error(`Failed to execute the '${command}' command. Error message: ${e}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||